Skip to content

Instantly share code, notes, and snippets.

@petermolnar
Created November 2, 2022 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermolnar/de57332d0b599db6a6913d0f178b2643 to your computer and use it in GitHub Desktop.
Save petermolnar/de57332d0b599db6a6913d0f178b2643 to your computer and use it in GitHub Desktop.
domoticz and home assistant MQTT auto-discovery kickoff for local MQTT from Glow SMETS2 CAD
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment