ESPHome MQTT sensor shows unavailable after few hours

Hello, my sensor sleeps for about 3.5 hours between measurements. When I reboot HA during the sleep the sensor shows unavailable. I thought it should be fixed by setting discovery_retain: true, but this is default setting so I do not need to have in esphome yaml config, right?

The problem is that it seems that HA cannot wait 3.5 hours for next sensor value and shows it as unavailable. What is the maximum time I need to refresh mqtt sensor so the HA shows its value all time?

You need to retain the sensor payloads as well.

May I please ask how to do it? I have seen tens of posts that I need to “retain”, but I was searching for example and could not find it neither here or on

Thank you very much, Jan

Actually the default is set to retain true for all mqtt messages.

I think you just need to supply blank LWT messages:

Thanks. Actually, I have put the RETAIN statement into sensor configuration in ESPHome and it seems to be working:

  - platform: vl53l0x
    name: "Flower Distance"
    retain: true
    address: 0x29
    update_interval: 200min
    accuracy_decimals: 0
    long_range: False
    unit_of_measurement: "mm"
      - multiply: 1000.0
1 Like