API last_update date

Hi,

I am trying to use the HASS API and Python to create an app that alerts when a sensor goes offline, and I figure that I would use the last_update field. However, I am experiencing an issue. I have a zigbee sensor that dropped offline this AM and came back online at 7:16AM.

The output from the API is as follows:

{'entity_id': 'binary_sensor.lumi_lumi_sensor_wleak_aq1_ias_zone', 'state': 'off', 'attributes': {'friendly_name': 'Water Sensor Well', 'device_class': 'moisture'}, 'last_changed': '2021-02-22T12:16:34.604859+00:00', 'last_updated': '2021-02-22T12:16:34.604859+00:00', 'context': {'id': 'xxxxx', 'parent_id': None, 'user_id': None}}

Converting this to my time zone indicates a last_update and last_changed time of 7:16AM. However, if I check the Zigbee page in HASS, I see the following: “Last Seen: 2021-02-22T21:29:43” which is equivalent to 9:29PM. Why the difference? Shouldn’t “last_update” match what is shown in the GUI?

TIA!

“Last Update” / “Last Changed” isn’t always the same as “Last Seen”. Devices can wake up and report in periodically… if there aren’t changes to the states (dry/wet, battery level, etc.), the “Last Update” / “Last Changed” fields won’t trigger.

Hi, how can we get last_seen as a value that can be used in an automation?
thanks

Thank you. As asked by the other poster, is there any way to access last_seen through the API? It seems like a big gap, if not.

One additional question, I understand your point but am still confused about the inconsistency. I have four of these devices and all others show a recent last_update that is very recent while this one does not.

I guess it has something to do with it having dropped offline, but I am still confused why this one is treated differently than the other three. It is still being updated though as indicated in the GUI and the historic graph.

What exactly triggers an unchanged last_update? Would it have stayed frozen on 7:16AM forever? This just feels wrong. As a test, I am running a Python script to dump last_update to a file to try and understand when it changes.

Edits: Clarified text and fixed grammar.