UI Switch element bug (or not)

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}]

It should work for any type, but the key fact is that what you send in the front must exactly match the output values, in value and in type. I can't look at your flow at the moment, but I suspect that if you look at what you are sending in then it does not match what comes out. It is up to you to convert the value you feed in if necessary.

Try this

[{"id":"1e8eb6b3.d6a6d9","type":"ui_switch","z":"bdd7be38.d3b55","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":340,"y":4280,"wires":[["b2422446.c83888"]]},{"id":"59f20718.f04c08","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"turn off","payloadType":"str","x":90,"y":4320,"wires":[["1e8eb6b3.d6a6d9"]]},{"id":"8639d783.045128","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"turn on","payloadType":"str","x":90,"y":4260,"wires":[["1e8eb6b3.d6a6d9"]]},{"id":"9aae44e.00b38b8","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":4120,"wires":[["b94c70a7.a1aad"]]},{"id":"e34b9a05.0583c8","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":90,"y":4180,"wires":[["b94c70a7.a1aad"]]},{"id":"b94c70a7.a1aad","type":"ui_switch","z":"bdd7be38.d3b55","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":330,"y":4140,"wires":[["9c0f8579.d52fb8"]]},{"id":"bd8295ec.ef06f8","type":"ui_switch","z":"bdd7be38.d3b55","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":330,"y":4000,"wires":[["d70d4fe.d8b9cb"]]},{"id":"f00668d1.9adc78","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":3960,"wires":[["bd8295ec.ef06f8"]]},{"id":"c9068a4e.5663c8","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"7","payloadType":"num","x":90,"y":4040,"wires":[["bd8295ec.ef06f8"]]},{"id":"d70d4fe.d8b9cb","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":4000,"wires":[]},{"id":"9c0f8579.d52fb8","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":4140,"wires":[]},{"id":"b2422446.c83888","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":4280,"wires":[]},{"id":"f811ea42.cde428","type":"ui_group","name":"switch test","tab":"efc74ccf.e0809","order":1,"disp":true,"width":"6","collapse":false},{"id":"efc74ccf.e0809","type":"ui_tab","name":"sw test","icon":"dashboard","disabled":false,"hidden":false}]

I thought that the State would have to be Boolean but I did try it with a String set as true/false and it does work as you suggest. (for strings)

I then tried to set the data type as Numeric. I set up two inject nodes for numeric, 0 and 1. And it also works.

It makes sense now that the input type would have to be the same as the output type. But I don't see how this would work if the output type was a timestamp. I saw all the output options and assumed that the input would need to be of Boolean type.

One thing that made me think that the data types wasn't the issue was that I can set the payload message for different types for the on and off output.

Did try your modification as well and it does work for the string type.

I don't think you could use the switch in that way with a timestamp output. If you need a timestamp output, but also need to control the switch with an input value, then set the switch to use a basic type and add the timestamp on the way out.

I totally missed this when I first read it. I had already worked out that the data types on the input and output needed to be the same. I had done my tests with strings but I had used true and false in my test. But in my application I had been sending out the strings light on and light off. But on the input I had been sending in true and false as a string. And it wasn't working.

I then did a simple test again with a single switch and inject nodes. I finally discovered that the output and the input need to match. Then I came back here and read Colin's first message again, which says exactly that.

The funny part is that my switch payload is light on. And my reply from the light is light on. But I was converting it to true (false for light off) because the instructions for the Indicator says, Switch icon shows state of input. And I took state to mean true or false. All I needed to do is feed what I was already receiving into the input of the switch.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.