output-Blinker

A subflow to send pulsing messages at a given interval to make something flash. Configurable by setting environment variables in the node's settings.

Output toggle node to send alternating messages at a specified frequency.

3 things need to be set to configure this subflow

1 - delay: milliseconds between toggls
2 - msg1: text message for state 1
3 - msg2: text message for state 2

Optional:

offmsg - sent when it is reset. May be handy to make sure things are off.

Input message

To start send msg.payload (anything)

To stop, send msg.reset (payload anything but please don't use timestamp)

Added: msg.topic now also toggles between 1 and 2 to indicate which message is being sent.

[{"id":"ca5e1e7f2227fa14","type":"subflow","name":"Blinker","info":"2021 12 7  \nA subflow to send pulsing messages at a given interval to make something *flash*.\nConfigurable by setting `environment` variables in the node's settings.\n\n\n# **Output toggle node to send alternating messages at a specified frequency.**\n# \n\n## 3 things need to be set to configure this subflow\n1 - `delay`:  milliseconds between toggls  \n2 - `msg1`:   text message for state 1  \n3 - `msg2`:   text message for state 2  \n \n## Optional:\n`offmsg` - sent when it is reset.\nMay be handy to make sure things are *off*.\n\n## Input message\nTo start send `msg.payload` (anything)\n\nTo stop, send `msg.reset` (`payload` anything but please don't use `timestamp`)\n\nAdded:\n`msg.topic` now also toggles between `1` and `2` to indicate which message is being sent.","category":"","in":[{"x":50,"y":190,"wires":[{"id":"80431f306bf42227"}]}],"out":[{"x":780,"y":190,"wires":[{"id":"7f2e332fb32d3422","port":0},{"id":"0666cb89ee9025cf","port":0}]}],"env":[{"name":"delay","type":"num","value":""},{"name":"msg1","type":"str","value":""},{"name":"msg2","type":"str","value":""},{"name":"offmsg","type":"str","value":""}],"meta":{"module":"Toggler","version":"0.1.1","desc":"Toggles output between `msg1` and `msg2` set in node config"},"color":"#A6BBCF","icon":"node-red-contrib-bool-gate/switch.png","status":{"x":780,"y":290,"wires":[{"id":"b1feb246df6a838b","port":0}]}},{"id":"a19da66d6694960f","type":"trigger","z":"ca5e1e7f2227fa14","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-2","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":190,"wires":[["7f2e332fb32d3422"]]},{"id":"7f2e332fb32d3422","type":"function","z":"ca5e1e7f2227fa14","name":"toggle","func":"msg1 = {};\nlet c = context.get(\"counter\") ||0;\nif (c == 0)\n{\n    //  0\n    msg.payload = env.get(\"msg1\");\n    msg.topic = \"1\";\n} else\nif (c == 1)\n{\n    //  1\n    msg.payload = env.get(\"msg2\");\n    msg.topic = \"2\";\n}\nmsg1.payload = c;\nc = (c + 1) % 2;\ncontext.set(\"counter\",c);\nreturn [msg,msg1];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":190,"wires":[[],["b1feb246df6a838b"]]},{"id":"8e3e5f0baa510afb","type":"switch","z":"ca5e1e7f2227fa14","name":"reset?","property":"reset","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":230,"wires":[["705f9da2fdc55481","490014d846f3ef05"]]},{"id":"705f9da2fdc55481","type":"switch","z":"ca5e1e7f2227fa14","name":"off msg?","property":"offmsg","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":230,"wires":[["0666cb89ee9025cf"]]},{"id":"0666cb89ee9025cf","type":"change","z":"ca5e1e7f2227fa14","name":"set off message","rules":[{"t":"set","p":"payload","pt":"msg","to":"offmsg","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":230,"wires":[[]]},{"id":"b1feb246df6a838b","type":"function","z":"ca5e1e7f2227fa14","name":"","func":"let c = msg.payload;\nif (c == 0)\n{\n    msg.payload = ({text: \"A\"});\n} else if (c == 1)\n{\n    msg.payload = ({text: \"B\"});\n} else\n    msg.payload = ({text:\" \"});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":290,"wires":[[]]},{"id":"490014d846f3ef05","type":"change","z":"ca5e1e7f2227fa14","name":"Reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":290,"wires":[["b1feb246df6a838b"]]},{"id":"80431f306bf42227","type":"function","z":"ca5e1e7f2227fa14","name":"set msg.delay","func":"msg.delay = env.get(\"delay\") || 1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":190,"wires":[["a19da66d6694960f","8e3e5f0baa510afb"]]},{"id":"1be47fea79647a74","type":"subflow:ca5e1e7f2227fa14","z":"0918ee609bf69fc7","name":"","x":320,"y":500,"wires":[[]]}]

Flow Info

Created 3 years, 5 months ago
Rating: 3 2

Actions

Rate:

Node Types

Core
  • change (x2)
  • function (x3)
  • switch (x2)
  • trigger (x1)
Other
  • subflow (x1)
  • subflow:ca5e1e7f2227fa14 (x1)

Tags

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