Created
December 30, 2020 15:37
-
-
Save sfirke/47393f597353ebd52cf767c2f02c213b to your computer and use it in GitHub Desktop.
Retrieving SolarEdge solar panel generation data from the API using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import solaredge | |
import time | |
s = solaredge.Solaredge("YOUR-API-KEY") | |
site_id = YOUR-SITE-ID | |
# Edit this date range as you see fit | |
# If querying at the maximum resolution of 15 minute intervals, the API is limited to queries of a month at a time | |
# This script queries one day at a time, with a one-second pause per day that is polite but probably not necessary | |
day_list = pd.date_range(start="2019-12-01",end="2020-12-01") | |
day_list = day_list.strftime('%Y-%m-%d') | |
energy_df_list = [] | |
for day in day_list: | |
temp = s.get_energy_details(site_id,day+' 00:00:00',day + ' 23:59:59',time_unit='QUARTER_OF_AN_HOUR') | |
temp_df = pd.DataFrame(temp['energyDetails']['meters'][0]['values']) | |
energy_df_list.append(temp_df) | |
time.sleep(1) | |
power_df_list = [] | |
for day in day_list: | |
temp = s.get_power_details(site_id,day+' 00:00:00',day + ' 23:59:59') | |
temp_df = pd.DataFrame(temp['powerDetails']['meters'][0]['values']) | |
power_df_list.append(temp_df) | |
time.sleep(1) | |
energy_df = pd.concat(energy_df_list) | |
energy_df.columns = ['date','energy'] | |
power_df = pd.concat(power_df_list) | |
power_df.columns = ['date','power'] | |
merged = pd.merge(energy_df,power_df) | |
merged.to_csv("C:/merged_solar_data.csv",index=False) |
Author
sfirke
commented
Mar 27, 2021
via email
Not sure, sorry. Maybe I should make this a repository to support issues
though.
…On Sat, Mar 27, 2021, 12:02 PM Conet1502 ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
What about if you want to pull the temperature and current data?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/47393f597353ebd52cf767c2f02c213b#gistcomment-3683399>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZYDEDPKJSX66M5H62JDVDTFX6SFANCNFSM4Z5BPUUA>
.
add this to the solaredge.py file
def get_data(self, site_id, short_serial ,start_time, end_time):
url = urljoin(BASEURL2, site_id, short_serial, "data")
params = {
'startTime': start_time,
'endTime': end_time,
'api_key': self.token,
}
r = requests.get(url,params)
r.raise_for_status()
return r.json()
and this to the example solaredge_retrieval.py
Line1Data_df_list = []
for day in day_list:
temp = s.get_data(site_id,short_serial,day+' 00:00:00',day + ' 23:59:59')
#temp_df = pd.DataFrame(temp['data']['telemetries'])
#temp_df = temp_df.drop(['L1Data'], axis=1)
temp = s.get_data(site_id,short_serial,day+' 00:00:00',day + ' 23:59:59')
temp_df1 = pd.json_normalize(temp['data']['telemetries'])
Line1Data_df_list.append(temp_df1)
#time.sleep(1)
Also add this to the solaredge.py
BASEURL2 = 'https://monitoringapi.solaredge.com/equipment'
Thanks for the additions! I moved this gist to a repo: https://github.com/sfirke/solaredge/ If you're up for it, feel free to send those changes as a pull request.
I get an error when downloading a whole year, due to summer time difference (DST) error
- issue is that during DST switch, one hour gets data missing
- at DST reversal, two hour data points are overlapped, thus broken data again
How to solve this? And download full year 15min power values?
How to get the full year data in one line?
- instead of adding up days after each other
@MaykThewessen I see you created an issue in that repo, let's continue there.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment