Let us see when last sensor data was received, even if unchanged

State Objects - Home Assistant (home-assistant.io)

Currently it is not possible to see if sensor is still sending data and when was the last packet/update received. Here’s an example:

This shows last_update was two hours ago, but I’m pretty sure the sensor should be sending updates every 10 seconds. But there’s no way to check until there’s a (unpredictable) timeout somewhere and it becomes unavailable, if ever.
And this is applicable to all sensors that I know of, let it be zigbee, BLE, cloud, etc.

I see two possible options this could be done.

  1. Add a last_seen state
  2. Change the behavior of last_updated state, as its name already suggests this functionality.

I have searched forums and found that in almost all hits people are having issues with last_updated due to misconception of what it actually does. Currently it only updates if at least something in the state changes, like one of attributes. But it will not update to current timestamp if the same value is received.

My proposal would be to update the timestamp in last_updated when any packet is received, even if unchanged.
If not possible due to whatever reason, then let’s implement last_seen.

This is serious, I already had my boiler almost explode due to dead and not yet timed-out sensor, and home assistant having no clue.

I have a similar serious issue with my sump pump outlet, which shows zero watts all summer, and continues to show zero even after the rainy season starts. I don’t know when I should be worried that the sensor isn’t working or the sump pump has failed.

2 Likes

Really, so few interested in this?

1 Like

Agree. Also good to check for missing devices. Unavailable is useless in that respect, since every reboot thigs go unavailable for a short time. Last seen too long ago is far more useful to detect dead devices.

1 Like

I agree that the last_updated property can be deceiving because it doesn’t update if the received value is the same as the existing value.

Until this is addressed (if ever) here’s how to monitor for a “stale sensor” where “stale” means its value hasn’t changed within a chosen time period. Naturally this is only useful for sensors whose value changes at least occasionally and doesn’t normally remain the same for a long time (if it does then this technique will report false positives).

Example for monitoring a single sensor:

Example for monitoring several sensors:

The whole point of this request is that unchanged does not mean a thing for a lot of devices. For instance, I have water sensors checking for leakage. They are only useful if they work, but they should never change to detected if all is well. Battery sensors are all but useless on these things, they stay 100% and then go offline all of a sudden.

Also, a location for my kids is not that useful if it is old. But how to tell the difference between I only know where he/she was an hour ago versus he/she hasn’t moved for an hour but was last seen at that location a minute or two ago.

3 Likes

Actually I would like to have recorded in database ALL readings, regardless of change from previous value. Not so stressing on database size, but on data consistency. IMHO better to have more data available - then it possibly to see if & when any data arrived from device.

Probably it can be just a configuration option - do HA owner wants to record same values or not. Do not see dramatical changes in other parts of HA, but during data recording.

1 Like

I agree, I would love an option to log all data points as well. I can afford larger disk.

2 Likes

I’m surprised this isn’t already the behavior, since last_changed and last_updated are separate in the State class, for example.

last_changed: last time the state was changed, not the attributes.
last_updated: last time this object was updated.

The devs don’t know what word ‘update’ means.

As I was looking for the solution (i thought I had it with last_updated) to raise a notification on my phone when any of sensors required for heating goes dead so I can somehow react (prevent some disaster) I stumbled on WTH discussion: WTH, how can I know when the last (unchanged) sensor value was received? - Month of “What the heck?!” - Home Assistant Community (home-assistant.io)

which turned out to be counterproductive. So I went online to find any workaround and found nothing of use (nothing I can set up fast when setting new sensors).
The only way would be ping <=> pong or somekind of heartbeat I can set up as scripts/automations/embed in sensor (ok for me to do it but not really user friendly) BUT that is relevant only to sensors/devices on ethernet (nothing for zigbee/esphome/ble/… devices). There was a suggestion: Use ESPHome, it has a expire_after configuration option.
But it works ONLY if you have mqtt component in configuration. Not sure why would I need mqtt if ESPhome has native API (which is faster, more reliable … )

I KNOW last_updated and last_changed CANNOT be reprogramed as ppl use them as they were designed from start. BUT we really need then the attrib something like: last_seen

Otherwise to all the devs of HA THANK YOU very much for all the good work you did/do/will :slight_smile: :grinning:

2 Likes

(Replying here because this is the first Google result for stale data.)

At least for BLE sensors there’s a way to force a “last update” to actually change every time data is received: Enable the “Signal Strength” sensor on that device and monitor the “last update” of that instead of the actual value. The signal strength will fluctuate wildly and almost never give the same reading twice in a row.

I have this as Helper->Template->Binary:

{{ now() - states.sensor.nest_signal_strength.last_changed >= timedelta (minutes=5) }}
1 Like

This FR is well over a year old and now an entity’s State Object contains a last_reported property.

2 Likes