Sensor data TTL

Hi!

I think that would be interesting that sensors have a maximum time to live for their data. This way if the sensor device stops working and stops sending data to HA we can detect it and don’t use the outdated value. For example, if the last temperature read by a sensor is more than 24 hours old we don’t want to use it to switch on the heater. The real world isn’t perfect and sensors could be dead.

It should be a generic feature because everybody, independently what sensor type they are using, would benefit from this feature thus it may be implemented in the core of HA. I hope someone from the core team finds this feature interesting. I need your help because I don’t see touching the core an easy task for me because the implications that it could have in all the sensor components.

On the other hand there may be another way to implement it (as a workaround) via automations. In case the sensor value is not updated recently the automation could change the value to discard it. ¿Any ideas on how can it be programed with a template trigger? I’ve seen that there are two fields (last_changed and last_updated) in the database but I don’t how to access them.

Any idea? Thanks a lot!

We have available() which indicates if the device is there or not but it depends on the contributor to implement it. last_changed could be used for templates to determine if the data is old.

1 Like