Skip to main content

A Python wrapper for the Huawei Inverter modbus TCP API

Project description

pipeline status PyPI version PyPI - Python Version PyPI - License Code style

Python library for connecting to Huawei SUN2000 Inverters over Modbus

This library implements an easy to use interface to locally connect to Huawei SUN2000 inverters over Modbus-TCP or Modbus-RTU following the 'Solar Inverter Modbus Interface Definitions' provided by Huawei.

It was primarily developed to add support for Huawei Solar inverters to Home Assistant, resulting in the following integration: wlcrs/huawei_solar.

Features:

  • Modbus-TCP support: connecting to the inverter via the SDongle, or over the WiFi-AP (SUN2000-<serial_no>) broadcasted by the inverter
  • Modbus-RTU support: connecting to the inverter via the RS485A1 and RS485B1 pins on the COM port
  • Batched reading of Modbus registers and converting them into the correct units
  • Reading Optimizer data via the specialized 'file' Modbus extension
  • Writing to Modbus registers (mostly useful for setting battery parameters)
  • Performing the login sequence to gain 'installer'-level access rights

Note t

Installation

This library is published on PyPI:

pip3 install huawei-solar

Basic usage

The library consists out of a low level interface implemented in huawei_solar.py which implements all the Modbus-operations, and a high level interface in bridge.py which facilitates easy usage (primarily meant for the HA integration).

Using the high level interface

An example on how to read the most interesting registers from the inverter:

bridge = await HuaweiSolarBridge.create(host="192.168.200.1", port=6607)
print(await bridge.batch_update([rn.INPUT_POWER, rn.LINE_VOLTAGE_A_B, rn.LINE_VOLTAGE_B_C, rn.LINE_VOLTAGE_C_A]))

This results in the following output being printed:

{'input_power': Result(value=82, unit='W'), 'line_voltage_A_B': Result(value=233.4, unit='V'), 'line_voltage_B_C': Result(value=0.0, unit='V'), 'line_voltage_C_A': Result(value=0.0, unit='V')}

Using the low level interface

Example code:

from huawei_solar import AsyncHuaweiSolar, register_names as rn

slave_id = 0
client = await AsyncHuaweiSolar.create("192.168.200.1", 6607, slave_id)

# Reading a single register

result = await bridge.client.get(rn.NB_PV_STRINGS, slave_id)
print("Number of PV strings: ", result.value)

# Batched reading of multiple registers
# Only possible when they are located closely to each other in the Modbus register space

results = await self.client.get_multiple([rn.LINE_VOLTAGE_A_B, rn.LINE_VOLTAGE_B_C, rn.LINE_VOLTAGE_C_A], self.slave_id)
print("A-B voltage: ", results[0].value)
print("B-C voltage: ", results[1].value)
print("C-A voltage: ", results[2].value)

A good starting point to learn how to use the low level interface is to look at how the high level interface in bridge.py uses it.

Acknowledgements

The initial implementation of v1 was done by @Emilv2.

Subsequent development on v2 was done by @wlcrs.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

huawei_solar-2.5.0.tar.gz (87.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huawei_solar-2.5.0-py3-none-any.whl (72.9 kB view details)

Uploaded Python 3

File details

Details for the file huawei_solar-2.5.0.tar.gz.

File metadata

  • Download URL: huawei_solar-2.5.0.tar.gz
  • Upload date:
  • Size: 87.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.23

File hashes

Hashes for huawei_solar-2.5.0.tar.gz
Algorithm Hash digest
SHA256 b5f5aa0dcb741d76f508f83bce4abdb766d9907a5810de2103ca0ce3747d8333
MD5 d4d93fd3800caeeafb76cf94f2d6c079
BLAKE2b-256 a3ae9c28b0046ad99fcf2a336aacf147aa3c1c4a08885a07d909c486deb7998b

See more details on using hashes here.

File details

Details for the file huawei_solar-2.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for huawei_solar-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10c75276aff71a13b02388f98992dca6d524f4240773f0c7e824489873806701
MD5 2ad4c5c4c4254cc9c02f293f2f84d601
BLAKE2b-256 ddcee78cb89c4815142d29290d9dfb7824a501fd92cd1c87c90997101dc09232

See more details on using hashes here.

Supported by

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