services: Add SMD630 to MQTT glue script

This commit is contained in:
polyfloyd 2023-12-03 14:12:40 +01:00
parent 7e72905165
commit 24980f5e7e
7 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,16 @@
# Managed by Ansible
[Unit]
Description=SMD630 to MQTT Probe
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /var/lib/power-mqtt.sh
Restart=on-failure
RestartSec=10s
DynamicUser=true
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,19 @@
#!/bin/bash
# Managed by Ansible
set -euo pipefail
h="{{ mqtt_internal_host }}"
while true; do
j=$(curl -s http://100.64.0.187/api/v1/data)
mqtt-simple -h $h -p bitlair/power/total_kwh -m $(echo "$j" | jq .total_power_import_kwh)
mqtt-simple -h $h -p bitlair/power/All/now_w -m $(echo "$j" | jq .active_power_w)
mqtt-simple -h $h -p bitlair/power/L1/now_w -m $(echo "$j" | jq .active_power_l1_w)
mqtt-simple -h $h -p bitlair/power/L2/now_w -m $(echo "$j" | jq .active_power_l2_w)
mqtt-simple -h $h -p bitlair/power/L3/now_w -m $(echo "$j" | jq .active_power_l3_w)
sleep 1
done