Compare commits
3 commits
3ba4e0839e
...
24980f5e7e
Author | SHA1 | Date | |
---|---|---|---|
24980f5e7e | |||
7e72905165 | |||
731e58316c |
9 changed files with 76 additions and 4 deletions
|
@ -11,7 +11,7 @@ trusted_ranges:
|
||||||
- { v: ipv4, cidr: 185.205.52.194/32 }
|
- { v: ipv4, cidr: 185.205.52.194/32 }
|
||||||
- { v: ipv6, cidr: "::1" }
|
- { v: ipv6, cidr: "::1" }
|
||||||
- { v: ipv6, cidr: "fe80::/10" }
|
- { v: ipv6, cidr: "fe80::/10" }
|
||||||
- { v: ipv6, cidr: "2a02:166b:92::/64" }
|
- { v: ipv6, cidr: "2a02:166b:92::/48" }
|
||||||
|
|
||||||
mqtt_internal_host: mqtt.bitlair.nl
|
mqtt_internal_host: mqtt.bitlair.nl
|
||||||
mqtt_public_host: bitlair.nl
|
mqtt_public_host: bitlair.nl
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
- name: mqtt-internal
|
- name: mqtt-internal
|
||||||
tags: mqtt_internal
|
tags: mqtt_internal
|
||||||
block:
|
block:
|
||||||
- name: Install broker
|
- name: Install dependencies
|
||||||
apt:
|
apt:
|
||||||
name: mosquitto
|
name:
|
||||||
state: present
|
- mosquitto
|
||||||
|
- avahi-daemon
|
||||||
|
|
||||||
- name: Configure Mosquitto
|
- name: Configure Mosquitto
|
||||||
template:
|
template:
|
||||||
|
|
|
@ -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