On/off switch start and stop Python script

I'm completely new with Node RED but so far I can make a button start a python script and another button stops the script.

But I would like to do this by using a on/off switch.
I can't get it to work.

The switch has 2 parameters (On Payload / Off Payload) and I thought I add a Exec node tot start and another Exec node to stop, but off course this doesn't work.

Can anybody help me?
What I want is to turn the switch to ON and the Python script mus start.
If I set the switch to OFF the script to kill the running Python script must be run.

node-red-python

A hint, use a switch node after the button

image

1 Like

Or with one ui-switch node and one exec node

[{"id":"3b8da533.1afcea","type":"ui_switch","z":"bf9e1e33.030598","name":"","label":"switch","tooltip":"","group":"2d4fe667.28f8ba","order":25,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"python/home/pi/test.py","onvalueType":"str","onicon":"","oncolor":"","offvalue":"fpkill -9 -f test.py","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":250,"y":2260,"wires":[["7700fa69.710624"]]},{"id":"7700fa69.710624","type":"exec","z":"bf9e1e33.030598","command":"","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":420,"y":2260,"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}]

1 Like

Wow, that's easy.

1 Like

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