glow-smets2-cad-mqtt-autodi.../glow-smets2-cad-mqtt-autodiscovery.py
Peter Molnar c4c649c4d0
2022-11-02 16:28:22 +00:00

78 lines
No EOL
2.8 KiB
Python

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)