Switch node - what is point of Show State of Output option?

With the ui_switch node, when Pass through messages is not selected, one of the options for Indicator is "Icon shows state of the output". In this mode, when the switch is clicked the visual state changes and the message is sent. Incoming messages are completely ignored, so it is pointless connecting an input. It seems to me that the identical operation is achieved if Pass Through is enabled but no inputs are connected. Am I missing something?
Perhaps there is a bug and the incoming message is supposed to set the visual indication but not send on a message.

2 Likes

Last night whilst looking at the node-red-contrib-ui-multistate-switch thread, I too tried the same thing, and had the same result, so pleased to see that you've raised this.

It is only ignoring the msg.payload.... you may also set some of the other fields by using msg properties - like label, icons (and more recently topic) etc... You may want to provide this as feedback from the click - but want to show the instant feedback of the click. OK it is possibly redundant if you craft messages carefully - but like much of Node-RED it has evolved over the years.

OK, that makes sense. Thanks.

I was looking at the 'Switch icon shows state of input', as it doesn't seem to work as I'd recalled.
Take this simple example;

[{"id":"48b78df7.023ba4","type":"debug","z":"a4801683.1c0448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":3040,"wires":[]},{"id":"e55ea81b.adfdd8","type":"ui_switch","z":"a4801683.1c0448","name":"","label":"switch","tooltip":"","group":"e68a1b8a.416f18","order":21,"width":"3","height":"1","passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":380,"y":3040,"wires":[["48b78df7.023ba4"]]},{"id":"4368bdf2.f7a874","type":"group","z":"a4801683.1c0448","name":"Output from Google Home","style":{"stroke":"#ffC000","fill":"#ffefbf","label":true,"label-position":"n","color":"#000000"},"nodes":["93dd8a1e.9f4538","47fb33e9.23e5ac"],"x":94,"y":2979,"w":193,"h":124},{"id":"93dd8a1e.9f4538","type":"inject","z":"a4801683.1c0448","g":"4368bdf2.f7a874","name":"Light ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":200,"y":3020,"wires":[["e55ea81b.adfdd8"]]},{"id":"47fb33e9.23e5ac","type":"inject","z":"a4801683.1c0448","g":"4368bdf2.f7a874","name":"Light OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":201,"y":3062,"wires":[["e55ea81b.adfdd8"]]},{"id":"e68a1b8a.416f18","type":"ui_group","name":"Default","tab":"6952137b.75c85c","order":1,"disp":false,"width":16,"collapse":false},{"id":"6952137b.75c85c","type":"ui_tab","name":"Home","icon":"dashboard","order":12}]

Where the switch controls a light, which is also voice controlled via Google Home.
So the light can be activated by either voice or dashboard.

The readme says;
"the icon can either track the state of... the input msg.payload, in order to provide a closed loop feedback."

So my expectations were that the switch can activate the light as normal, but if a change was made to the light's status via voice, then that could be fed back to the switch node to reflect the change made, without sending an output (which would cause an endless loop).
The switch icon would then always be in sync.

But the result is that the switch cannot be changed via the dashboard.

I can't test your flow at the moment but have you checked that the incoming data exactly matches the values specified in the switch? Numbers vs Strings for example is easy to not notice.

The problem isn't that the incoming data doesn't change the switch icon - it does.
But as I said above;

...which means that the dashboard switch loses functionality, and is therefore just a visual cue.

But this is what it would be IRL - with an actual lamp

[{"id":"48b78df7.023ba4","type":"debug","z":"f2f2e382.3228b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1060,"wires":[]},{"id":"e55ea81b.adfdd8","type":"ui_switch","z":"f2f2e382.3228b","name":"","label":"switch","tooltip":"","group":"e68a1b8a.416f18","order":21,"width":"3","height":"1","passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":400,"y":1060,"wires":[["48b78df7.023ba4","655a0d88.557ff4"]]},{"id":"655a0d88.557ff4","type":"ui_switch","z":"f2f2e382.3228b","name":"","label":"actual lamp","tooltip":"","group":"","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":430,"y":1160,"wires":[["e55ea81b.adfdd8"]]},{"id":"4368bdf2.f7a874","type":"group","z":"f2f2e382.3228b","name":"Output from Google Home","style":{"stroke":"#ffC000","fill":"#ffefbf","label":true,"label-position":"n","color":"#000000"},"nodes":["93dd8a1e.9f4538","47fb33e9.23e5ac"],"x":94,"y":1059,"w":193,"h":124},{"id":"93dd8a1e.9f4538","type":"inject","z":"f2f2e382.3228b","g":"4368bdf2.f7a874","name":"Light ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":200,"y":1100,"wires":[["e55ea81b.adfdd8","655a0d88.557ff4"]]},{"id":"47fb33e9.23e5ac","type":"inject","z":"f2f2e382.3228b","g":"4368bdf2.f7a874","name":"Light OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":201,"y":1142,"wires":[["e55ea81b.adfdd8","655a0d88.557ff4"]]},{"id":"e68a1b8a.416f18","type":"ui_group","name":"Default","tab":"6952137b.75c85c","order":1,"disp":false,"width":16,"collapse":false},{"id":"6952137b.75c85c","type":"ui_tab","name":"Home","icon":"dashboard","order":12}]

Now I've seen that, I can see how it works, but without your example, and relying on the readme I think I would struggle.

Open to suggestions to improve docs/words

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