Sometimes I forget to timely replace a battery in one of my battery-powered devices, - typical a PIR or door-window sensor. I noticed that the indicators for battery level are not much reliable.
As result I’m too late replacing batteries. The devices run out of power and communication to HA stops.
To improve this, I want to monitor state changes. If a state hasn’t changed for more than a week, I want HA to send a notification to check its battery.
I think I can determine this in YAML with this code to find the time since last state change.
In the image you see the status of sensor “irresponsive…” is true (last change more than 7days old), changes to false after a reboot. This while the state of the door sensor remains open, because the battery is depleted.
How can I prevent that “last_changed” gets updated after HA gets power cycled?