Always keep track of when entity state is written #1062
Replies: 6 comments 4 replies
-
This proposal would solve 99% of users complains related to the |
Beta Was this translation helpful? Give feedback.
-
If we decide to fire the If we use the dispatcher or a callback subscription to get the data to the recorder this likely mitigates that concern. |
Beta Was this translation helpful? Give feedback.
-
A ton of templates use last_updated properly to catch attributes changing. We should not consider deprecating that property. |
Beta Was this translation helpful? Give feedback.
-
Will it also be made possible to add this as a |
Beta Was this translation helpful? Give feedback.
-
I noticed that |
Beta Was this translation helpful? Give feedback.
-
Closing this discussion as the proposal has been implemented. |
Beta Was this translation helpful? Give feedback.
-
Proposal
last_reported
, to state objects which indicates when the integration set the state, regardless of if the state or any state attributes have been changed.hass.states
on every state write, regardless of if the state or any state attributes have been changed.state_reported
which fired on every state write, regardless of if the state or any state attributes have been changed.state_changed
such that when fired, theold_state
will have an updatedlast_reported
timestamp.Background
Home Assistant currently discards state writes where neither the state nor the state attributes are changed, unless the integration sets the
force_update
flag. This behavior makes it very difficult for integrations to correctly do time series analysis of numerical sensor state. It also means the user don't know if an integration is updating a sensor or not.Performance concerns
The main identified performance concern is recording of state changes by the recorder. If the recorder would subscribe to the new event type
state_set
and record those events, the recorder would have to process much more events and also do much more database writes. Some quick sanity checks on a few systems @bdraco suggests a factor of 20-30, but this will vary wildly depending on user setup.To address this, the proposal is that the recorder will still only subscribe to
state_changed
events, and update the last recorded state'slast_reported
timestamp as needed.Future improvements
If this proposal is accepted, we should consider deprecating the
force_update
flag forhass.states.async_set
.We should also consider deprecating the
last_updated
timestamp onState
objects; it's used only be a few integrations, and to my understanding incorrectly, as if thelast_updated
timestamp is thelast_reported
timestamp proposed here. That's for example the case in thefilter
, thegeneric_hygrostat
andintegration
integrations.Beta Was this translation helpful? Give feedback.
All reactions