MQTT Discovery for Diagnostic & Configuration

Hello together,

I recently started to add my MQTT sensors entities (which are delivered from the same micro-controller) to a new device with Mqtt discovery. That Feature is pretty nice and works fine with all that features, described here: [MQTT Discovery - Home Assistant]

But I would like to add some features (similar to Tasmota):

  1. Adding a new window with a name like “Diagnostic”
  2. Adding a button with sending a ping to the device

After reading the spec several times, I used a MQTT tool like https://mqtt-explorer.com/ to get a better feel for ‘real’ usage (would need SetOption19 1 now for Tasmota), then experimented with mosquitto_pub to manually send test discovery settings until they worked enough to code up (in this case Python).

My test was something like this… (not tested - copied from partial notes)

mosquitto_pub -d -h HOSTNAME --username 'USER' --pw "PASS" -t 'homeassistant/switch/grow-1_pump/config' --retain -m '{  "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" }'

The device should appear immediately, and use MQTT Explorer to delete the retained topics to remove it.

A simple button is pretty easy - advertise a switch, then set it back to OFF in code. There’s bound to be a way to get a push button rather than a faked-toggle.

If this helps, :heart: this post!

Entity category(ent_cat is the short version) is what you want for the separate windows with MQTT discovery. entity_category: sensor is the default and will bounce and give you an error if you try to put it through discovery.

"ent_cat":  "config"           
"entity_category": " diagnostic"

It works similarly in Tasmota integration if I recall, might have a slightly different name.

1 Like

thanks, for this super helpful link :slight_smile:
still using a lot MQTT discovery, necessary if you are coding your own mcu…

with diagnostic you can send many nice information about your device…

"entity_category": " diagnostic"

like for example, status, uptime, received msg, sent msg, etc.