Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions getstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
BASE_URL = 'https://enlighten.enphaseenergy.com'
SYSTEM_URL = BASE_URL + '/systems/{system_id}'
STATS_URL = SYSTEM_URL + '/inverter_data_x/time_series.json'
POWER_URL = SYSTEM_URL + '/power_time_series?days=1&date={date}'
INVERTERS_URL = SYSTEM_URL + '/inverter_status_x.json'
INVERTER_STATS_URL = SYSTEM_URL + '/inverters/{inverter_id}/time_series_x'
STATS = 'POWR,DCV,DCA,ACV,ACHZ,TMPI'
Expand Down Expand Up @@ -102,6 +103,19 @@ def report_error(msg):
print('Sleeping...')
time.sleep(10)
print(date.isoformat())

url = POWER_URL.format(system_id=system_id, date=date.isoformat())
print(url)

with urllib.request.urlopen(url) as f:
data = f.read().decode('UTF-8')
json_obj = json.loads(data, object_pairs_hook=OrderedDict)

with open('data/' + date.isoformat() + '-production_consumption.json', 'w') as datafile:
datafile.write(json.dumps(json_obj, indent=4, separators=(',', ': ')))

time.sleep(1)

first = True
for key in inverters:
if first:
Expand Down