streamdeck-homeassistant
streamdeck-homeassistant copied to clipboard
Custom Icon Button Treats Lights under 100% as off
As the title says. I'm using two different icons but it always treats anything under 100% brightness as off for the icon.
And then just a question...I have the title set to give me brightness with {{((((brightness*100)//255)))}}%
but it returns NaN for off. I've never used Nunjucks and when I attempted to make a conditional statement I couldn't get it to work. How would I show "Off" rather than "NaN %"?
This worked alright for me:
{{ "Off" if not brightness else ((((brightness*100)//255)) + '%') }}
Also, I just tried to replicate the off / on icon thing, and it works exactly as intended for me. The icon only changes to the "off" icon when I actually turn the light off using the toggle switch in HA (picture 1). As shown in picture 2, I've got the light in my room set to 10% and the SD plugin shows the state as on:
What sort of lights are you trying to control? I've got Hue lights controlled through ZHA, but I don't know if there are any lights out there that don't expose an on / off toggle in HA like I've shown.
That structure worked to get rid of the NaN text, but the icon still isn't functioning as expected.
I believe I've figured out the bug. If the button is set to toggle, the code doesn't check the value after the button is pressed. It knows the start state and assumes the final state. I have a light fixture I regularly want set at 30%, so I set the button to toggle, and a long press to set it to 30%. If I adjust brightness with another button or through HA, the original button does properly update when a new event indicates the value has changed, and it will properly display the ON icon.
Suggestion resolution: set icon based on post-button-press state read back, in the same manner the text is updated.