yasdi2mqtt
is an MQTT adapter for SMA inverters communicating over serial interface. It fetches spot values from attached devices in a fixed interval and publishes them via MQTT in JSON data format. Moreover, it also works with only a fraction of all inverters being online at the same time.
If you encounter any problems, please check out the new Discussions
tab.
Full Output Example
yasdi2mqtt
will publish a json payload via MQTT in the given update interval (channel $MQTT_TOPIC_PREFIX/<device_sn>
). Messages will be sent for each inverter individually and have the following format:
{"sn":000,"time":1586608779,"values": {
"Iac":12580,
"Uac":239,
"Fac":50.019998881965876,
"Pac":3006,
"Zac":0.17200000816956162,
"Riso":10000,
"dI":4,
"Upv-Ist":416,
"PPV":3013,
"E-Total":45358.538154414855,
"h-Total":47797.772832013434,
"h-On":51654.766385075491,
"Netz-Ein":9012,
"Seriennummer":000,
"E-Total DC":45694.108978657052,
"Status":"Mpp",
"Fehler":"-------"
}}
By default YASDI is configured to use directly attached RS485 adapters. Further information on how to set up IP-based hardware instead can be found here (German). To prevent permission problems, yasdi2mqtt
runs as container root in all showcased scenarios. Therefore, consider creating an unprivileged user for production builds.
TODO
- Check
yasdi.ini
configuration- The included blueprint is meant to be used with serial adapters, but IP-based communication should be possible as well (see YASDI reference)
- Create empty
devices
directory- YASDI will use this folder as device cache, so you'll save the 1-2 minutes for device data download after second startup
- Edit
docker-compose.yml
file- See the table below for environment variables (section
environment
) - Adjust serial adapter path (section
devices
) if not mapped to/dev/ttyUSB0
or drop it for IP-based setup
- See the table below for environment variables (section
docker-compose up
- After starting up,
yasdi2mqtt
should immediately connect to your MQTT broker - Detected devices will be printed to console, the first MQTT message might take 1-2 minutes more because of device data download
- After starting up,
Docker Setup Instructions
- Check
yasdi.ini
configuration- The included blueprint is meant to be used with serial adapters, but IP-based communication should be possible as well (see YASDI reference)
- Create empty
devices
directory- YASDI will use this folder as device cache, so you'll save the 1-2 minutes for device data download after second startup
- Start container with following command:
docker run \
--device /dev/ttyUSB0:/dev/ttyUSB0 \
-v <project_dir>/devices:/etc/yasdi2mqtt/devices \
-v <project_dir>/yasdi.ini:/etc/yasdi2mqtt/yasdi.ini:ro \
-e YASDI_CONFIG="/etc/yasdi2mqtt/yasdi.ini" \
-e YASDI_DRIVER_ID="0" \
-e YASDI_MAX_DEVICE_COUNT="1" \
-e YASDI_UPDATE_INTERVAL="30" \
-e MQTT_TOPIC_PREFIX="/solar/inverter" \
-e MQTT_SERVER="example.com" \
-e MQTT_PORT="1883" \
-e MQTT_USER="johndoe" \
-e MQTT_PASSWORD="sEcReT" \
pkwagner/yasdi2mqtt
Manual Setup Instructions (consider using docker-compose or docker instead)
- Install cJSON, other project's dependencies and build toolchain
sudo apt install git gcc make cmake openssl libssl-dev libcjson1 libcjson-dev
for Ubuntu-based distributions
- Clone and install Paho
make
sudo make install
- Clone and install log.c
gcc -shared -fPIC -DLOG_USE_COLOR -o liblog_c.so src/log.c
sudo cp liblog_c.so /usr/local/lib
to install system-widesudo cp src/*.h /usr/local/include
to make headers available system-wide
- Clone and install YASDI
mkdir projects/generic-cmake/build-gcc
cd projects/generic-cmake/build-gcc
cmake -D YASDI_DEBUG_OUTPUT=0 ..
make
sudo make install
- Clone and install this repository
make YASDI_PATH=<yasdi_dir>
sudo make YASDI_PATH=<yasdi_dir> install
- Check
yasdi.ini
configuration- The included blueprint is meant to be used with serial adapters, but IP-based communication should be possible as well (see YASDI reference)
- Create empty
devices
directory- YASDI will use this folder as device cache, so you'll save the 1-2 minutes for device data download after second startup
- Set required environment variables according to the table below
./yasdi2mqtt
- After starting up,
yasdi2mqtt
should immediately connect to your MQTT broker - Detected devices will be printed to console, the first MQTT message might take 1-2 minutes more because of device data download
- After starting up,
Variable | Description | Example value |
---|---|---|
YASDI_CONFIG | Path to yasdi.ini file Inside container, shouldn't be changed therefore |
/etc/yasdi2mqtt/yasdi.ini |
YASDI_DRIVER_ID | ID of driver declared in yasdi.ini to use |
0 |
YASDI_MAX_DEVICE_COUNT | Maximum number of devices being online at the same time | 1 |
YASDI_UPDATE_INTERVAL | Time between value update requests in seconds Value update itself takes some time, so it shouldn't be lower than 15 from my experience |
30 |
MQTT_TOPIC_PREFIX | MQTT messages will later be published to topic $MQTT_TOPIC_PREFIX/<device_sn> |
solar/inverter |
MQTT_SERVER | example.com | |
MQTT_PORT | 1883 | |
MQTT_SSL_CERT | Optional Path to cert.pem fileIf you want to use MQTTS, you have to define the path to the cert here and add the cert to the container (e.g. mount a volume) |
/etc/certs/cert.pem |
MQTT_QOS_LEVEL | Optional See here for explanation. |
2 |
MQTT_USER | Optional | johndoe |
MQTT_PASSWORD | Optional | sEcReT |
LOG_LEVEL | Optional Set 0 to enable debug output |
0 |
If you stuck during setup, there are a few options you can check to make yasdi2mqtt
more verbose. When using custom build settings, you always need to compile your own container with docker build -t yasdi2mqtt .
afterwards.
- Enable debug output of
yasdi2mqtt
itself (see variableLOG_LEVEL
in the table below) - Replace
YASDI_DEBUG_OUTPUT=0
byYASDI_DEBUG_OUTPUT=1
inDockerfile
to activateYASDI
debug output- When using manual setup method, replace parameter during YASDI install directly