Python package to talk to Sungrow inverters
MIT License
This Python package provides abstractions over the Modbus protocol used by inverters of the brand Sungrow.
Tested: SH10RT
In theory: SG60KTL, SG60KU, SG33KTL-M, SG36KTL-M, SG40KTL-M, SG50KTL-M, SG60KTL-M, SG60KU-M, SG49K5J, SG8KTL-M, SG10KTL-M, SG12KTL-M, SG80KTL, SG80KTL-M, SG80HV, SG125HV, SH5K-20, SH3K6, SH4K6, SH5K-V13, SH5K-30, SH3K6-30, SH4K6-30, SH5.0RS, SH3.6RS, SH4.6RS, SH6.0RS, SH8.0RT, SH6.0RT, SH5.0RT
Do you have an inverter that's not been tested yet? Please follow the instructions under Getting started including running the get
command, and report the result in a new issue.
Install using pip
:
pip install pysungrow
See below for usaging from Python. Also comes with a simple command line interface:
pysungrow [-p PORT] [-s SLAVE] [HOST] identify
pysungrow [-p PORT] [-s SLAVE] [HOST] get [-k KEY]
pysungrow [-p PORT] [-s SLAVE] [HOST] set [KEY] [VALUE]
It is recommended to start using these commands to verify that you can connect to your inverter successfully.
from pysungrow import identify, SungrowClient
from pymodbus.client import AsyncModbusTcpClient
async def example_get():
modbus_client = AsyncModbusTcpClient("192.168.1.228")
# first we need to identify the model of inverter...
serial_number, device, output_type = await identify(modbus_client)
# ...then we can create a client...
client = SungrowClient(modbus_client, device, output_type)
# ...using which we can get data
return await client.get("total_dc_power")
Note that the first call to client.get
will fetch all variables defined for your model of inverter. You can limit this by first manually triggering a fetch using await client.refresh(["total_dc_power"])
.
from pysungrow import identify, SungrowClient
from pysungrow.definitions.variables.hybrid import ChargeDischargeCommand
from pymodbus.client import AsyncModbusTcpClient
async def example_set():
modbus_client = AsyncModbusTcpClient("192.168.1.228")
# first we need to identify the model of inverter...
serial_number, device, output_type = await identify(modbus_client)
# ...then we can create a client...
client = SungrowClient(modbus_client, device, output_type)
# ...using which we can control the inverter
await client.set("charge_discharge_command", ChargeDischargeCommand.CHARGE)
Contributions are always welcome!
For code contributions please make sure that all automated checks pass. The easiest way to do this is using these commands:
pre-commit run --all-files
pytest
There are a few other similar projects available (however neither of them fit my needs):