services/power_mqtt: New config for Space 4

The power meters are not online yet, so this is not tested
This commit is contained in:
polyfloyd 2024-07-03 21:47:43 +02:00
parent b1ab5e0c14
commit 087a8619cf
4 changed files with 26 additions and 14 deletions

View file

@ -15,7 +15,7 @@ export:
- subscribe: bitlair/# - subscribe: bitlair/#
- subscribe: bitlair/climate/+location/# - subscribe: bitlair/climate/+location/#
- subscribe: bitlair/climate/+location/dust_mass/+size - subscribe: bitlair/climate/+location/dust_mass/+size
- subscribe: bitlair/power/+group/# - subscribe: bitlair/power/+net/+group/#
- subscribe: bitlair/wifi/+ssid/# - subscribe: bitlair/wifi/+ssid/#
- subscribe: bitlair/state - subscribe: bitlair/state

View file

@ -12,22 +12,31 @@
mode: 0755 mode: 0755
notify: restart power-mqtt notify: restart power-mqtt
- name: Remove old service
file:
path: /etc/systemd/system/power-mqtt.service
state: absent
- name: Install power-mqtt service - name: Install power-mqtt service
template: template:
src: generic.service src: generic.service
dest: /etc/systemd/system/power-mqtt.service dest: /etc/systemd/system/power-mqtt@.service
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
vars: vars:
description: SMD630 to MQTT Probe description: "SMD630 to MQTT Probe"
exec: /var/lib/power-mqtt.py exec: "/var/lib/power-mqtt.py %i"
notify: restart power-mqtt notify: restart power-mqtt@
- name: Start power-mqtt - name: Enable power-mqtt
systemd: systemd:
name: power-mqtt name: "power-mqtt@{{ item.net }}/{{ item.ip }}"
state: started state: started
enabled: yes enabled: yes
daemon_reload: true daemon_reload: true
with_items:
- net: space
ip: 0.0.0.0
- net: unicorndept
ip: 0.0.0.0

View file

@ -1,4 +1,4 @@
# Managed by Ansible # {{ ansible_managed }}
[Unit] [Unit]
Description={{ description }} Description={{ description }}

View file

@ -1,13 +1,16 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# {{ ansible_managed }}
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import paho.mqtt.subscribe as subscribe import paho.mqtt.subscribe as subscribe
from time import sleep from time import sleep
import os
import requests import requests
sdm630_host = '100.64.0.187'
mqtt_host = '{{ mqtt_internal_host }}' mqtt_host = '{{ mqtt_internal_host }}'
(net, sdm630_host) = os.argv[1].split('/')
client = mqtt.Client() client = mqtt.Client()
@ -19,10 +22,10 @@ while True:
try: try:
data = requests.get(f'http://{sdm630_host}/api/v1/data').json() data = requests.get(f'http://{sdm630_host}/api/v1/data').json()
client.publish('bitlair/power/total_kwh', data['total_power_import_kwh']) client.publish('bitlair/power/total_kwh', data['total_power_import_kwh'])
client.publish('bitlair/power/All/now_w', data['active_power_w']) client.publish(f'bitlair/power/{net}/All/now_w', data['active_power_w'])
client.publish('bitlair/power/L1/now_w', data['active_power_l1_w']) client.publish(f'bitlair/power/{net}/L1/now_w', data['active_power_l1_w'])
client.publish('bitlair/power/L2/now_w', data['active_power_l2_w']) client.publish(f'bitlair/power/{net}/L2/now_w', data['active_power_l2_w'])
client.publish('bitlair/power/L3/now_w', data['active_power_l3_w']) client.publish(f'bitlair/power/{net}/L3/now_w', data['active_power_l3_w'])
except Exception as err: except Exception as err:
print(err) print(err)
continue continue