My daughter has one of those mirrors with lights around the edge, and a touch button in the mirror. I wanted to make it controllable (as a learning thing) so I connected an esp8266 to a servo (which touches the back of the button) and a light sensor (inside the mirror) to register if the lights are on or off.
All works well, except when I do a turn off or turn on (from HA), it always toggles it, regardless of whether the switch is shown as on or off.
Or they could just simply turn on Optimistic mode…
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.
The problem is with the servo. There are 3 seperate movements for each turn_on and turn_off and each one does the exact same servo movements. Theres no difference between On and Off
Optimistic just keeps the switch states updated between HA and esphome.
Why is the servo making 3 movements with 3 delays for each turn_on and turn_off?
What do the logs say? Whats triggering the toggle?
Where is the automation for the light sensor? Is that causing a problem? We cant tell because you didnt post it.
What type of switch/button is on the mirror? Is it a momentary switch or latching?
Why are you even using a servo? Why not connect to the button and then you can trigger it from esp and also read its state if someone physically pushes it. Servo seems kind of over the top and unnecessary.
Basically I to to make the turn off and on actions dependent on whether the light is already on or off. It makes sense looking at it now but didn’t back then.