This is a frequently discussed topic on the forum:
- Persistent last changed sensor
- Persist last_changed between HA restarts
- What the heck is with the 'latest state change' not being kept after restart?
- Is last_changed or last_update persistent across reboots?
- A state (timestamp) that is not affected by HA restarts?
- Last changed/Last updated
- Handling stale/broken sensors that drive thermostats
- Real state last_changed
A cursory look at the codebase indicates that the last_updated and last_changed variables are defined whenever the class is instantiated ie. on a restart?