I am working on integrating HA into my monitoring system to detect entities who are not available and alert me.
In addition to tracking the unavailable
state (which, if I understand correctly, is actively sought by HA for devices that set a state - such as wifi switches) I wanted to inquire about the last time HA saw a given device.
This is particularly important for sensors that just send values about themselves (no state).
I grabbed the states, for example
{
"entity_id": "binary_sensor.waterleak_sdb_water_leak",
"state": "off",
"attributes": {
"battery": 100,
"battery_low": false,
"last_seen": "2021-07-04T16:21:24.539Z",
"linkquality": null,
"tamper": false,
"voltage": 3145,
"water_leak": false,
"friendly_name": "waterleak_sdb_water_leak",
"device_class": "moisture"
},
"last_changed": "2021-08-13T20:50:27.709510+00:00",
"last_updated": "2021-08-13T20:50:27.891332+00:00",
"context": {
"id": "c263882279523891c025d4e536c03fec",
"parent_id": null,
"user_id": null
}
},
I was suspicious about the dates provided by last_chnaged
or last_updated
because Zigbee2MQTT (the bridge between the sensor and MQTT) reports the device missing for a month (vs ~48h above).
I then had a look at another entity that is missing for ages, and it reports the same time!
My question: is the date persistent? If not - can I make it persistent?
I use HA in a docker container with a persistent volume holding the whole “root” directory and everything below (this is the directory configuration.yaml
is, including storage
) - so the files do persist.