Access APSystems ECU data over MQTT
Project description
APS2MQTT
Allows you to access your APsystems Energy Communication Unit (ECU) data by MQTT. This MQTT bridge queries the ECU directly at regular interval for new data, parse the returned data and publish them over MQTT.
In this way you can integrate your APsystems devices with whatever smart home infrastructure you are using.
:warning: It currently supports only one ECU.
Acknowledgements
This work is based on the awesome homeassistant-apsystems_ecur (v1.2.30). This couldn't have been done without their hardwork.
Prerequisites
- A compatible APSystems ECU
- ECU-B
- ECU-R
- ECU-C
- Some inverters
- YC1000/QT2
- YC600/DS3/DS3-H/DS3-L/DS3D
- QS1/QS1A
Your ECU needs to be fully configured by the EMA Manager and should have a fixed IP address. APS2MQTT should run on a machine in the same network (or in an accessible one) as the ECU.
ECU-C and modern ECU-R (ID starting with 2162) can be automatically restarted in case of connection error. For older ECU-R and for ECU-B, the restart need to be done manually.
Test your connection
You can test the connection between APS2MQTT and the ECU using Netcat. From your terminal, run the following command (assuming your ECU IP address is 192.168.1.42) to open the connection
nc -v 192.168.1.42 8899
ECU should response with an "open" message
192.168.1.42 (192.168.1.42:8899) open
Connection is now established, the ECU is ready to receive commands
APS1100160001END
If this command return with an APS message, you are ready to start APS2MQTT. If not, rebbot your ECU and try again.
Install
Binaries are available in the release asset or on PyPI. Using a virtual env is recommended for better insulation.
# with PyPI
pip3 install aps2mqtt
# manually
pip3 install aps2mqtt-[version]-py3-none-any.whl
Start it
python3 -m aps2mqtt -h
Run as a service
Using systemd, APS2MQTT can be started automatically
[Unit]
Description=APS2MQTT
After=multi-user.target
[Service]
Type=simple
User=user
Restart=on-failure
ExecStart=/path-to-your-venv/python3 -m aps2mqtt -c config.yaml
[Install]
WantedBy=multi-user.target
Configuration
APS2MQTT configuration can be provided by a yaml config file or by environment variables (in a container context for example).
MQTT
| Key | Description | Example | Default value |
|---|---|---|---|
| MQTT_BROKER_HOST | Host of the MQTT broker | "192.168.1.1", "broker.hivemq.com" | "127.0.0.1" |
| MQTT_BROKER_PORT | Port of the MQTT broker | 1883 | 1883 |
| MQTT_BROKER_USER | User login of the MQTT broker | "john-doe" | "" |
| MQTT_BROKER_PASSWD | User password of the MQTT broker | "itsasecret" | "" |
| MQTT_CLIENT_ID | Client ID if the MQTT client | "MyAwesomeClient" | "APS2MQTT" |
| MQTT_TOPIC_PREFIX | Topic prefix for publishing | "my-personal-topic" | "" |
| MQTT_RETAIN | Retain MQTT messages | True | False |
| MQTT_DISCOVERY_ENABLED | Enable MQTT discovery | True | False |
| MQTT_DISCOVERY_PREFIX | MQTT discovery prefix | "homeassistant" | "homeassistant" |
| MQTT_BROKER_SECURED_CONNECTION | Use secure connection to MQTT broker | True | False |
| MQTT_BROKER_CACERTS_PATH | Path to the cacerts file | "/User/johndoe/.ssl/cacerts" | None |
ECU
| Key | Description | Example | Default value |
|---|---|---|---|
| APS_ECU_IP | IP of the ECU | "192.168.1.42" | None, this field id mandatory |
| APS_ECU_PORT | Communication port of the ECU | 8899 | 8899 |
| APS_ECU_TIMEZONE | Timezone of the ECU | 'Europe/Paris' | None (use system timezone) |
| APS_ECU_AUTO_RESTART | Automatically restart ECU in case of error | True | False |
| APS_ECU_WIFI_SSID | SSID of the ECU Wifi :information_source: Only used if automatic restart is enabled |
"My Wifi" | "" |
| APS_ECU_WIFI_PASSWD | Password of the ECU Wifi :information_source: Only used if automatic restart is enabled |
"secret-key" | "" |
| APS_ECU_STOP_AT_NIGHT | Stop ECU query during the night | True | False |
| APS_ECU_POSITION_LAT | Latitude of the ECU, used to retrieve sunset and sunrise :information_source: Only used if stop at night is enabled |
51.49819 | 48.864716 (Paris) |
| APS_ECU_POSITION_LNG | Longitude of the ECU, used to retrieve sunset and sunrise :information_source: Only used if stop at night is enabled |
-0.13087 | 2.349014 (Paris) |
Timezone
Without any specific configuration, aps2mqtt use your system's timezone as a reference.
-
If you use aps2mqtt as a python application, setting the ECU timezone is recommended by setting the configuration variable 'APS_ECU_TIMEZONE' for better processing.
-
If you are using aps2mqtt as a Docker image, you can configure the timezone for the whole container using the environement variable 'TZ'
MQTT Discovery
APS2MQTT supports MQTT discovery for seamless integration with home automation platforms like Home Assistant.
When enabled, aps2mqtt will publish configuration messages to the specified discovery prefix. These messages allow your home automation platform to automatically discover and configure the ECU and all its associated inverters and panels as devices and entities.
To enable this feature, set the MQTT_DISCOVERY_ENABLED option to True in your configuration.
mqtt:
# ... other mqtt settings
MQTT_DISCOVERY_ENABLED: True
# Optional: Change the discovery prefix if your platform requires it
MQTT_DISCOVERY_PREFIX: 'homeassistant'
Once enabled, you should see the devices automatically appear in your home automation platform.
Example
Unsecured connection
ecu:
APS_ECU_IP: '192.168.1.42'
APS_ECU_TIMEZONE: 'Europe/Paris'
APS_ECU_STOP_AT_NIGHT: True
APS_ECU_POSITION_LAT: 47.206
APS_ECU_POSITION_LNG: -1.5645
mqtt:
MQTT_BROKER_HOST: '192.168.1.12'
MQTT_BROKER_PORT: 1883
MQTT_BROKER_USER: 'johndoe'
MQTT_BROKER_PASSWD: 'itsasecret'
MQTT_RETAIN: True
MQTT_DISCOVERY_ENABLED: True
Secured connection
ecu:
APS_ECU_IP: '192.168.1.42'
APS_ECU_TIMEZONE: 'Europe/Paris'
APS_ECU_STOP_AT_NIGHT: True
APS_ECU_POSITION_LAT: 47.206
APS_ECU_POSITION_LNG: -1.5645
mqtt:
MQTT_BROKER_HOST: 'broker.hivemq.com'
MQTT_BROKER_PORT: 8883
MQTT_BROKER_SECURED_CONNECTION: True
MQTT_DISCOVERY_ENABLED: True
MQTT_DISCOVERY_PREFIX: 'custom_discovery'
Using Docker Compose
services:
aps2mqtt:
image: fligneul/aps2mqtt:latest
restart: always
environment:
- TZ=Europe/Paris
- DEBUG=True
- APS_ECU_IP=192.168.1.42
- APS_ECU_STOP_AT_NIGHT=True
- APS_ECU_POSITION_LAT=47.206
- APS_ECU_POSITION_LNG=-1.5645
- MQTT_BROKER_HOST=broker.hivemq.com
- MQTT_BROKER_PORT=8883
- MQTT_BROKER_USER=johndoe
- MQTT_BROKER_PASSWD=itsasecret
- MQTT_BROKER_SECURED_CONNECTION=True
Breaking Changes
With the introduction of MQTT Discovery, the MQTT topic structure has changed significantly to align with Home Assistant's best practices for discovery. Previously, each data point was published to a separate topic (e.g., aps/[ECU_ID]/power). Now, data for an ECU or an inverter is published as a single JSON payload to a base topic (e.g., aps/[ECU_ID] or aps/[ECU_ID]/[INVERTER_ID]).
Migration Steps:
-
Enable MQTT Discovery: It is highly recommended to enable MQTT Discovery by setting
MQTT_DISCOVERY_ENABLED: Truein yourmqttconfiguration. This will automatically configure your devices in Home Assistant. -
Update Manual Configurations: If you were previously using manual MQTT sensor configurations in Home Assistant (or any other platform), you will need to update them to reflect the new JSON payload structure and base topics. You will need to use
value_templateto extract the specific values from the JSON payload.Example (Old vs. New for ECU Power):
Old (Manual Sensor):
mqtt: sensor: - name: "ECU Power" state_topic: "aps/123456789/power" unit_of_measurement: "W"
New (Manual Sensor - if not using discovery):
mqtt: sensor: - name: "ECU Power" state_topic: "aps/123456789" unit_of_measurement: "W" value_template: "{{ value_json.current_power }}"
Similar changes will be required for all inverter and panel sensors.
MQTT topics
The aps2mqtt retrieves data from the entire PV array as a whole, as well as detailed information for each individual inverter.
aps/status- Current status of theaps2mqttservice, publishingonlineoroffline. Theofflinemessage is sent as a Last Will and Testament (LWT) message by the MQTT broker upon unexpected disconnection. This topic is also used as theavailability_topicfor MQTT Discovery.
ECU data
aps/[ECU_ID]- Publishes a JSON payload containing the following data for the entire ECU:current_power- Total amount of power (in W) being generated right now.today_energy- Total amount of energy (in kWh) generated today.lifetime_energy- Total amount of energy (in kWh) generated from the lifetime of the array.
Inverter data
aps/[ECU_ID]/[INVERTER_ID]- Publishes a JSON payload containing the following data for each individual inverter:online-Trueif the inverter is communicating with the ECU,Falseotherwise.signal- The signal strength of the zigbee connection.temperature- The temperature of the inverter in your local unit (C or F).frequency- The AC power frequency (in Hz).power- The current power generation (in W), sum of all panel power.voltage- The AC voltage (in V).panel_[ID]_power- The current power generation (in W) of the selected panel.panel_[ID]_voltage- The AC voltage (in V) of the selected panel.
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 aps2mqtt-2.0.2.tar.gz.
File metadata
- Download URL: aps2mqtt-2.0.2.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23b07d637334540f8bc6f769818da4c4baaeac0fec36f05a71e3e6155303ef40
|
|
| MD5 |
d3895b2c6d6e6ceb1994a819d47689b2
|
|
| BLAKE2b-256 |
20f27cfdb827d30e320087b59e78d3e165b3430283247f2f7dc30e1f10978cb9
|
Provenance
The following attestation bundles were made for aps2mqtt-2.0.2.tar.gz:
Publisher:
release.yml on fligneul/aps2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aps2mqtt-2.0.2.tar.gz -
Subject digest:
23b07d637334540f8bc6f769818da4c4baaeac0fec36f05a71e3e6155303ef40 - Sigstore transparency entry: 303066704
- Sigstore integration time:
-
Permalink:
fligneul/aps2mqtt@ebe97dd1fbd98f8e464065475c92daa715973783 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fligneul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ebe97dd1fbd98f8e464065475c92daa715973783 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aps2mqtt-2.0.2-py3-none-any.whl.
File metadata
- Download URL: aps2mqtt-2.0.2-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46061ef50e33102cc05876db426ef4ae1c74510c75cead7cfe8f77cfb5ca67e9
|
|
| MD5 |
f7927541c6d9b3bbf4f2cb9faf82b2b0
|
|
| BLAKE2b-256 |
e8dafd0c42c134539985ad43b7bfc712545ce8f7447156ba31a94fb50b475c1a
|
Provenance
The following attestation bundles were made for aps2mqtt-2.0.2-py3-none-any.whl:
Publisher:
release.yml on fligneul/aps2mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aps2mqtt-2.0.2-py3-none-any.whl -
Subject digest:
46061ef50e33102cc05876db426ef4ae1c74510c75cead7cfe8f77cfb5ca67e9 - Sigstore transparency entry: 303066717
- Sigstore integration time:
-
Permalink:
fligneul/aps2mqtt@ebe97dd1fbd98f8e464065475c92daa715973783 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fligneul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ebe97dd1fbd98f8e464065475c92daa715973783 -
Trigger Event:
push
-
Statement type: