Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose storage API #13

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Documentation of function
  • Loading branch information
ntropy-esa committed Mar 30, 2022
commit 41b5c7b9ac878592173f27bb07d6e05a87eab0a0
49 changes: 42 additions & 7 deletions growatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def _back_success_response(response):
return result

def _obj_success_response(response):
"""
Check and return the response, where we expect a "result" key with value 1 and with
another key named "obj" item.
"""
if response.status_code != 200:
raise GrowattApiError("Request failed: %s" % response)
data = response.json()
Expand Down Expand Up @@ -254,13 +258,45 @@ def get_storage_day_line(self, date, typ=None):
/newStorageAPI.do?op=getDayLineStorage&id=NZH4BHH033&date=2022-03-26&type=12

Multiple variables available at mutliple time resolutions.
Type Variable Meaning
At 5-min time resolution:
Type Variable Meaning
8 PPV1 Power production of PV array 1, in W
10 PPV2 Power production of PV array 2, in W
3 PV1 Voltage Voltage of PV array 1, in V
9 PV2 Voltage Voltage of PV array 2, in V
7 Battery SOC State of charge of battery, in %
11 VBattery Voltage of the battery, in V
12 OutPutPower Power consumed by the load (or generated by the inverter), in W
13 OutputVoltage Voltage of output power (load), in V
14 Grid Voltage Voltage of power from the grid, in V
15 EPV Today Cummulative PV production, in kWh
16 EAC Today Cummulative power taken from the grid, in kWh
17 Ebat Today Cummulative power charge to the battery, in kWh
18 EBatDischarge Today Cummulative power discharged from the battery, in kWh (although app displays W)

useful lists & dicts
L1 = [8,10,3,9,7,11,12,13,14,15,16,17,18]
L2 = ['PPV1', 'PPV2', 'PV1 Voltage', 'PV2 Voltage', 'Battery SOC', 'VBattery', 'OutPutPower', 'OutputVoltage', 'Grid Voltage', 'EPV Today', 'EAC Today', 'Ebat Today', 'EBatDischarge Today']
Ldict = {k:v for k,v in zip(L1,L2)}

To be implemented (in separate functions)
At daily resolution:
1 EPV Month, 2 EBat-Charge Month, 3 Ebat-Discharge Month, 4 EAC-Charge Month
https://server-api.growatt.com/newStorageAPI.do?op=getMonthLineStorage_sacolar&id=NZH4BHH033&date=2022-03&type=1

At monthly resolution:
1 EPV Year, 2 EBat-Charge Year, 3 Ebat-Discharge Year, 4 EAC-Charge Year
https://server-api.growatt.com/newStorageAPI.do?op=getYearLineStorage_sacolar&id=NZH4BHH033&date=2022&type=1

At yearly resolution:
1 EPV Total, 2 EBat-Charge Total, 3 Ebat-Discharge Total, 4 EAC-Charge Total
https://server-api.growatt.com/newStorageAPI.do?op=getTotalLineStorage_sacolar&id=NZH4BHH033&type=1

'''

if(typ is None):
# check for null or None type
typ = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20, 21, 22]
typ = [8,10,3,9,7,11,12,13,14,15,16,17,18]
if(isinstance(typ, int)):
typ = [typ] # make a list out of it

Expand All @@ -273,12 +309,11 @@ def get_storage_day_line(self, date, typ=None):
"date": date,
"type":str(t)}
)
#print("type", t, "response", response)
#print("response json", response.json())
if response.status_code != 200:
data_dict[t] =response.json() # returns ['obj'] if no error on server side
# else:
# data_dict[t] = response.status_code
raise GrowattApiError("Request failed for type %s: %s" % (str(t), response))
else:
data = response.json()
data_dict[t] = data

return data_dict

Expand Down