Every time I reload HA the timestamp in the last-changed attribute becommes incorrect and is set to the time HA was reloaded. The same is true for the last-updated attribute, but there I would say the change is correct.
Nevertheless my System knows that the last state change was ~11 hours ago and not the 1 hour it says in the attribute fields.
See:
It seems automations can carry last triggered over but the state entity seems to default to “last reboot”. At least that what looks like for my entities. I rebooted last night and every single entity that hasn’t changed today is listed as the reboot time…
This is a long standing issue and there are a lot of threads about it. I would also like to know this and always read threads that come up about it to see if there has been a new discovery to make it work and it’s always the same: this is not currently possible unless you add your own sensors or helpers with timestamps and roll your own method.
It’s the way the state machine works. When you restart home assistant every entity state value starts at unknown until the integration it depends upon is loaded and the state is restored. Therefore both last_changed and last_updated for the entity are also changed because the state changed. Same goes for reloading.
That does not explain why that switch’s is showing 1 hour though. That may be a frontend bug.
That 1 hour is correct (even so absolutely silly).
Its the time since HA rebooted, so last-changed and last-updated both refer to this time.
If this is yet again a topic boiling down to the core design of HA, it seems we need a third timestamp something along the lines of last-known-good or something.
But frankly… imho last-changed should contain that, while last-updated can happily contain the time of reboot.
So I for my part need to make up my mind if I am just willing to live with these bogus times reported or invest the effort to track each of these times in some variables / additional sensors…
Probably a history_stat Sensor would be the best to measure how long ago the State was either ‘on’ or ‘off’…