services: Add SMD630 to MQTT glue script
This commit is contained in:
parent
7e72905165
commit
24980f5e7e
7 changed files with 71 additions and 0 deletions
|
@ -8,6 +8,7 @@ prometheus:
|
||||||
export:
|
export:
|
||||||
- subscribe: bitlair/#
|
- subscribe: bitlair/#
|
||||||
- subscribe: bitlair/climate/+location/#
|
- subscribe: bitlair/climate/+location/#
|
||||||
|
- subscribe: bitlair/power/+group/#
|
||||||
- subscribe: bitlair/wifi/+ssid/#
|
- subscribe: bitlair/wifi/+ssid/#
|
||||||
|
|
||||||
- subscribe: bitlair/state
|
- subscribe: bitlair/state
|
||||||
|
|
|
@ -13,6 +13,7 @@ topic bitlair/music/+/state out
|
||||||
topic bitlair/music/+/volume out
|
topic bitlair/music/+/volume out
|
||||||
topic bitlair/photos out
|
topic bitlair/photos out
|
||||||
topic bitlair/pos/product out
|
topic bitlair/pos/product out
|
||||||
|
topic bitlair/power/# out
|
||||||
topic bitlair/state out
|
topic bitlair/state out
|
||||||
topic bitlair/state/djo out
|
topic bitlair/state/djo out
|
||||||
topic bitlair/wifi/+/online out
|
topic bitlair/wifi/+/online out
|
||||||
|
|
|
@ -54,3 +54,9 @@
|
||||||
name: wifi-mqtt
|
name: wifi-mqtt
|
||||||
state: restarted
|
state: restarted
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
|
|
||||||
|
- name: restart power-mqtt
|
||||||
|
systemd:
|
||||||
|
name: power-mqtt
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
|
|
@ -19,3 +19,6 @@
|
||||||
|
|
||||||
- tags: services_wifi_mqtt
|
- tags: services_wifi_mqtt
|
||||||
import_tasks: wifi_mqtt.yaml
|
import_tasks: wifi_mqtt.yaml
|
||||||
|
|
||||||
|
- tags: services_power_mqtt
|
||||||
|
import_tasks: power_mqtt.yaml
|
||||||
|
|
25
roles/services/tasks/power_mqtt.yaml
Normal file
25
roles/services/tasks/power_mqtt.yaml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
- name: Install power-mqtt
|
||||||
|
template:
|
||||||
|
src: power-mqtt.sh
|
||||||
|
dest: /var/lib/power-mqtt.sh
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
notify: restart power-mqtt
|
||||||
|
|
||||||
|
- name: Install power-mqtt service
|
||||||
|
template:
|
||||||
|
src: power-mqtt.service
|
||||||
|
dest: /etc/systemd/system/power-mqtt.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: restart power-mqtt
|
||||||
|
|
||||||
|
- name: Start power-mqtt
|
||||||
|
systemd:
|
||||||
|
name: power-mqtt
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: true
|
||||||
|
|
16
roles/services/templates/power-mqtt.service
Normal file
16
roles/services/templates/power-mqtt.service
Normal 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
|
||||||
|
|
19
roles/services/templates/power-mqtt.sh
Normal file
19
roles/services/templates/power-mqtt.sh
Normal 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
|
Loading…
Add table
Reference in a new issue