Hello to everyone,
i have zero node-red and javascript experience. I want to choose between the output of 2 nodes. The selection will depend on the output of a third node.
I have a "solenoid valve switch" node and a "scheduler" node and i want to choose only one of those outputs to feed the rest of my flow.
i didn't find any build-in node to do it and I tried with functions.
Any help would be appreciated,
Thank you
[{"id":"fdfdb59a.dbf3f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c4532bc.d3616d8","type":"file","z":"fdfdb59a.dbf3f8","name":"WriteFile","filename":"/data/time-schedule.txt","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":340,"y":120,"wires":[[]]},{"id":"2d230dba.0ac172","type":"inject","z":"fdfdb59a.dbf3f8","name":"FireAfterReboot","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":120,"wires":[["fa4881b6.63139"]]},{"id":"fa4881b6.63139","type":"file in","z":"fdfdb59a.dbf3f8","name":"ReadFile","filename":"/data/time-schedule.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":120,"y":200,"wires":[["aaba4afb.f8a0a8"]]},{"id":"aaba4afb.f8a0a8","type":"ui_time_scheduler","z":"fdfdb59a.dbf3f8","group":"671f39c6.6d0858","name":"","startDay":"0","refresh":60,"devices":["Valve 1","Valve 2","Valve 3"],"customPayload":false,"eventMode":false,"sendTopic":false,"outputs":4,"order":8,"width":0,"height":0,"x":290,"y":200,"wires":[["c4532bc.d3616d8"],["b50bbad8.776ff8"],[],[]]},{"id":"dda2ebb.43c1118","type":"ui_template","z":"fdfdb59a.dbf3f8","group":"","name":"Clock Toolbar","order":2,"width":"0","height":"0","format":"<script id=\"titleScript\" type=\"text/javascript\">\n\n$(function() {\n if($('.md-toolbar-tools').length != 0){\n loadClock();\n }else setTimeout(loadClock, 500)\n});\n\nfunction loadClock(){\n $('#clock').remove();\n var toolbar = $('.md-toolbar-tools');\n \n var div = $('<div/>');\n var p = $('<p/ id=\"clock\">');\n \n div.append(p);\n div[0].style.margin = '5px 5px 5px auto';\n toolbar.append(div);\n\n function displayTitle(lh) {\n p.text(lh); \n }\n \n function upTime() {\n var d = new Date();\n p.text(d.toLocaleString());\n }\n\n if(document.clockInterval){ \n clearInterval(document.clockInterval);\n document.clockInterval = null;\n }\n \n document.clockInterval = setInterval(upTime,1000);\n}\n\n</script>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"global","x":120,"y":40,"wires":[[]]},{"id":"8b90ee5a.56226","type":"ui_switch","z":"fdfdb59a.dbf3f8","name":"Solenoid Valve 1","label":"Solenoid Valve 1","tooltip":"","group":"671f39c6.6d0858","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"garden/node2/gpio2","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":470,"y":280,"wires":[["af43250.73801d8"]]},{"id":"1042ad1f.5e3d03","type":"mqtt out","z":"fdfdb59a.dbf3f8","name":"Valve 1","topic":"garden/node2/gpio2","qos":"","retain":"","broker":"681b9d99.717f94","x":680,"y":480,"wires":[]},{"id":"f0f3dde8.b78f2","type":"mqtt in","z":"fdfdb59a.dbf3f8","name":"Valve 1 status","topic":"garden/node2/gpio2_stat","qos":"2","datatype":"auto","broker":"681b9d99.717f94","x":90,"y":600,"wires":[["14fd21e9.8345ce","cde0ca54.0ea7d8"]]},{"id":"14fd21e9.8345ce","type":"debug","z":"fdfdb59a.dbf3f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":290,"y":640,"wires":[]},{"id":"cde0ca54.0ea7d8","type":"ui_text","z":"fdfdb59a.dbf3f8","group":"671f39c6.6d0858","order":6,"width":0,"height":0,"name":"Valve Current value","label":"Valve Current value","format":"{{msg.payload}}","layout":"row-center","x":310,"y":600,"wires":[]},{"id":"b50bbad8.776ff8","type":"change","z":"fdfdb59a.dbf3f8","name":"convert","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":180,"wires":[["b90d2e12.6f9bf"]]},{"id":"19ceb6c3.322569","type":"function","z":"fdfdb59a.dbf3f8","name":"Status of Switch","func":"global.set(\"Switch\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":420,"wires":[["1f578815.977fd8"]]},{"id":"cf5894c7.6c44d8","type":"ui_switch","z":"fdfdb59a.dbf3f8","name":"Switch","label":"Switch (Manual/Scheduler)","tooltip":"","group":"671f39c6.6d0858","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":70,"y":420,"wires":[["19ceb6c3.322569"]]},{"id":"b90d2e12.6f9bf","type":"function","z":"fdfdb59a.dbf3f8","name":"Status of Scheduler","func":"global.set(\"Scheduler_stat\",msg.payload);\nreturn msg;\n\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":180,"wires":[["e2f0e39f.10446"]]},{"id":"af43250.73801d8","type":"function","z":"fdfdb59a.dbf3f8","name":"Status of Valve 1","func":"global.set(\"SV1_stat\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":280,"wires":[["36cb5147.c7d2be"]]},{"id":"36cb5147.c7d2be","type":"debug","z":"fdfdb59a.dbf3f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":340,"wires":[]},{"id":"e2f0e39f.10446","type":"debug","z":"fdfdb59a.dbf3f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":120,"wires":[]},{"id":"da53790d.37b8d8","type":"debug","z":"fdfdb59a.dbf3f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":440,"wires":[]},{"id":"1f578815.977fd8","type":"debug","z":"fdfdb59a.dbf3f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":250,"y":480,"wires":[]},{"id":"f4444809.61b3a8","type":"function","z":"fdfdb59a.dbf3f8","name":"Valve 1 control","func":"var switchstatus=global.get(\"Switch\");\nvar scheduler=global.get(\"Scheduler_stat\");\nvar SV1=global.get(\"SV1_stat\");\n\nif(switchstatus==\"1\")\n{\n msg.payload = \"SV1\";\n}\nelse if(switchstatus==\"0\")\n{\n msg.payload = \"scheduler\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":440,"wires":[["1042ad1f.5e3d03","da53790d.37b8d8"]]},{"id":"31babaa1.3cffe6","type":"function","z":"fdfdb59a.dbf3f8","d":true,"name":"Valve 1 control test","func":"if (context.get(\"Switch\") == \"1\")\n{\n msg.payload = \"1\";\n}\nelse if (context.get(\"Switch\") == \"0\")\n{\n msg.payload = \"0\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":480,"wires":[["1042ad1f.5e3d03","da53790d.37b8d8"]]},{"id":"671f39c6.6d0858","type":"ui_group","name":"Garden","tab":"a8281535.325108","order":1,"disp":true,"width":"6","collapse":false},{"id":"681b9d99.717f94","type":"mqtt-broker","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"a8281535.325108","type":"ui_tab","name":"Garden","icon":"dashboard","order":1,"disabled":false,"hidden":false}]