Skip to content

Commit 8a645a1

Browse files
authored
Merge branch 'master' into master
2 parents b551c7f + 4b70e42 commit 8a645a1

5 files changed

Lines changed: 127 additions & 12 deletions

File tree

docs/shinephone.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Any methods that may be useful.
6363
| `api.update_mix_inverter_setting(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified Mix inverter. see: [details](./shinephone/inverter_settings.md) |
6464
| `api.update_ac_inverter_setting(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified AC-coupled inverter. see: [details](./shinephone/inverter_settings.md) |
6565
| `api.update_noah_settings(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified Noah device. see: [details](./shinephone/noah_settings.md) |
66+
| `api.update_classic_inverter_setting(default_parameters, parameters)` | default_parameters: Dict, parameters: Dict/Array | Applies settings for specified system based on serial number. This function is only going to work for classic inverters. |
6667

6768
### Variables
6869

docs/shinephone/inverter_settings.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ Known working settings & parameters are as follows (all parameter values are str
7878
* start_time: timedate object with start time of segment with format HH:MM
7979
* end_time: timedate object with end time of segment with format HH:MM
8080
* enabled: time segment enabled, boolean: True (Enabled), False (Disabled)
81+
* **Classic inverter settings**
82+
* function: `api.update_classic_inverter_setting`
83+
* description: Applies settings for specified system based on serial number. This function is only going to work for classic inverters.
84+
* params:
85+
* `param1`: First parameter (specific to the setting type)
86+
* `param2`: Second parameter (specific to the setting type)
87+
* Additional parameters can be passed as needed.
8188

8289
The four functions `update_tlx_inverter_setting`, `update_mix_inverter_setting`, `update_ac_inverter_setting`, and `update_inverter_setting` take either a dictionary or an array. If an array is passed it will automatically generate the `paramN` key based on array index since all params for settings seem to used the same numbering scheme.
8390

84-
Only the settings described above have been tested with `update_tlx_inverter_setting` and they all take only one single parameter. It is very likely that the function works with all settings returned by `tlx_get_enabled_settings`, but this has not been tested. A helper function `update_tlx_inverter_time_segment` is provided for the settings that require more than one parameter.
91+
Only the settings described above have been tested with `update_tlx_inverter_setting` and they all take only one single parameter. It is very likely that the function works with all settings returned by `tlx_get_enabled_settings`, but this has not been tested. A helper function `update_tlx_inverter_time_segment` is provided for the settings that require more than one parameter.
92+
93+
The `api.get_mix_inverter_settings` method can be used to get the current inverter settings for the specified serial number including charge/discharge schedule for hybrid systems.

examples/settings_example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
# Get plant settings - This is performed for us inside
5353
# 'update_plant_settings' but you can get ALL of the settings using this
5454
current_settings = api.get_plant_settings(plant_id)
55-
# pp.pprint(current_settings) # noqa: ERA001
55+
#pp.pprint(current_settings)
5656

57+
#Get mix inverter settings
58+
inverter_settings = api.get_mix_inverter_settings(device_sn)
59+
pp.pprint(inverter_settings)
5760

5861
# Change the timezone of the plant
5962
plant_settings_changes = {"plantTimezone": "0"}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import growattServer
2+
import getpass
3+
import pprint
4+
5+
"""
6+
This script demonstrates how to interface with the configuration settings of a plant and its classic inverters.
7+
It uses the `update_classic_inverter_setting` function to apply settings to a classic inverter.
8+
"""
9+
pp = pprint.PrettyPrinter(indent=4)
10+
11+
# Prompt user for username
12+
username = input("Enter username:")
13+
14+
# Prompt user to input password
15+
user_pass = getpass.getpass("Enter password:")
16+
17+
api = growattServer.GrowattApi(True, username)
18+
login_response = api.login(username, user_pass)
19+
20+
plant_list = api.plant_list(login_response['user']['id'])
21+
22+
# Simple logic to just get the first inverter from the first plant
23+
# Expand this using a for-loop to perform for more systems
24+
plant = plant_list['data'][0] # This is an array - we just take the first - would need a for-loop for more systems
25+
plant_id = plant['plantId']
26+
plant_name = plant['plantName']
27+
plant_info = api.plant_info(plant_id)
28+
29+
devices = api.device_list(plant_id)
30+
device = devices[0] # This is an array - we just take the first - would need a for-loop for more systems
31+
device_sn = device['deviceSn']
32+
device_type = device['deviceType']
33+
34+
# Turn inverter on
35+
print("Turning on inverter: %s" % (device_sn))
36+
37+
# Set up the default parameters
38+
default_parameters = {
39+
"action": "inverterSet",
40+
"serialNum": device_sn,
41+
}
42+
43+
parameters = {
44+
"paramId": "pv_on_off",
45+
"command_1": "0001", # 0001 to turn on, 0000 to turn off
46+
"command_2": "", # Empty string for command_2 as not used
47+
}
48+
response = api.update_classic_inverter_setting(default_parameters, parameters)
49+
print(response)

growattServer/base_api.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -761,16 +761,41 @@ def mix_detail( # noqa: D417
761761
"""
762762
date_str = self.__get_date_string(timespan, date)
763763

764-
response = self.session.post(
765-
self.get_url("newMixApi.do"),
766-
params={
767-
"op": "getEnergyProdAndCons_KW",
768-
"plantId": plant_id,
769-
"mixId": mix_id,
770-
"type": timespan.value,
771-
"date": date_str,
772-
},
773-
)
764+
response = self.session.post(self.get_url('newMixApi.do'), params={
765+
'op': 'getEnergyProdAndCons_KW',
766+
'plantId': plant_id,
767+
'mixId': mix_id,
768+
'type': timespan.value,
769+
'date': date_str
770+
})
771+
772+
return response.json().get('obj', {})
773+
774+
def get_mix_inverter_settings(self, serial_number):
775+
"""
776+
Gets the inverter settings related to battery modes
777+
Keyword arguments:
778+
serial_number -- The serial number (device_sn) of the inverter
779+
Returns:
780+
A dictionary of settings
781+
"""
782+
783+
default_params = {
784+
'op': 'getMixSetParams',
785+
'serialNum': serial_number,
786+
'kind': 0
787+
}
788+
response = self.session.get(self.get_url('newMixApi.do'), params=default_params)
789+
data = json.loads(response.content.decode('utf-8'))
790+
return data
791+
792+
def dashboard_data(self, plant_id, timespan=Timespan.hour, date=None):
793+
"""
794+
Get 'dashboard' data for specified timespan
795+
NOTE - All numerical values returned by this api call include units e.g. kWh or %
796+
- Many of the 'total' values that are returned for a Mix system are inaccurate on the system this was tested against.
797+
However, the statistics that are correct are not available on any other interface, plus these values may be accurate for
798+
non-mix types of system. Where the values have been proven to be inaccurate they are commented below.
774799
775800
return response.json().get("obj", {})
776801
@@ -1369,3 +1394,31 @@ def update_noah_settings( # noqa: D417
13691394
)
13701395
13711396
return response.json()
1397+
1398+
def update_classic_inverter_setting(self, default_parameters, parameters):
1399+
"""
1400+
Applies settings for specified system based on serial number
1401+
See README for known working settings
1402+
1403+
Arguments:
1404+
default_params -- Default set of parameters for the setting call (dict)
1405+
parameters -- Parameters to be sent to the system (dict or list of str)
1406+
(array which will be converted to a dictionary)
1407+
1408+
Returns:
1409+
JSON response from the server whether the configuration was successful
1410+
"""
1411+
settings_parameters = parameters
1412+
1413+
# If we've been passed an array then convert it into a dictionary
1414+
if isinstance(parameters, list):
1415+
settings_parameters = {}
1416+
for index, param in enumerate(parameters, start=1):
1417+
settings_parameters['param' + str(index)] = param
1418+
1419+
settings_parameters = {**default_parameters, **settings_parameters}
1420+
1421+
response = self.session.post(self.get_url('tcpSet.do'),
1422+
params=settings_parameters)
1423+
1424+
return response.json()

0 commit comments

Comments
 (0)