Hi All,
I'm in trouble with this project.
I just wanto to have a Switch, plus a Button.
I want that pressing the button, the button do the action ONLY if the the switch is switched on! (Is a kind of safety)
I try in different way but I'm not able to do this.
Could someone help me giving the easyste and simplest solution?
Hi Lumanga,
it seems to me, that you have to use context variable. Please import the attached flow and inspect nodes.
[{"id":"174aad89f01f41e5","type":"ui_text","z":"ef1fc105685aed46","group":"e924fd1fd06cf83a","order":2,"width":0,"height":0,"name":"","label":"Button msg:","format":"{{msg.payload}}","layout":"row-spread","className":"","x":710,"y":360,"wires":[]},{"id":"e924fd1fd06cf83a","type":"ui_group","name":"Default","tab":"854bd9cd49df7ac1","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"854bd9cd49df7ac1","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
I hope it helps.
Stepan
An alternative is to use a node-red-contrib-simple-gate node (which you have to install via Manage Palette).
It can be set up so that an ON message from the switch opens the gate, allowing messages from the button to pass and OFF closes it, blocking the button messages.
Or use a join node and a switch node.
e.g.
[{"id":"725512a1.b50eec","type":"ui_switch","z":"bf9e1e33.030598","name":"","label":"switch","tooltip":"","group":"2d4fe667.28f8ba","order":8,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"switch","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":190,"y":2080,"wires":[["6dc8aa87.cc473c"]]},{"id":"6dc8aa87.cc473c","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":320,"y":2120,"wires":[["9056566f.da35d8"]]},{"id":"8ce1886b.667c78","type":"ui_button","z":"bf9e1e33.030598","name":"","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"the payload","payloadType":"str","topic":"button","topicType":"str","x":190,"y":2180,"wires":[["6dc8aa87.cc473c"]]},{"id":"9056566f.da35d8","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload.switch","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":2120,"wires":[["c4eb9de8.b47e3"]]},{"id":"c4eb9de8.b47e3","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload.button","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":2120,"wires":[["93e51fcb.ead128"]]},{"id":"93e51fcb.ead128","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":1920,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
or use the switch to enable / diable the button
e.g.
[{"id":"8ce1886b.667c78","type":"ui_button","z":"bf9e1e33.030598","name":"","group":"2d4fe667.28f8ba","order":9,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"the payload","payloadType":"str","topic":"button","topicType":"str","x":160,"y":1980,"wires":[["93e51fcb.ead128"]]},{"id":"c4eb9de8.b47e3","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"enabled","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2020,"wires":[["8ce1886b.667c78"]]},{"id":"93e51fcb.ead128","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":1920,"wires":[]},{"id":"725512a1.b50eec","type":"ui_switch","z":"bf9e1e33.030598","name":"","label":"switch","tooltip":"","group":"2d4fe667.28f8ba","order":8,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"switch","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":160,"y":2020,"wires":[["c4eb9de8.b47e3"]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":1,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
use the switch to enable / disable the button
Genius
AMAZING solution! Incredible... thanks a lot!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.