Node RED activating different elements/diodes with Dashboard slider

Hello to All,

I used the Dashoboard slider to activate different elements, in my case raspberry pi 4 GPIO connected to diodes. The idea is that the slider has 4 steps 0, 1, 2 and.

When the slider is on 0 no diode shines.

When the slider is on 1, 1 diode shines.

When the slider is on 2, 2 diodes shine.

When the slider is on 3, all 3 diodes shine.

Just for information I also use links as the raspberry pi logic is in another flow. For interacting with raspberry pi I use the module " node-red-node-pi-gpio" (you need to have Node-RED on the raspberry pi, to control its GPIO pins)

https://nodered.org/docs/faq/interacting-with-pi-gpio

The function "Func1" to make the fist diode to shine, when the slider is 1, 2 or 3 position is:

if (msg.payload == 1 || msg.payload == 2 || msg.payload == 3)
{
    msg.payload = 1;
} else {
    
    msg.payload = 0;
    
}
return msg;

image

[{"id":"58826869.170d3","type":"ui_slider","z":"794cd749.ae3b9","name":"","label":"slider","tooltip":"","group":"dd11ee4.37f1b1","order":1,"width":0,"height":0,"passthru":false,"outs":"end","topic":"","topicType":"str","min":"0","max":"3","step":1,"x":330,"y":220,"wires":[["e3cc053c.5a3a38","9315d9b8.578a88","5bd7ebe0.9520fc"]]},{"id":"79d30609.fb0ed8","type":"link out","z":"794cd749.ae3b9","name":"1","links":["c6843345.dbac1"],"x":1095,"y":140,"wires":[]},{"id":"eba0eeb4.6eb45","type":"link out","z":"794cd749.ae3b9","name":"2","links":["6ba11d90.a3f234"],"x":1095,"y":240,"wires":[]},{"id":"775d7f38.06d928","type":"link out","z":"794cd749.ae3b9","name":"3","links":["ab6516ea.646c18"],"x":1095,"y":320,"wires":[]},{"id":"e3cc053c.5a3a38","type":"function","z":"794cd749.ae3b9","name":"Func1","func":"if (msg.payload == 1 || msg.payload == 2 || msg.payload == 3)\n{\n    msg.payload = 1;\n} else {\n    \n    msg.payload = 0;\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":140,"wires":[["79d30609.fb0ed8"]]},{"id":"9315d9b8.578a88","type":"function","z":"794cd749.ae3b9","name":"Func2","func":"if (msg.payload == 2 || msg.payload == 3)\n{\n    msg.payload = 1;\n} else {\n    \n    msg.payload = 0;\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":240,"wires":[["eba0eeb4.6eb45"]]},{"id":"5bd7ebe0.9520fc","type":"function","z":"794cd749.ae3b9","name":"Func3","func":"if (msg.payload == 3)\n{\n    msg.payload = 1;\n} else {\n    \n    msg.payload = 0;\n    \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":320,"wires":[["775d7f38.06d928"]]},{"id":"dd11ee4.37f1b1","type":"ui_group","name":"Default","tab":"e66b254.14380d8","order":1,"disp":true,"width":"6","collapse":false},{"id":"e66b254.14380d8","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Try this, It will send 1 or 0 to corresponding outputs depending on slider value.

[{"id":"17cf4abc.4dffb5","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":240,"y":3860,"wires":[["58826869.170d3"]]},{"id":"58826869.170d3","type":"ui_slider","z":"5a245aa1.510164","name":"","label":"slider","tooltip":"","group":"dd11ee4.37f1b1","order":1,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","topicType":"str","min":"0","max":"3","step":1,"x":340,"y":3940,"wires":[["e3cc053c.5a3a38"]]},{"id":"e3cc053c.5a3a38","type":"function","z":"5a245aa1.510164","name":"Func1","func":"if (msg.payload == 1 ){\n    return [{payload: 1},{payload: 0}, {payload: 0}]\n}else if ( msg.payload == 2 ){\n    return [{payload: 1},{payload: 1}, {payload: 0}]\n}else if ( msg.payload == 3){\n    return [{payload: 1},{payload: 1}, {payload: 1}]\n}else{\n    return [{payload: 0},{payload: 0}, {payload: 0}]\n}\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","x":480,"y":3940,"wires":[["223e5053.1d17e"],["223e5053.1d17e"],["223e5053.1d17e"]]},{"id":"a755c89.8a54338","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":260,"y":4100,"wires":[["58826869.170d3"]]},{"id":"27ebd5d9.45522a","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":260,"y":4040,"wires":[["58826869.170d3"]]},{"id":"e423764d.a9e948","type":"inject","z":"5a245aa1.510164","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":240,"y":4000,"wires":[["58826869.170d3"]]},{"id":"223e5053.1d17e","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":3920,"wires":[]},{"id":"dd11ee4.37f1b1","type":"ui_group","name":"Default","tab":"e66b254.14380d8","order":1,"disp":true,"width":"6","collapse":false},{"id":"e66b254.14380d8","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
2 Likes

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