From db65673a2c5446bae74396a52242a186028ff31d Mon Sep 17 00:00:00 2001 From: StuartW Date: Sat, 10 Apr 2021 19:09:52 +1000 Subject: [PATCH] Update getstats.py to add power_time_series data Add download of power_time_series data for each day requested. --- getstats.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/getstats.py b/getstats.py index f204d8b..0f876c4 100755 --- a/getstats.py +++ b/getstats.py @@ -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' @@ -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: