If my entity has not changed state in days, it gets purged from the recorder and then has "no state history", and cannot be rendered in the graph. How to handle?

I was debugging an issue where some of my sensors were disappearing from my lovelace dashboard’s history graphs. These would be very infrequently changing sensors, particularly from ESPHome, where the state has not changed often, like if a certain sensor is connected, or if the sprinkler system is on (in the wintertime) etc.

When I tried to find out why these sensors had no state, I looked in the SQL database and realized that they had no entries in the database.

I believe if there has been no change in state in the recorder purge window, then all the information about that sensors gets purged, and then the lovelace history graph refuses to render these entities anymore, so they just become omitted.

Is there any good way to handle these, like maybe force a record to be recorded in the database at least once a week or nightly?

I guess just rebooting HA weekly is one way, since that will force it to reconnect to the sensors and query a new state, but that feels like overkill. Any other ideas?

Maybe try the Statistics Graph Card.
ESPhome sensors should work with it.

Create an automation and run

service: homeassistant.update_entity

every night on those entities ?

1 Like