So basically a red and yellow LED to imitate a fireplace. I don’t want the LEDs to be exposed to HA, so I set them to internal. No I want a switch to flick the LEDs on and off. But the switch works not as expected: Whenever I switch it to ON in the frontend, the LEDs react as I want them to. But then the switch turns itself off after about a second. When I’m quick enough, I can switch it off myself and the LEDs will follow as expected.
Is there something about the internal state of switch I am missing perhaps?
The template switch has no way of knowing its state. You need to supply either:
lambda (Optional, lambda): Lambda to be evaluated repeatedly to get the current state of the switch.
Or one of these:
optimistic (Optional, boolean): Whether to operate in optimistic mode - when in this mode, any command sent to the template switch will immediately update the reported state. Defaults to false.
assumed_state (Optional, boolean): Whether the true state of the switch is not known. This will make the Home Assistant frontend show buttons for both ON and OFF actions, instead of hiding one of them when the switch is ON/OFF. Defaults to false.
Supplying a lambda state (Both LEDs on = switch is on) would be best.
Assumed state is a good option if you don’t mind having two lighting bolt icons, one for off and one for on instead of a toggle switch in Home Assistant.
Optimistic would be a second best option, as the LEDs can only be controlled by the template switch (and no other outside source like the individual LED controls) you only have to worry about the state being incorrect after loss of power.
I tried different methods to get the state from the lights, but I can’t seem to get it working… The switch always turns itself on again; even if the lights are off.