I would like to program virutal switch, which runs lambdas instead of turning hardware gpios. I designed following yaml script, but it does not work - toggling the switch in HA (or in its own web page) does not change the state. What is wrong please?
@Didgeridrew is correct, you need to use either turn_on_action/turn_off_action or set optimistic: true to have the switch reflect the current state. The new release tomorrow will enforce this.
I had set it up that way but it didn’t work properly.
Now with your help I understand
the GPIO switch from the moment it is activated immediately sends the change of state and then executes the actions
[15:40:04][D][switch:045]: 'Blocco Chiusura Vasistas': Sending state ON
[15:40:04][D][cover:072]: 'Finestre vasistas' - Setting
[15:40:04][D][cover:076]: Command: STOP
while the switch template performs the actions and then changes the state.
[15:36:42][D][switch:025]: 'Virtual Switch' Turning OFF.
[15:36:42][D][main:715]: ----ACTION---SCRIPT---ACTION--------------------------- OFF
[15:36:42][D][switch:045]: 'Virtual Switch': Sending state OFF
This is ruinous for me because when I go to OFF he activates a script inside which he checks the status of the switch.
So with the GPIO it works, while with the template it doesn’t and I have to create yet another dedicated verification variable