How to prevent MQTT sensors from becoming “unavailable” during deep sleep?

Hi everyone,

I’ve noticed that Home Assistant automatically sets my MQTT sensors to “unavailable” whenever they temporarily disconnect from the broker — for example, when the device goes into deep sleep.

Here’s my setup:

  • retain is enabled,
  • QoS is 1,
  • there are no birth or last will messages configured,

Despite this, Home Assistant marks the MQTT sensor as unavailable as soon as it goes to sleep, even though the retained data on the broker remains valid.

According to the ESPHome documentation, this behavior is described as a feature. However, for setups like mine it’s quite problematic — the sensor shouldn’t be considered “unavailable” just because it’s in deep sleep.

My question is:
Is there any way to disable or override this behavior, so that Home Assistant keeps showing the last known value instead of switching to “unavailable”?

Thanks in advance for any advice or insights!

You might want to have a look at this thread: Link
Maybe this will help…

I had a similar issue with a solar powered ESP with attached temp sensor in the pool. The ESP goes to sleep to conserve power and occasionally HA would mark the temp sensor as unavailable. This was a problem because that temp value shows on a home dashboard.

I got around it by creating a clone sensor in HA that always shows the last good known value, and updates when the ESP wakes up to take a new reading. That clone sensor is what’s now on the dashboard and no one is the wiser.

If you’re keen on this as a solution, I’m happy to share that HA code when I get home later.

“If the birth message and last will message have empty topics or topics that are different from each other, availability reporting will be disabled.”