Unify optimistic states for entities at core level to prevent UI "flipflops" and Voice Assistant errors #740
Replies: 6 comments 12 replies
This comment has been hidden.
This comment has been hidden.
-
This issue keeps popping up, this time I'm experiencing the same issue for Matter devices, especially Thread based devices can be slow to report their state. Click the switch in the HA interface to turn on a light, the light turns on almost immediately but the report that the light turned on takes a few seconds to arrive and you see the UI flipflopping causing confusion. This issue also exists with Zigbee, Z-Wave and many other integrations where some of them already "hacked" around it by setting the state just optimistic (without any fallback or check). |
Beta Was this translation helpful? Give feedback.
-
My idea to tackle/fix it in a very generic way, at the base entity model.
--> making use of the optimistic state has to be implemented per platform (within the service call) |
Beta Was this translation helpful? Give feedback.
-
The state machine in Home Assistant is to store what HA currently thinks the state is. This might be a recent report, or if By storing optimistic state updates in the state machine, we are now giving the states in the state machine 2 meanings: the state it currently is and the state it should become soon. I think that this is a mistake, as it means that a) we cannot see the actual state and b) every time you consume a state, you now need to check what is going on. We had a similar problem in the past for context. How do we attribute upcoming state changes to a context. We did that by adding What if we move the frontend logic of providing a fake state to the backend by building upon The impact would be that if you would call This solves a couple of use cases:
|
Beta Was this translation helpful? Give feedback.
-
If we go with the approach that HA does not manipulate the states, the frontend should show the target value immediately. I don't support doing tricks such as showing a moving slider if you don't have any real-time update report from the device. |
Beta Was this translation helpful? Give feedback.
-
I just wanted to chime in this post to state that me being a user who is not development or code savvy has been confused by the behavior of some products. @marcelveldt was kind enough to direct me to this post. I will attach some videos of my user experience issues. I hope this somehow gets resolved in the future. 20231212-1902-23.5203812.mp420231214-2043-15.1022987.mp4The Bedroom LED is a Hue Zigbee Lightstrip connected via Zigbee2MQTT |
Beta Was this translation helpful? Give feedback.
-
So, this is a discussion dragging around for years now and still a lot of (non technical) users get hit by this and while trying to fix this at integration level a simple solution popped in my head to fix this one once and for all at core level.
Currently we have 3 ways of dealing with how the actual state of devices/entities is handled within HA:
Fully optimistic: The integration doesn't poll/retrieve a device to get the actual state but just assumes it based on commands sent from HA.
Partially optimistic: The integration retrieves the actual state of a device by polling it periodically and/or from some sort of push message from the device itself. When sending a command to a device, the integration updates the state with the values sent in the command. These values can be overwritten later when the actual state comes in by poll/push.
Source based, not optimistic: The integration completely relies on state updates from the device itself to update the HA state. Technically the best option as the state is always 100% accurate.
So, what's the big deal ?
Well, in option 2 you can have a situation where the device did not receive your command, just partially accepted it or another user/system controls that same device (e.g. a light controlled by a light switch). So the UI (or voice assistant) confirms the action succeeded but some seconds after, the state changes again .
In option 2 you give a command to a light and kind of expect it to respond very fast with a new state update. In fact the command can suffer from the same issues as mentioned above for option 2 but we've see a lot of cases (especially Z-Wave) where a light is just slow to respond with the updated state.
On the various support channels for HA this is identified as 2 commonly reported issues:
The Home Assistant UI "flipflops" when I give a command. For example a light switch is toggled ON, after 2 seconds it switches back OFF and another 1 or 2 seconds later it switches back ON.
I give my Voice Assistant a command to turn ON/OFF a light but is responds that the command did not succeed while in fact it did.
The Home Assistant UI is kind of prepared for this and already has a 2 second redemption period to prevent flipflopping:
home-assistant/frontend#10735
In real life this is not enough because a state update can be received later than 2 seconds and another thing wrong about the current approach is that the user has no visual indication that we're waiting for the device to process the command.
Users, especially the non-technical ones do not understand this, imo this is really bad UX.
People do tend to forget that while people installing Home Assistant are most likely the tech savvy but their family members also have to deal with it ;-)
I have a proposal to fix this at core level (state machine or generic entity model) and at the same time have a good look at how integrations handle this and try to unify this a bit more.
Proposed solution
1a) Service call received (and executed) by the integration's platform.
4a) State update received from device --> remove optimistic mark and update state
4b) Timeout expired (no state received from device) --> remove optimistic mark and restore state
I think there should be some overridable flag to set the amount of seconds an entity is in the optimistic state.
Alternative to this solution is that integrations implement the optimistic state themselves but can set a boolean state attribute while the state is optimistic so the Ui can act on it.
Beta Was this translation helpful? Give feedback.
All reactions