Executing Python scripts based on node templates (without file)

here is example like a https://flows.nodered.org/flow/0a6e073bcd6bda364fafd32699837cc7 but without creating python file.

[{"id":"98fca24aeaf2d408","type":"inject","z":"d49472cb.6086a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":60,"wires":[["2aec38202e8e25a9"]]},{"id":"f450911752855685","type":"exec","z":"d49472cb.6086a","command":"python3 -c","addpay":"payload","append":"","useSpawn":"false","timer":"5","winHide":false,"oldrc":false,"name":"","x":590,"y":60,"wires":[["793df30a8fdf7bf2"],[],[]]},{"id":"793df30a8fdf7bf2","type":"debug","z":"d49472cb.6086a","name":"debug 62","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":40,"wires":[]},{"id":"2aec38202e8e25a9","type":"template","z":"d49472cb.6086a","name":"","field":"payload","fieldType":"msg","format":"python","syntax":"plain","template":"# Python code\na = 1\nb = 2\nc = a + b\nprint(c)","output":"str","x":280,"y":60,"wires":[["32fc2683618b1091"]]},{"id":"32fc2683618b1091","type":"function","z":"d49472cb.6086a","name":"quote","func":"msg.payload = `\"${msg.payload}\"`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":60,"wires":[["f450911752855685"]]}]

Flow Info

Created 2 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • exec (x1)
  • function (x1)
  • inject (x1)
  • template (x1)

Tags

  • python
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option