forked from bitlair/ansible
27 lines
822 B
Python
27 lines
822 B
Python
#!/usr/bin/env python3
|
|
|
|
import paho.mqtt.client as mqtt
|
|
import paho.mqtt.subscribe as subscribe
|
|
from time import sleep
|
|
import requests
|
|
|
|
|
|
sdm630_host = '100.64.0.187'
|
|
mqtt_host = '{{ mqtt_internal_host }}'
|
|
|
|
|
|
client = mqtt.Client()
|
|
client.connect(mqtt_host, 1883, 60)
|
|
|
|
while True:
|
|
sleep(1)
|
|
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'])
|
|
except Exception as err:
|
|
print(err)
|
|
continue
|