Use this runtime when Home Assistant cannot host the listener or when you want a separate Linux host for development and diagnostics. It exposes the same authenticated connector API consumed by the HACS integration and ESPHome-compatible tooling.
Python 3.12 or newer is required:
git clone https://github.com/valexi7/Huawei-Modbus-TLS-Server /opt/huawei-emma
cd /opt/huawei-emma
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
python modbus-server.pyThe zero-argument start loads .env, creates a random EMMA_API_TOKEN when absent,
generates a persistent CA/server certificate when absent, validates existing TLS files,
and starts:
- reverse Modbus/TLS listener on port
16100 - authenticated connector API on port
8088
Read the generated API token locally:
grep '^EMMA_API_TOKEN=' /opt/huawei-emma/.envNever commit .env, certificates, private keys, or tokens.
Configure the HACS integration in External connector mode with the Linux host,
port 8088, and EMMA_API_TOKEN. Configure EMMA's third-party management-system
connection with the Linux host on port 16100; import
/opt/huawei-emma/certs/ca-cert.pem into EMMA.
The HTTP bearer token protects Home Assistant-to-connector traffic. It is independent of the TLS CA that EMMA trusts.
The supplied unit expects this exact installation location:
sudo useradd --system --home-dir /opt/huawei-emma --shell /usr/sbin/nologin huawei-emma 2>/dev/null || true
sudo chown -R huawei-emma:huawei-emma /opt/huawei-emma
sudo cp /opt/huawei-emma/deploy/huawei-emma.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now huawei-emma.serviceCheck its health and logs:
sudo systemctl status huawei-emma.service
journalctl -u huawei-emma.service -fIf the unit reports /opt/huawei-emma does not exist, the project was installed in a
different directory. Move/clone it there or edit all unit paths consistently before
enabling the service.
cd /opt/huawei-emma
sudo -u huawei-emma git pull --ff-only
sudo -u huawei-emma .venv/bin/python -m pip install -r requirements.txt
sudo systemctl restart huawei-emma.serviceThe .env file and certs/ directory are local runtime state and are not changed by a
normal Git pull. Review release notes before upgrades that change certificate, token, or
catalog behavior.
Use --log-raw for Modbus frame summaries:
sudo systemctl stop huawei-emma.service
cd /opt/huawei-emma
sudo -u huawei-emma .venv/bin/python modbus-server.py --log-rawDo not use raw logs or screenshots to share bearer tokens. For direct API requests and TOU examples, see the connector API guide. For ESP32 migration, see the LilyGO T-ETH-Elite guide.