General optimistic support

Some integrations have an “optimistic” parameter that lets HA assume a device’s state is set before receiving confirmation. This is helpful for devices that take a moment to report state, or for when doing rapid changes to a device (toggling a switch twice, or dimming repeatedly).

Right now, this is implemented at the integration level. I see that MQTT and template integrations typically implement this, but many do not.

Specifically, I have a light that I want to toggle twice in short succession, so that a toggle command is sent each time I press/release a hardware button. When I use the Lutron integration, this works every time. But with the TPLink, the switch often gets out of sync with the button presses. If I press the button a few times, the switch stays toggled in the wrong state.

I also noticed that with my hue devices, if I am sending multiple commands to do multiple brightness steps of -20, sometimes things will get out of sync and the brightness will go up and down instead of smoothly change.

Rather than add logic to each integration that needs it, I propose adding an optimistic feature to core integrations: light, switch, etc. This way any integration could benefit.

If you are having a problem with TPLink and Hue, are you asking that those integrations be changed? If it works in Lutron, HA must support it. It’s dificult to know what you are asking someone to help you with exactly.

Perhaps read the Pinned post again and try to clarify your request.

Feature Request Guidelines 📔.

It’s not exactly an issue of “support”. Some commands (for example toggle and brightness step) require a read-modify-write cycle to work. If the device takes some time to report its state change back (even 100 ms can be too slow), then (for example) 2 successive switch.toggle commands will not work as expected, because both would read the state as off and both try to set to on, since the state confirmation may not get the chance to arrive in time.

This is what “optimistic” support solves, but it’s only available in particular integrations, for example in MQTT (MQTT Switch - Home Assistant).

My request is: since this is useful across many integrations, it should be part of the core instead of implemented separately for each integration. The functionality is identical and should be implemented once.

I would be interesting in contributing this, but I don’t want to start any work if there isn’t agreement.