WTH: Why last_changed still doesn't survive restart

Changes in the UI lately have been making more and more progress when it comes to visibility into who changed what and when.

Yet we’re still stuck with the issue of last_changed not preserving its value across restarts. Every HA update or restart changes the timestamp displayed in the UI, making it unreliable.

As in previous years - even if this is ‘hard to fix’, why not simply introduce another attribute that would ensure that temporary unavailability (especially when HA itself goes down) doesn’t affect the recorded state change timestamp?

If I haven’t turned something on or off for an entire year, why can’t I see that reflected accurately without having to resort to hacks and template sensors?

This has been one of the top-voted feature requests in every WTH year.

Maybe this could finally be the last one…? :slight_smile:

Agreed, this needs to be upvoted more. I believe it’s an outdated architecture issue, or maybe even a core team decision. It’s doable as I’m currently using a third-party integration that restores the ‘last_changed’ and last_updated after reboot, and it works perfectly fine.

Asked for and begged for, for several years. Even after all the FR forums were wiped/replaced we have over 120 bumps on github FR…

This, this, this…
HA should save last known state before restart/reboot and restore it after but not default to “unavailable”!

Yep, every time I reboot proxmox or install a HA update my wife starts getting worried about the garage door being ‘last changed 5 mins ago’ even though i’ve been at work all day (and did the update remotely)

As the rules of WTH says we can reply and link a pull request, I actually wrote a patch to Core that fixes this problem. The whole thing is less than 50 lines of code, so you can be 100% sure I’m doing anything that I shouldn’t do to your home. It handles restarts but also temporarily unavailable entities (unreliable Zigbee link for example): while the entity is unavailable it still works like now, but when the entity comes back it restore its old last change timestamp if the new state is the same one than the one it had before going offline. I’ve been using it since last February and never encountered any problem with it

You can find the code here: local patch: restore_last_changed.patch · home-assistant/core@6cd34f8 · GitHub

On my github account, you’ll also find several other modifications I made to both Core and Frontend (I update them every start of month with the latest patch release of the previous month)

For those who don’t know, the HACS integration last changed keeper fixes this pretty well. It should still be built into HA but this has been a solid work around for me for a few months now.

You can find details here:

Would also be nice to keep track of when a device was updated (or received an update if not yet installed)