A Python wrapper for the Huawei Inverter modbus TCP API
Project description
Python library for connecting to Huawei SUN2000 Inverters over Modbus
This library implements an easy to use interface to locally connect to Huawei Solar devices 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.
Supported devices:
- SUN2000 inverters
- LUNA2000 batteries (when connected to SUN2000)
- EMMA
- SCharger (when connected to EMMA)
Features:
- Modbus-TCP support: connecting to the inverter via the SDongle, EMMA, 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
Installation
This library is published on PyPI.
Basic usage
The library consists out of a low level interface implemented in modbus_client.py which implements all the Modbus-operations, and a high level interface in huawei_solar/devices which facilitates easy usage (primarily meant for the HA integration).
Using the high level 'Devices' interface
An example on how to read the most interesting registers from the inverter:
import asyncio
from huawei_solar import (
SUN2000Device,
create_device_instance,
create_tcp_client,
)
from huawei_solar import register_names as rn
async def test() -> None:
"""Run test."""
client = create_tcp_client(host="192.168.1.1", port=503)
device = await create_device_instance(client)
assert isinstance(device, SUN2000Device)
print(
await device.batch_update(
[
rn.INPUT_POWER,
rn.LINE_VOLTAGE_A_B,
rn.LINE_VOLTAGE_B_C,
rn.LINE_VOLTAGE_C_A,
]
),
)
if __name__ == "__main__":
asyncio.run(main())
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')}
Frequently asked questions
Q: the connection is interrupted a few seconds after connecting to the Huawei Device. How do I solve this?
A:: Huawei devices only support one connection at a time. If your connection is interrupted, this is typically because another device is trying to (re-)connect to it. Disable that device and try again.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file huawei_solar-3.0.0.tar.gz.
File metadata
- Download URL: huawei_solar-3.0.0.tar.gz
- Upload date:
- Size: 107.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
370c57cc5741d00beb6677c5c5a2f7c190b9c9e2eea838362dbc2fbd639e6346
|
|
| MD5 |
267256f9f0a1baa15d437a8833b7cbc4
|
|
| BLAKE2b-256 |
041b2d092af5608c0a782857b51b273d76649de26b5420050fbf5aebb1851f67
|
Provenance
The following attestation bundles were made for huawei_solar-3.0.0.tar.gz:
Publisher:
pypi-publish.yml on wlcrs/huawei-solar-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
huawei_solar-3.0.0.tar.gz -
Subject digest:
370c57cc5741d00beb6677c5c5a2f7c190b9c9e2eea838362dbc2fbd639e6346 - Sigstore transparency entry: 1223554671
- Sigstore integration time:
-
Permalink:
wlcrs/huawei-solar-lib@b5401e39d1ce6614ccebf43e1dd6a0cad3ec6a4b -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/wlcrs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@b5401e39d1ce6614ccebf43e1dd6a0cad3ec6a4b -
Trigger Event:
push
-
Statement type:
File details
Details for the file huawei_solar-3.0.0-py3-none-any.whl.
File metadata
- Download URL: huawei_solar-3.0.0-py3-none-any.whl
- Upload date:
- Size: 88.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbed5a4f9b7be3d6f28311a83790f14272185ff3d2db6902dbf4b36af2df88f7
|
|
| MD5 |
fd7397c92efbe6667a428ff6279522e3
|
|
| BLAKE2b-256 |
3385a41cada7afaa4253193db8611f3ecdc76ab2304e86f21adc5367d1c6b78b
|
Provenance
The following attestation bundles were made for huawei_solar-3.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on wlcrs/huawei-solar-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
huawei_solar-3.0.0-py3-none-any.whl -
Subject digest:
bbed5a4f9b7be3d6f28311a83790f14272185ff3d2db6902dbf4b36af2df88f7 - Sigstore transparency entry: 1223554734
- Sigstore integration time:
-
Permalink:
wlcrs/huawei-solar-lib@b5401e39d1ce6614ccebf43e1dd6a0cad3ec6a4b -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/wlcrs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@b5401e39d1ce6614ccebf43e1dd6a0cad3ec6a4b -
Trigger Event:
push
-
Statement type: