The switch element is comprised of a "button" (click/touch area) and the graphic for the switch state. The default operation is for the graphic state of the switch to toggle when someone presses the button. The On Payload and the Off Payload are alternately sent to coincide with the toggling of the switch graphic.
There is an option to set the currently displayed switch position graphic to follow the input of the switch element. If the input to the switch element is True the switch will appear as ON. If the input is False then the switch will appear as Off. When someone activates (click/press) the switch element on the UI the payload for the opposite state will be sent out of the switch element.
The above operation is used when feedback of the state change, as a result of a activation, is required. In my case I have the output of the switch sent to my lamp. The lamp sends back a message that it turned on the light. That message is presented to the input of the switch element and then the graphic on the UI changes to reflect the true state of the lamp.
But it was not working for me. Eventually I found that the desired operation only works properly with a specific condition. Not the condition that was my use case.
The switch operation only works properly when the output is set for Boolean output. I had the output set to send strings for the payload. I have also tried it with a numeric output and it also fails. This caused the operation to fail.
I am currently on version 1.1.3 so I don't know if this has been discovered and fixed yet. I have not found
I am including a sample flow that contains three switches. One is set for string output. One for Boolean output. And one with a numeric output and a Boolean output. Each has inject nodes to set the state of the input.
[{"id":"1e8eb6b3.d6a6d9","type":"ui_switch","z":"fa91f5a0.848e58","name":"String output for both","label":"String output for both","tooltip":"","group":"f811ea42.cde428","order":3,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"turn on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"turn off","offvalueType":"str","officon":"","offcolor":"","x":640,"y":380,"wires":[["b2422446.c83888"]]},{"id":"59f20718.f04c08","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":390,"y":420,"wires":[["1e8eb6b3.d6a6d9"]]},{"id":"8639d783.045128","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":390,"y":360,"wires":[["1e8eb6b3.d6a6d9"]]},{"id":"9aae44e.00b38b8","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":390,"y":220,"wires":[["b94c70a7.a1aad"]]},{"id":"e34b9a05.0583c8","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":390,"y":280,"wires":[["b94c70a7.a1aad"]]},{"id":"b94c70a7.a1aad","type":"ui_switch","z":"fa91f5a0.848e58","name":"Bool output for both","label":"Bool output for both","tooltip":"","group":"f811ea42.cde428","order":2,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":630,"y":240,"wires":[["9c0f8579.d52fb8"]]},{"id":"bd8295ec.ef06f8","type":"ui_switch","z":"fa91f5a0.848e58","name":"Numeric output for Off Payload","label":"Numeric output for Off Payload","tooltip":"","group":"f811ea42.cde428","order":1,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"7","offvalueType":"num","officon":"","offcolor":"","x":630,"y":100,"wires":[["d70d4fe.d8b9cb"]]},{"id":"f00668d1.9adc78","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":390,"y":60,"wires":[["bd8295ec.ef06f8"]]},{"id":"c9068a4e.5663c8","type":"inject","z":"fa91f5a0.848e58","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":390,"y":140,"wires":[["bd8295ec.ef06f8"]]},{"id":"d70d4fe.d8b9cb","type":"debug","z":"fa91f5a0.848e58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":100,"wires":[]},{"id":"9c0f8579.d52fb8","type":"debug","z":"fa91f5a0.848e58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":240,"wires":[]},{"id":"b2422446.c83888","type":"debug","z":"fa91f5a0.848e58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":380,"wires":[]},{"id":"f811ea42.cde428","type":"ui_group","z":"","name":"switch test","tab":"efc74ccf.e0809","order":1,"disp":true,"width":"6","collapse":false},{"id":"efc74ccf.e0809","type":"ui_tab","z":"","name":"sw test","icon":"dashboard","disabled":false,"hidden":false}]