Skip to main content

Read and manipulate Sungrow inverters

Project description

pysungrow - Python interface to Sungrow inverters

PyPI PyPI - Python Version PyPI - Status GitHub CI

This Python package provides abstractions over the Modbus protocol used by inverters of the brand Sungrow.

Features

  • Both getting and setting data
  • Fully async
  • Fully typed
  • Supports most forms of Modbus (TCP, UDP, TLS and Serial)
  • (Theoretically) supports most Sungrow inverters, both string and hybrid
  • High test coverage

Supported inverters

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.

Getting started

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.

Usage

Getting data from the inverter

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"]).

Controlling the inverter

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)

Contributing

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

Acknowledgements

There are a few other similar projects available (however neither of them fit my needs):

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysungrow-1.1.0.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

pysungrow-1.1.0-py3-none-any.whl (25.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page