all repos — glow-smets2-cad-mqtt-autodiscovery.py @ c4c649c4d00aae87b82cf66618c367c6a7129aa1


        
Peter Molnar github@petermolnar.net
Wed, 02 Nov 2022 16:28:22 +0000
commit

c4c649c4d00aae87b82cf66618c367c6a7129aa1

1 files changed, 78 insertions(+), 0 deletions(-)

jump to
A glow-smets2-cad-mqtt-autodiscovery.py

@@ -0,0 +1,78 @@

+import paho.mqtt.client as mqtt +import json + +client = mqtt.Client() + +# set the mqtt user and password if you have to +client.username_pw_set( + username="your mqtt user", password="your mqtt password" +) +# set the host and the port if you have to +client.connect("127.0.0.1", 1883) + +# this is a bit tricky to get; if you listen in on MQTT, eg: +# mosquitto_sub -v -P mqtt_password -u mqtt_user -h 127.0.0.1 -p 1883 -t '#' +# you'll see topics published from your CAD under the topic you set in the +# device settings like: +# [topic you set in the MQTT settings]/[numbers here]/SENSOR/electricitymeter {payload} +# those "numbers here" bit is the unit ID +# add that in the next line + +unitID = "ID OF YOUR GLOW CAD UNIT" + +device = { + "identifiers": [unitID], + "manufacturer": "Hildebrand", + "model": "Glow SMEST2 CAD", + "name": "Glow SMEST2 CAD", +} + +autoconfig = { + f"homeassistant/sensor/{unitID}/electricitymeter/config": { + "device": device, + "device_class": "energy", + "enabled_by_default": True, + "name": "Electricity Meter", + "state_class": "total_increasing", + "state_topic": f"glow/{unitID}/SENSOR/electricitymeter", + "unique_id": f"{unitID}_electricitymeter", + "unit_of_measurement": "kW", + "value_template": "{{ value_json.electricitymeter.energy.import.cumulative }}", + }, + f"homeassistant/sensor/{unitID}/powermeter/config": { + "device": device, + "device_class": "energy", + "enabled_by_default": True, + "name": "Current Electricity Power", + "state_class": "measurement", + "state_topic": f"glow/{unitID}/SENSOR/electricitymeter", + "unique_id": f"{unitID}_powermeter", + "unit_of_measurement": "kW", + "value_template": "{{ value_json.electricitymeter.power.value }}", + }, + f"homeassistant/sensor/{unitID}/gaskwhmeter/config": { + "device": device, + "device_class": "energy", + "enabled_by_default": True, + "name": "Gas Meter (kWh)", + "state_class": "total_increasing", + "state_topic": f"glow/{unitID}/SENSOR/gasmeter", + "unique_id": f"{unitID}_gaskwhmeter", + "unit_of_measurement": "kW", + "value_template": "{{ value_json.gasmeter.energy.import.cumulative }}", + }, + f"homeassistant/sensor/{unitID}/gasvolmeter/config": { + "device": device, + "device_class": "energy", + "enabled_by_default": True, + "name": "Gas Meter (m3)", + "state_class": "total_increasing", + "state_topic": f"glow/{unitID}/SENSOR/gasmeter", + "unique_id": f"{unitID}_gasvolmeter", + "unit_of_measurement": "m3", + "value_template": "{{ value_json.gasmeter.energy.import.cumulativevol }}", + }, +} + +for topic, pl in autoconfig.items(): + client.publish(topic, payload=json.dumps(pl), qos=0, retain=True)