File: settings_example_classic.py

package info (click to toggle)
growattserver 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 392 kB
  • sloc: python: 1,722; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import getpass
import pprint

import growattServer

"""
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(f"Turning on inverter: {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)