This is my effort at a node which could be handy for people who like flashy things on their dashboard.
You want to make a light blink rather than just be constantly on.
Though not complicated, this may save you some heart ache.
The toggle
node does this for you and you can configure it with 3 settings:
1 - how fast you want it to toggle. (Set in milliseconds)
2 - The first message to be sent
3 - The second message to be sent
There is an optional offmsg
which could be handy if you are blinking a light between two colours and want it off when the flashing has stopped.
Example flow included.
Subflow node:
[{"id":"ca5e1e7f2227fa14","type":"subflow","name":"Toggler","info":"# **Output toggle node to send alternating messages at a specified frequency.\n# **\n## 3 things need to be set to configure this subflow\n * 1 - `delay`: milliseconds between toggls\n * 2 - `msg1`: text message for state 1\n * 3 - `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` (anything but don't use `timestamp`)\n\nSet the variables (`delay`, `msg1`, `msg2` and optionally `offmsg`) as environment variables in this node's config page.\n","category":"","in":[{"x":50,"y":80,"wires":[{"id":"bebc43cf227dc00a"},{"id":"8e3e5f0baa510afb"}]}],"out":[{"x":660,"y":80,"wires":[{"id":"7f2e332fb32d3422","port":0},{"id":"0666cb89ee9025cf","port":0}]}],"env":[],"meta":{"module":"Toggler","version":"0.1","desc":"Toggles output between `msg1` and `msg2` set in node config"},"color":"#A6BBCF","icon":"node-red-contrib-bool-gate/switch.png"},{"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":380,"y":80,"wires":[["7f2e332fb32d3422"]]},{"id":"7f2e332fb32d3422","type":"function","z":"ca5e1e7f2227fa14","name":"toggle","func":"let c = context.get(\"counter\") ||0;\nif (c == 0)\n{\n // 0\n //msg.payload = \"rgb,1,0,18,12\";\n msg.payload = env.get(\"msg1\");\n} else\nif (c == 1)\n{\n // 1\n //msg.payload = \"rgb,1,0,0,0\";\n msg.payload = env.get(\"msg2\");\n}\nc = (c + 1) % 2;\ncontext.set(\"counter\",c);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":80,"wires":[[]]},{"id":"bebc43cf227dc00a","type":"change","z":"ca5e1e7f2227fa14","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":80,"wires":[["a19da66d6694960f"]]},{"id":"8e3e5f0baa510afb","type":"switch","z":"ca5e1e7f2227fa14","name":"reset?","property":"reset","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":160,"y":120,"wires":[["705f9da2fdc55481"]]},{"id":"705f9da2fdc55481","type":"switch","z":"ca5e1e7f2227fa14","name":"off msg?","property":"offmsg","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":120,"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":520,"y":120,"wires":[[]]},{"id":"2d6c0ca8e486046c","type":"subflow:ca5e1e7f2227fa14","z":"3b6b347467ee4c87","name":"","env":[{"name":"delay","value":"1000","type":"num"},{"name":"msg1","value":"message 1","type":"str"},{"name":"msg2","value":"message 2","type":"str"},{"name":"offmsg","value":"off","type":"str"}],"x":420,"y":280,"wires":[["6e383c3d1a21b3aa"]],"info":"** 3 things needed to configure\n1 - delay: milliseconds between toggling\n2 - msg1: text message 1\n3 - msg2: text message 2\n"}]
Example flow:
[{"id":"ca5e1e7f2227fa14","type":"subflow","name":"Toggler","info":"# **Output toggle node to send alternating messages at a specified frequency.\n# **\n## 3 things need to be set to configure this subflow\n * 1 - `delay`: milliseconds between toggls\n * 2 - `msg1`: text message for state 1\n * 3 - `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` (anything but don't use `timestamp`)\n\nSet the variables (`delay`, `msg1`, `msg2` and optionally `offmsg`) as environment variables in this node's config page.\n","category":"","in":[{"x":50,"y":80,"wires":[{"id":"bebc43cf227dc00a"},{"id":"8e3e5f0baa510afb"}]}],"out":[{"x":660,"y":80,"wires":[{"id":"7f2e332fb32d3422","port":0},{"id":"0666cb89ee9025cf","port":0}]}],"env":[],"meta":{"module":"Toggler","version":"0.1","desc":"Toggles output between `msg1` and `msg2` set in node config"},"color":"#A6BBCF","icon":"node-red-contrib-bool-gate/switch.png"},{"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":380,"y":80,"wires":[["7f2e332fb32d3422"]]},{"id":"7f2e332fb32d3422","type":"function","z":"ca5e1e7f2227fa14","name":"toggle","func":"let c = context.get(\"counter\") ||0;\nif (c == 0)\n{\n // 0\n //msg.payload = \"rgb,1,0,18,12\";\n msg.payload = env.get(\"msg1\");\n} else\nif (c == 1)\n{\n // 1\n //msg.payload = \"rgb,1,0,0,0\";\n msg.payload = env.get(\"msg2\");\n}\nc = (c + 1) % 2;\ncontext.set(\"counter\",c);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":80,"wires":[[]]},{"id":"bebc43cf227dc00a","type":"change","z":"ca5e1e7f2227fa14","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":80,"wires":[["a19da66d6694960f"]]},{"id":"8e3e5f0baa510afb","type":"switch","z":"ca5e1e7f2227fa14","name":"reset?","property":"reset","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":160,"y":120,"wires":[["705f9da2fdc55481"]]},{"id":"705f9da2fdc55481","type":"switch","z":"ca5e1e7f2227fa14","name":"off msg?","property":"offmsg","propertyType":"env","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":120,"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":520,"y":120,"wires":[[]]},{"id":"7679fb92b3291a98","type":"inject","z":"3b6b347467ee4c87","name":"start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":210,"y":260,"wires":[["2d6c0ca8e486046c"]]},{"id":"fc206ec3b72d19b7","type":"inject","z":"3b6b347467ee4c87","name":"stop","props":[{"p":"reset","v":"blah","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":300,"wires":[["2d6c0ca8e486046c"]]},{"id":"6e383c3d1a21b3aa","type":"debug","z":"3b6b347467ee4c87","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":280,"wires":[]},{"id":"2d6c0ca8e486046c","type":"subflow:ca5e1e7f2227fa14","z":"3b6b347467ee4c87","name":"","env":[{"name":"delay","value":"1000","type":"num"},{"name":"msg1","value":"message 1","type":"str"},{"name":"msg2","value":"message 2","type":"str"},{"name":"offmsg","value":"off","type":"str"}],"x":420,"y":280,"wires":[["6e383c3d1a21b3aa"]],"info":"** 3 things needed to configure\n1 - delay: milliseconds between toggling\n2 - msg1: text message 1\n3 - msg2: text message 2\n"}]
Enjoy!