Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/shinephone.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Any methods that may be useful.
| `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) |
| `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) |
| `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) |
| `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. |

### Variables

Expand Down
7 changes: 7 additions & 0 deletions docs/shinephone/inverter_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Known working settings & parameters are as follows (all parameter values are str
* start_time: timedate object with start time of segment with format HH:MM
* end_time: timedate object with end time of segment with format HH:MM
* enabled: time segment enabled, boolean: True (Enabled), False (Disabled)
* **Classic inverter settings**
* function: `api.update_classic_inverter_setting`
* description: Applies settings for specified system based on serial number. This function is only going to work for classic inverters.
* params:
* `param1`: First parameter (specific to the setting type)
* `param2`: Second parameter (specific to the setting type)
* Additional parameters can be passed as needed.

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.

Expand Down
49 changes: 49 additions & 0 deletions examples/settings_example_classic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import growattServer
import getpass
import pprint

"""
This script demonstrates how to interface with the configuration settings of a plant and its classic inverters.
It uses the `update_classic_inverter_setting` function to apply settings to a classic inverter.
"""
pp = pprint.PrettyPrinter(indent=4)

# Prompt user for username
username = input("Enter username:")

# Prompt user to input password
user_pass = getpass.getpass("Enter password:")

api = growattServer.GrowattApi(True, username)
login_response = api.login(username, user_pass)

plant_list = api.plant_list(login_response['user']['id'])

# Simple logic to just get the first inverter from the first plant
# Expand this using a for-loop to perform for more systems
plant = plant_list['data'][0] # This is an array - we just take the first - would need a for-loop for more systems
plant_id = plant['plantId']
plant_name = plant['plantName']
plant_info = api.plant_info(plant_id)

devices = api.device_list(plant_id)
device = devices[0] # This is an array - we just take the first - would need a for-loop for more systems
device_sn = device['deviceSn']
device_type = device['deviceType']

# Turn inverter on
print("Turning on inverter: %s" % (device_sn))

# Set up the default parameters
default_parameters = {
"action": "inverterSet",
"serialNum": device_sn,
}

parameters = {
"paramId": "pv_on_off",
"command_1": "0001", # 0001 to turn on, 0000 to turn off
"command_2": "", # Empty string for command_2 as not used
}
response = api.update_classic_inverter_setting(default_parameters, parameters)
print(response)
28 changes: 28 additions & 0 deletions growattServer/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,31 @@ def update_noah_settings(self, serial_number, setting_type, parameters):
data=settings_parameters)

return response.json()

def update_classic_inverter_setting(self, default_parameters, parameters):
"""
Applies settings for specified system based on serial number
See README for known working settings

Arguments:
default_params -- Default set of parameters for the setting call (dict)
parameters -- Parameters to be sent to the system (dict or list of str)
(array which will be converted to a dictionary)

Returns:
JSON response from the server whether the configuration was successful
"""
settings_parameters = parameters

# If we've been passed an array then convert it into a dictionary
if isinstance(parameters, list):
settings_parameters = {}
for index, param in enumerate(parameters, start=1):
settings_parameters['param' + str(index)] = param

settings_parameters = {**default_parameters, **settings_parameters}

response = self.session.post(self.get_url('tcpSet.do'),
params=settings_parameters)

return response.json()