MQTT las value persists on the HA's dasboard even when the publisher goes offline

Hi.
I’ve just installed an MQTT Mosquitto broker on the same Raspberry PI that hosts HA.
I’ve defined an external ESP32 configured as an MQTT publisher that sends a simple test dataset every ten seconds to the Mosquitto broker.
Finally I’ve added this code to the configuration.yaml :

# Example configuration.yaml entry
mqtt:
  sensor:
    - name: "ESP32-pin 25-Volts"  
      state_topic: "studio/test/pin25"
      unit_of_measurement: "Volts"
      payload_available: "online"
      payload_not_available: "offline"
      force_update: true

The issue is that even if I shutdwon the external ESP32 board on the HA’s dashboard I see the last value sended while I’d like to show that the board is offline.
2022-12-19_094002

Any idea?

Retain is probably set to true (true is the default) on your ESPHome board.

  • retain (Optional, boolean): If the published message should have a retain flag on or not. Defaults to true.

expire_after should solve your problem

1 Like

It works fine.
Thanks

1 Like