Skip to main content

📊🏠🔌☀ HomeAssistant Huawei SUN2000 Exporter

Prometheus exporter providing metrics from a HomeAssistant instance about a Huawei SUN2000 inverter.

Why?

  • HomeAssistant's Prometheus integration is currently broken (see issue #80656 and issue #104803 for example).
  • The SUN2000's TCP modbus interface can always just talk to one single client at a time, therefore using a direct modbus connection to the inverter would interfere with HomeAssistant's data scraping.
  • HomeAssistant provides stats through its built-in API anyway, so let's use them.

Until there is a better solution, this workaround does the job.

⚙🔧 How? ⚙🔧

Example installation on Debian / Ubuntu:

### all commands run as "root" or using "sudo" ###

# required for creating Python virtualenvs:
apt update
apt install -y python3-venv

# create a virtualenv in /opt:
python3 -m venv /opt/prometheus-hass-sun2k

# update 'pip' and install the 'prometheus-hass-sun2k' package:
/opt/prometheus-hass-sun2k/bin/pip install --upgrade pip
/opt/prometheus-hass-sun2k/bin/pip install prometheus-hass-sun2k

🏃 Running in foreground mode 🏃

Create a configuration file by copying the config-example.yaml file to e.g. config.yaml and adjust the settings there. Then run the exporter (from within the activated venv or using the full path) like this:

prometheus-hass-sun2k -vvv --config config.yaml

The exporter running in foreground can be terminated as usual via Ctrl+C.

👟 Running as a service 👟

# create a system user for running the service:
adduser --system --group has2k-exporter

# copy the configuration example, adjust permissions and edit it:
cp -v /opt/prometheus-hass-sun2k/lib/python*/site-packages/prometheus_hass_sun2k/resources/config-example.yaml /opt/prometheus-hass-sun2k/config.yaml
chgrp has2k-exporter /opt/prometheus-hass-sun2k/config.yaml
chmod 640 /opt/prometheus-hass-sun2k/config.yaml
editor /opt/prometheus-hass-sun2k/config.yaml

# install, register and adjust the systemd unit file:
cp -v /opt/prometheus-hass-sun2k/lib/python*/site-packages/prometheus_hass_sun2k/resources/systemd/prometheus-hass-sun2k.service  /etc/systemd/system/
systemctl daemon-reload
systemctl edit prometheus-hass-sun2k.service

The last command will open an editor with the override configuration of the service's unit file. Check the values from the provided example script (e.g. paths) and adjust as necessary.

Finally enable the service and start it right away. The second line will show the log messages on the console until Ctrl+C is pressed. This way you should be able to tell if the service has started up properly and is providing metrics on the configured port:

systemctl enable --now prometheus-hass-sun2k.service
journalctl --follow --unit prometheus-hass-sun2k

🆙 Upgrading 🆙

Assuming the exporter has been installed as described above, an upgrade to a newer version could be done like this:

/opt/prometheus-hass-sun2k/bin/pip install --upgrade prometheus-hass-sun2k
# check the changelog for potentially new configuration settings, integrate them
# if necessary and finally restart the service:
systemctl restart prometheus-hass-sun2k.service

Metadata

Release files for prometheus-hass-sun2k 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prometheus-hass-sun2k 0.2.0
File Size Uploaded
prometheus_hass_sun2k-0.2.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prometheus-hass-sun2k 0.2.0
File Interpreter ABI Platform
prometheus_hass_sun2k-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / prometheus_hass_sun2k-0.2.0.tar.gz

Download URL prometheus_hass_sun2k-0.2.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
65d982e78d461eab78a23ab0aa1bee9bb4e11b1b6049b1f85679be6d15042abb
BLAKE2b-256 checksum
How to use checksums
6592f92cb2a2adacf4503d42d9ba41df82589e947fdd1afce8ddc7258ee2bca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/5.15.0-102-generic

Release files / prometheus_hass_sun2k-0.2.0-py3-none-any.whl

Download URL prometheus_hass_sun2k-0.2.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9eeb3eec2ccdbf8d90e64044ac97505b3b14615f96fc9cb00d5a94f6292ad933
BLAKE2b-256 checksum
How to use checksums
b09ac8f5c57352a93ceb2fc0440b922ca27152ff0c7054f2e92da35daf8d3d9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/5.15.0-102-generic

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page