How to read MQTT retained value at startup

Hi All,
I configured this in HA:

mqtt:
  fan:
  - name: "Recuperatore DRU50"
    command_topic: "rec46/onoff"
    state_topic: "rec46/onoff/state"
    availability_topic: "rec46/will"
    retain: true

And this automation:

alias: START HA aggiorna MQTT
triggers:
  - event: start
    trigger: homeassistant
conditions: []
actions:
  - data:
      payload: online
      topic: rec46/will
    action: mqtt.publish
mode: single

With MQTT EXPLORER I can see that the retained value are present…
But when HA starts, the fan is in unknow status.
after startup, can HA reads the retained value?

That means fan.recuperatore_dru50 has not received any payload published to its state_topic. Its state will remain unknown until it receives a valid payload.

Use MQTT Explorer to check the last payload published to rec46/onoff/state. If nothing ever gets published to this topic, the fan entity’s state will remain unknown.

in fact the device published without retain,
I added the retain and when HA starts have the retained value…

1 Like