Skip to content

Instantly share code, notes, and snippets.

@michael-fobian
Created January 14, 2020 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-fobian/0a6e073bcd6bda364fafd32699837cc7 to your computer and use it in GitHub Desktop.
Save michael-fobian/0a6e073bcd6bda364fafd32699837cc7 to your computer and use it in GitHub Desktop.
Executing Python scripts based on node templates

I was searching for documentation on how to write a Python script using the template node and executing that script with the exec node.

This flow is an example of that - using only built in Node-RED nodes.

I would have liked to skip the part, where I am writing the file to disk - but I was unable to get this result, when running the exec node in spawn mode.

[{"id":"d7276cd2.d6f55","type":"tab","label":"pythontest","disabled":false,"info":""},{"id":"a7d4e707.fd8a18","type":"inject","z":"d7276cd2.d6f55","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":240,"wires":[["97c92fce.dd6f6"]]},{"id":"97c92fce.dd6f6","type":"template","z":"d7276cd2.d6f55","name":"","field":"payload","fieldType":"msg","format":"python","syntax":"plain","template":"import time\n\nwhile True:\n print(time.ctime())\n time.sleep(10)\n","output":"str","x":320,"y":240,"wires":[["1273e63.74b5c1a"]]},{"id":"1273e63.74b5c1a","type":"file","z":"d7276cd2.d6f55","name":"","filename":"pythontest.py","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":510,"y":240,"wires":[["14057906.c24237"]]},{"id":"14057906.c24237","type":"exec","z":"d7276cd2.d6f55","command":"python3 pythontest.py","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"","x":740,"y":240,"wires":[["a33c536c.9900e"],[],[]]},{"id":"a33c536c.9900e","type":"debug","z":"d7276cd2.d6f55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":970,"y":240,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment