Update in MQTT
This commit is contained in:
20
smart.py
20
smart.py
@@ -12,11 +12,11 @@ import random
|
||||
import paho.mqtt.publish as publish
|
||||
|
||||
# General config
|
||||
user= '1707910897002706169923_ECPR0002108185'
|
||||
# user= '1707911515002706169998_ECPR0002107915'
|
||||
# user= '1707910897002706169923_ECPR0002108185'
|
||||
user= '1707911515002706169998_ECPR0002107915'
|
||||
password = 'V!lhanhan03'
|
||||
meter-id= '1EFR2375175891'
|
||||
# meter-id= '1EFR2375175878'
|
||||
# meter_id= '1EFR2375175891'
|
||||
meter_id= '1EFR2375175878'
|
||||
|
||||
# MQTT config
|
||||
broker= 'homeassistant'
|
||||
@@ -69,28 +69,28 @@ for row in rows:
|
||||
}
|
||||
msgs = [
|
||||
{
|
||||
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_value",
|
||||
'topic': f"homeassistant/sensor/{meter_id}/{result_data['obis']}_value",
|
||||
'payload': result_data['value'], 'qos':1, 'retain': False
|
||||
},
|
||||
{
|
||||
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_unit",
|
||||
'topic': f"homeassistant/sensor/{meter_id}/{result_data['obis']}_unit",
|
||||
'payload': result_data['unit'], 'qos':1, 'retain': False
|
||||
},
|
||||
{
|
||||
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_timestamp",
|
||||
'topic': f"homeassistant/sensor/{meter_id}/{result_data['obis']}_timestamp",
|
||||
'payload': result_data['timestamp'], 'qos':1, 'retain': False
|
||||
},
|
||||
{
|
||||
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_isvalid",
|
||||
'topic': f"homeassistant/sensor/{meter_id}/{result_data['obis']}_isvalid",
|
||||
'payload': result_data['isvalid'], 'qos':1, 'retain': False
|
||||
},
|
||||
{
|
||||
'topic': f"homeassistant/sensor/{meter_id}_{result_data['obis']}_name",
|
||||
'topic': f"homeassistant/sensor/{meter_id}/{result_data['obis']}_name",
|
||||
'payload': result_data['name'], 'qos':1, 'retain': False
|
||||
}
|
||||
]
|
||||
results.append(result_data)
|
||||
publish.multiple(msgs, hostname= broker, port= mqttport,retained=False, auth={'username': mqttuser, 'password':mqttpass})
|
||||
publish.multiple(msgs, hostname= broker, port= mqttport, auth={'username': mqttuser, 'password':mqttpass})
|
||||
|
||||
# Ergebnisse ausgeben
|
||||
for result in results:
|
||||
|
||||
Reference in New Issue
Block a user