MQTT discovery startup automation to gather tasmota device states

Hello,

I noticed that in the docs, MQTT discovery does not save states for devices between reboots.

The embedded MQTT broker does not save any messages between restarts. If you use the embedded MQTT broker you have to send the MQTT discovery messages after every Home Assistant restart for the devices to show up.

However, after trying a few things, it’s clear to me that I don’t know what you have to send the MQTT discovery messages after every Home Assistant restart means.

Does anyone know of a way to make an automation that will launch at startup that can do this step?

I am using tasmota devices, made from sonoff S31 outlets, and I would like the state to be accurate when I restart HA.

Thanks,

Randy

- id: '1565194745362'
  alias: Status starting HA
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      payload: ''
      topic: tasmotas/cmnd/status
    service: mqtt.publish
  - data:
      payload: ''
      topic: sonoffs/cmnd/status
    service: mqtt.publish

The tasmotas are for tasmota versions 7.x up, the sonoffs are for lower versions.

It works if your mqtt is configured like this :

If you have devices configured with %prefix%/%topic% , you need to use

- id: '1565194745362'
  alias: Status starting HA
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      payload: ''
      topic: cmnd/tasmotas/status
    service: mqtt.publish
  - data:
      payload: ''
      topic: cmnd/sonoffs/status
    service: mqtt.publish

Although it does not hurt to have them all 4 :slight_smile:

Thanks for the reply.
I tried that, and the automation does execute as expected. On the Tasmota device console I can see that the mqtt request comes in and the device returns the status as requested (in json). However, the status in Home Assistant still doesn’t update. It won’t update again until the device sends tele/tasmota_******/STATE , which I think it does every 5 mins.

Any ideas on what the UI won’t update when the status is sent?