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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pysungrow-1.1.0.tar.gz.

File metadata

  • Download URL: pysungrow-1.1.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.13.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.16

File hashes

Hashes for pysungrow-1.1.0.tar.gz
Algorithm Hash digest
SHA256 48886c1bdd2f8534d4f6d2bf55cc8d44792b51b4af0a3f0be95b8fdda0913b4d
MD5 7de1ed5e4a91e7270b6823a1f702108e
BLAKE2b-256 bc56892ac21d980c9fe6e7954b8e16ef105428fda64073afe12541e47437db4a

See more details on using hashes here.

File details

Details for the file pysungrow-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pysungrow-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.13.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.16

File hashes

Hashes for pysungrow-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c3cf2947677a1690c192db8e63d3df0bd59a51644d08b21a24f4d558e97072b
MD5 be6f854a86b6e90014a64c9038ee97a5
BLAKE2b-256 505f1e0618d3f3f850a3aad64297437c6a8eff91b2018615f0aa191c6fbbdc98

See more details on using hashes here.

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