Understanding dashboard switch

#1

Good day

So I want to integrate a switch onto my dashboard which will allow a series of pulse through. But that is not happening, am I misunderstanding how the switch node should work in that configuration?

Many Thanks

#2

Yes, you are misunderstanding. All the Pass Through checkbox does, when selected, is that if an input 0 or 1 is received then it will not only set the switch off or on but will also pass on that message. With it unchecked then an input message will set the switch but will not pass anything on. Unchecked is the usual setting because otherwise it is easy to get into a loop where pressing the switch sends a message, which for example goes off to MQTT, but if the input of the switch is connected to an MQTT In node subscribed to the same topic then the message will come back from MQTT into the front of the switch. If Pass Through is selected then the message will get passed on, into MQTT, and back into the front of the switch, through the switch and into MQTT again .....

1 Like
#3

Ooooooh okay I see, any recommendations on how I can achieve such functionality then?

A switch on the UI, which when I turn on, allows payload values through and when I turn off, does not allow payload values through?

Many Thanks

#4

Let the switch be the controller of the gate

[{"id":"6f6a991e.4a28d8","type":"function","z":"81c5c63b.6b8288","name":"gate","func":"// read (or initialize) gate state\nvar gateIsOpen = context.get(\"gateIsOpen\") || false;\n\n//message is from switch\nif(msg.topic === \"gate\"){\n gateIsOpen = msg.payload;\n // store the gate state \n context.set(\"gateIsOpen\",gateIsOpen);\n}\n\n// message is from other sources\nelse{\n if(gateIsOpen === true){\n node.status({fill:\"green\",shape:\"ring\",text:\"gate is open\"});\n // send through the original message\n return msg;\n }\n else{\n //just display the status of gate\n node.status({fill:\"red\",shape:\"ring\",text:\"gate is closed\"});\n }\n}\n\n","outputs":1,"noerr":0,"x":650,"y":580,"wires":[["d28937dd.8d5a98"]]},{"id":"58196f37.a5047","type":"ui_switch","z":"81c5c63b.6b8288","name":"","label":"switch","group":"df7325b1.2ce318","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":430,"y":500,"wires":[["6f6a991e.4a28d8"]]},{"id":"e67fead5.6a33c8","type":"inject","z":"81c5c63b.6b8288","name":"","topic":"init","payload":"This is data","payloadType":"str","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":580,"wires":[["6f6a991e.4a28d8"]]},{"id":"d28937dd.8d5a98","type":"debug","z":"81c5c63b.6b8288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":580,"wires":[]},{"id":"2f34865f.5350aa","type":"comment","z":"81c5c63b.6b8288","name":"Switch controls gate","info":"Switch sends boolean value to gate.\nmsg has topic \"gate\". This way the gate can understand \nthat this message is meant for gate to change it's state ","x":390,"y":440,"wires":[]},{"id":"a1928b73.28be98","type":"comment","z":"81c5c63b.6b8288","name":"Gate ","info":"Gate can be even OPEN or CLOSED (boolean value)\nAccording to the current state the incoming data is sent through or not","x":650,"y":520,"wires":[]},{"id":"df7325b1.2ce318","type":"ui_group","z":"","name":"Default","tab":"245a6127.50b27e","disp":true,"width":"6","collapse":false},{"id":"245a6127.50b27e","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

1 Like
#5

Several examples on the flows.nodered.org site also...
including https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65

1 Like