What the heck is with the 'latest state change' not being kept after restart?

I know what you mean - I only need it on a few entities for automations to work properly, but I would much prefer it to work with every entity for informational purposes (especially lights, motion detection, etc).

Here for example I make extensive use of last-changed state for my lights - I restarted HA an hour ago but they certainly didn’t turn on/off at that time which is annoying. Whilst I don’t need it here for HA to function, I would very much prefer them to have correct values.

image

This has been my number one annoyance with HA since I started using it a couple of years ago. I restart now and again for HACS updates and it’s extremely annoying to see all my last-changed statuses reset on the dashboard. Especially for some of the security sensors which throw me off now and again.

I know I could create workarounds but it just adds a lot more complexity and convoluted code. It would be great to either set the current last-changed to not reset on startup in the settings (not sure if technically possible) or to have a new last-changed attribute that persists through restarts.

Every new release I hope something is done to combat this, hopefully one day it will as I’d imagine this is quite a common use case for a lot of consumers! I don’t believe in the “This isn’t too much of an issue if you don’t restart” argument as to the average consumer/user you’d look at an attribute called “last-changed” and would expect it to be the last time that sensor changed, not that it changed due to a restart. Finding a solution to that seems better than just hoping people don’t need to restart often imo.

1 Like

Maybe introduction of new “Discussioncs” regarding Feature requests will trigger some recognition regarding this topic? As it is 2nd top-voted WhatTheHack idea… :slight_smile:

@frenck - how do you think? Will it fit? :slight_smile:

1 Like

I think it will be part of the next release update!

At least I hope

What gives you that impression? Did I miss something?

  1. This is top x of the most requested WTH
  2. This just can’t wait any longer :slight_smile:

But it does not just magically appear :laughing: . So far there is no agreed solution (that I am aware of), so no related changes as a result in the upcoming release.

Collection of info is here: https://github.com/home-assistant/architecture/issues/230

from discussion on github one could have feeling that core devs have no interest in that improvement until some other person puts ready to use solution onto the table.

1 Like

Stumbled across this WTH, as I was looking for a solution to also save some timestamps from varoius sensors during restart/reboot.
Voted for this, too…

I heard it will only be solved over 1000 votes :stuck_out_tongue_winking_eye:

For some reason due to some architecture / design that has been around for a while makes the last changed / last updated properties of an entity to be handled differently from all other properties. And it seems like some made som spaghetti coding to make it really impossible to change as those are foundation that actually makes home assistant not fall into pieces :wink:

All software projects have similar “things” in them. Something that stinks, was introduced when someone had a bad day at the office, but is connected to everything in an undocumented spaghetti way. And no one dares to touch it and/or fix it as who knows what might happen or break elsewhere.

That is why i proposed adding another spaghetti layer on top. An attribute with the name of persisted_last_changed or similar, for the last_changed property. And only update it when a value change, not on restart, and treat it like any other attribute that gets recalled to the last known state after reboot.

1000 upvotes will not change anything, it stinks and no one still wants to touch it :wink:

Can we vote on it somewhere? :wink:

Yes, on this page at the top.

Oh, I thought there’s an PR somewhere with the spaghetti you’ve mentioned.

Nope, there is no PR and that is why nothing happens :slight_smile:

Another five cents to the feature request.
State is needed to complete automations in progress, for example:

action:
      - service: homeassistant.turn_on
        target:
          entity_id: switch.waste_air1_switch
      - delay:
          minutes: 15
      - service: homeassistant.turn_off
        target:
          entity_id: switch.waste_air1_switch

may stuck forever.

The lack of persistence for states is a big problem for what I want to do with HA.
I have a server that I can work out if it’s on, but it’s independent direct attached storage unit is a switch (for on/off), it must be shutdown AFTER the main server. I have a script that will check states and all that.
But updating HA 10 times a day, crashes, etc, I will loose my states which can potentially lead to my server turning off incorrectly causing data corruption.

Not to mention it’s annoying to have to tell it my lights are on…
(I have an automation that will not turn on lights if it’s already set to on, which you know, makes sense…)

For those that are still interested in this feature, please have a look at the feature request: Retain last state change data of a sensor after reboot

Until implemented this custom component GitHub - PiotrMachowski/Home-Assistant-custom-components-Saver: This custom component allows you to save current state of any entity and use its data later to restore it. did the job for me.

I upvoted it. Can’t believe this is still an issue after 2 years of feature request(s) and a lot of upvotes.

6 Likes