Problem reloading Mqtt entities with latest update

I have updated to the latest HA which has the quick reload service. I am facing an issue with syncing my mqtt entities(tasmotas) now with this service. I have been using an automation which triggers when HA starts to reload all my mqtt devices. But when I use the quick reload, I dont have any triggers like Home assistant Start to trigger this automation so my entities are not reloaded. Is there any solution for this?

I’m not sure what you mean by this. The actions you use in an automation can not affect the triggers available.

Let me explain further.

I have some tasmota devices which doesn’t update itself soon after we restart home assistant. To make them force update soon after HA restart I have been using an automation like below. If this is not done, the device will be unknown until the telemetric message comes.

alias: Hassio Start Sync
  - event: start
    platform: homeassistant
condition: []
  - delay: "00:00:02"
  - data:
      payload: check
      topic: cmnd/tasmotas/state
      qos: 0
      retain: false
    service: mqtt.publish

This works fine.

Now in the latest update we have the quick reload option. When we use this, the mqtt devices states becomes unknown. Since this is not a Home assistant start event, the automation used like above wont trigger. So I have to manually trigger the automation. If there was any trigger like home assistant start in case of quick reload also, I could have used it with the above automation to force update states of mqtt devices.

Untested, but you could try adding this trigger:

    - platform: event
        - mqtt_reloaded

A better option would be to publish the Tasmota state messages (but not command messages or you will get “ghost” triggering) with the retain flag set. That way the state is always available to home assistant whenever it resubscribes to the topics (after a restart or reload). It is years since I have used Tasmota so I’m not sure if this is out of date but it explains how to set the retained flags correctly: Fix Random Switching in Tasmota by Adjusting Retain Settings - YouTube

This might not work because whe HA is rebooted, it doesnot stop the mosquittto mqtt addon. So the tasmota devices is not disconnected from mqtt. This could work in full system reboot as mqtt addon is also restarted.

It will work because it is the Home Assistant mqtt integration not the addon that disconnects then reconnects. When the reconnection occurs the broker sends retained messages to the client (home assistant mqtt integration) for any subscribed topics that contain retained messages.

Tried it, it didn’t work

Tried what?

I gave you two options.

this one i tried. The second method is of not full use to me as there are also non tasmota devices which updates its state with a particular mqtt message.

Yeah, as I said:

Worth a try.

As for the other method, you just have to spend the time making sure all the mqtt devices that are slow to update send retained state messages.

Should I open a request feature to add an an event with the start and end of quick reload function to negate such issues.

You should fix your devices so they send retained state messages.

Also try this trigger:

  - platform: event
    event_type: event_mqtt_reloaded

again, untested.

They send messages but only according to the set teleperiod. When HA restarts, we have force update the states or else HA will have to wait till telemetric messages comes.

this event worked. Thanks bro

1 Like

But if the messages are retained in the broker (i.e. the messages are sent from the devices with the retained flag set) then as soon as the Home Assistant mqtt integration subscribes to the topic (like after a restart or mqtt reload) the broker sends the retained message and Home Assistant updates the state.

FWIW, I believe the devices don’t have to send with a retained flag set, but anything that publishes to the topic can set the retained flag.

Given that, you could use MQTT Explorer to set the retained flag on a topic, and assuming the broker is configured to have persistence you will always have the retained flag set unless something clears it.