Hi,
After writing a Python device using HASS Discovery, I found HASS changes configuration state almost immediately after I published the discovery topics to the broker. This made manual testing of the structure straightforward as the debug cycle was basically:
- Delete the previous retained topics using MQTT Explorer
- Publish new discovery data with
mosquitto_pub
on the command line - See what happened in HASS immediately
- Cross-check what the broker actually published using https://mqtt-explorer.com/ and not your code!
I’ve not touched the code for a year, but managed to get units, icons, etc all working by trial and error with no YAML config at all - all sensors and actuators created via HASS Discovery.
Unlike Tasmota Discovery, HASS Discovery is baked-into the MQTT add-on, so there’s nothing to configure.
My best guess is therefore something has changed in the interpretation of your HASS Discovery topics.
My code was based on (pre-Tasmota Discovery) Tasmota HASS discovery using FULL topics, without ~
, e.g.:
ChannelX mqtt_topic_state: tele/grow-1/SENSOR
/ tele/grow-1/LWT
homeassistant/sensor/grow-1_chan1/config = {
"name": "glz-rpi-grow Channel 1",
"stat_t": "tele/glz-rpi-grow/SENSOR",
"val_tpl": "{{value_json.Channel1}}",
"avty_t": "tele/glz-rpi-grow/LWT",
"pl_avail": "Online",
"pl_not_avail": "Offline",
"uniq_id": "glz-rpi-grow_chan1",
"dev": {
"ids": ["glz-rpi-grow"],
"name": "glz-rpi-grow",
"mf": "Pimoroni",
"mdl": "Grow",
"sw": "0.2",
"sa": "Conservatory"
},
"icon": "mdi:water-percent",
"dev_cla": "humidity",
"unit_of_meas": "%",
"expire_after": "1200",
"frc_upd": "true"
}
Tested MQTT command:
mosquitto_pub -d -h BROKER --username 'NAME' --pw "PW" -t 'homeassistant/sensor/grow-1_chan1/config' --retain -m '{"name":"Grow-1 Channel 1", "stat_t":"tele/grow-1/SENSOR", "val_tpl":"{{value_json.Channel1}}", "avty_t":"tele/grow-1/LWT", "pl_avail":"Online", "pl_not_avail":"Offline", "uniq_id":"grow-1_chan1", "dev": {"ids":["grow-1"], "name":"Grow 1", "mf":"Pimoroni", "mdl":"Grow", "sw":"0.2", "sa":"Conservatory"}, "icon":"mdi:sprout", "dev_cla":"humidity", "unit_of_meas":"%", "expire_after":"1200", "frc_upd": true}'
Example switch (driving an irrigation pump)
homeassistant/switch/grow-1_pump/config {
"name":"glz-rpi-grow Water 1",
"stat_t":"tele/glz-rpi-grow/PUMP/1",
"avty_t":"tele/glz-rpi-grow/LWT",
"pl_avail":"Online",
"pl_not_avail":"Offline",
"cmd_t":"cmnd/glz-rpi-grow/PUMP/1",
"pl_off":"OFF",
"pl_on":"ON",
"val_tpl":"{{value_json.POWER}}",
"uniq_id":"glz-rpi-grow_pump1",
"dev": {
"ids": ["glz-rpi-grow"],
"name": "glz-rpi-grow",
"mf": "Pimoroni",
"mdl": "Grow",
"sw": "0.2",
"sa": "Conservatory"
},
"icon": "mdi:watering-can",
"expire_after": "1200",
"frc_upd": "true"
}
I’d suggest a stare at the accurate, but not useful docs using the above examples!
If this helps, this post!