forked from bitlair/ansible
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:
parent
b1ab5e0c14
commit
087a8619cf
4 changed files with 26 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
# Managed by Ansible
|
||||
# {{ ansible_managed }}
|
||||
|
||||
[Unit]
|
||||
Description={{ description }}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# {{ ansible_managed }}
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
import paho.mqtt.subscribe as subscribe
|
||||
from time import sleep
|
||||
import os
|
||||
import requests
|
||||
|
||||
|
||||
sdm630_host = '100.64.0.187'
|
||||
mqtt_host = '{{ mqtt_internal_host }}'
|
||||
(net, sdm630_host) = os.argv[1].split('/')
|
||||
|
||||
|
||||
client = mqtt.Client()
|
||||
|
@ -19,10 +22,10 @@ while True:
|
|||
try:
|
||||
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/All/now_w', data['active_power_w'])
|
||||
client.publish('bitlair/power/L1/now_w', data['active_power_l1_w'])
|
||||
client.publish('bitlair/power/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}/All/now_w', data['active_power_w'])
|
||||
client.publish(f'bitlair/power/{net}/L1/now_w', data['active_power_l1_w'])
|
||||
client.publish(f'bitlair/power/{net}/L2/now_w', data['active_power_l2_w'])
|
||||
client.publish(f'bitlair/power/{net}/L3/now_w', data['active_power_l3_w'])
|
||||
except Exception as err:
|
||||
print(err)
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue