cgiesche / streamdeck-homeassistant

Control your Home Assistant devices from StreamDeck
MIT License
768 stars 38 forks source link

Custom icon entities ignore actual state when pressed #234

Closed Guspaz closed 5 months ago

Guspaz commented 5 months ago

If you create a button of type "Entity (custom icons)", then pressing the button toggles between on and off regardless of the actual state of the entity. For example, if the appearance entity is a switch, if you set the action to "turn on", you would expect repeated presses to leave the visual state always on, but instead the visual state toggles back and forth. Or if you set an action that does not affect the switch state (or does not affect it immediately), you would expect the visual state to remain unchanged, but instead it toggles on and off.

This does not happen with switches created from "Entity (generic)", those correctly reflect the entity state. This only affects custom icon entities. The visual state does correctly update on its own if the state changes in HASS, the problem only seems to be that the state changes on button presses instead of waiting for HASS to say the state has changed.

This bug occurs regardless of what type of entities are used, pressing the physical button always toggles the visual appearance between on and off even if the appearance entity has a binary state that differs from this.

Guspaz commented 5 months ago

Looking at the Stream Deck SDK, it looks like it's the Stream Deck that will automatically toggle between states when the key is released. A workaround to this may be for the plugin to call setState every time it receives a key release event, to update the state to the HASS state. Or potentially set "DisableAutomaticStates" to "true"?

Guspaz commented 5 months ago

Can confirm, setting "DisableAutomaticStates" to true on the action in the plugin's manifest.json file fixes this bug completely. This solution only works for two-state actions, but that's what this plugin uses, so it's perfect.

This attribute was only added to the manifest in versus 6.4 of the software, so it's quite new.

cgiesche commented 5 months ago

Hi @Guspaz,

that is a nice finding! From the beginning the automatic switch behaviour was a problem. I am quite sure i did not find anything like "DisableAutomaticStates" that when i initially added the feature. Maybe the option has been added to the API meanwhile

I will add this to the manifest.

Guspaz commented 5 months ago

You can find the documentation for it here: https://docs.elgato.com/sdk/plugins/manifest#actions It was added in 6.4: https://docs.elgato.com/sdk/plugins/changelog So it's probably very recent. It's also bizarre that it only works on actions with two states, and not three or more, but since this plugin only has either one or two states, that isn't a problem.

sammyke007 commented 5 months ago

I'm facing this too. I have an icon setup for my front door state (binary door/window sensor). On key press it opens the door lock (sensor.***). When I press the button, the door lock opens, but the door is still closed. The icon changes to the open state however. Is this the fix?

Any hint on where to find the manifest.json to edit this? Is it C:\Users\****\AppData\Roaming\Elgato\StreamDeck\Plugins\de.perdoctus.streamdeck.homeassistant.sdPlugin\manifest.json?

Edit: it was the above file. Adding the "DisableAutomaticStates": true, on line 29 and restarting Stream Deck fixed it, tnx!