Single Button MultiPress (subflow)

Sends single, double, triple or long press commands based on binary input (e.g GPIO switches or other switches that sends "pressed" and "released" events). Video of this subflow in action here

If you are using an IHC controller, you should create the multipress logic in the original controller software instead.

Subflow image

Example flow 1 image

Example flow 2 image


Copy the subflow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option

[{"id":"c23401c4.cf92b","type":"subflow","name":"Single Button MultiPress","info":"","category":"","in":[{"x":60,"y":100,"wires":[{"id":"f6674880.4a98d8"}]}],"out":[{"x":780,"y":260,"wires":[{"id":"621fd442.e3355c","port":0},{"id":"bb24b600.e59d68","port":0}]},{"x":780,"y":300,"wires":[{"id":"621fd442.e3355c","port":1}]},{"x":780,"y":340,"wires":[{"id":"621fd442.e3355c","port":2}]},{"x":780,"y":380,"wires":[{"id":"9a560181.5faed","port":0}]}],"env":[{"name":"ButtonPressed","type":"str","value":"0"},{"name":"ButtonReleased","type":"str","value":"1"},{"name":"single press","type":"str","value":"single press output"},{"name":"double press","type":"str","value":"double press output"},{"name":"triple press","type":"str","value":"triple press output"},{"name":"long press","type":"str","value":"long press output"}],"color":"#E6E0F8","inputLabels":["from trigger"],"outputLabels":["Single press","Double press","Triple press","Long press"],"icon":"node-red/serial.svg","status":{"x":780,"y":220,"wires":[{"id":"9a560181.5faed","port":0},{"id":"3833bace.548da6","port":0},{"id":"bb24b600.e59d68","port":0}]}},{"id":"7fefbd86.bcfda4","type":"trigger","z":"c23401c4.cf92b","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"400","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Wait for 400 ms","x":480,"y":180,"wires":[["3833bace.548da6"]]},{"id":"f6674880.4a98d8","type":"switch","z":"c23401c4.cf92b","name":"pressed/released?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ButtonPressed","vt":"env"},{"t":"eq","v":"ButtonReleased","vt":"env"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":100,"wires":[["6218943c.5fc54c","6fd796e.e5a7968"],["7fefbd86.bcfda4","31b52fd1.ea8d1"]]},{"id":"3ced6124.55172e","type":"function","z":"c23401c4.cf92b","name":"set press variable","func":"if (flow.get(\"presses\") == env.get(\"triple press\"))\n    {\n    }\nelse\n    if (flow.get(\"presses\") == env.get(\"double press\"))\n    {\n    flow.set(\"presses\", env.get(\"triple press\"));\n    }\n    else\n    {\n    flow.set(\"presses\", env.get(\"double press\"));\n    }\nreturn msg","outputs":1,"noerr":0,"x":210,"y":220,"wires":[["81be5c16.dd42a"]]},{"id":"6218943c.5fc54c","type":"trigger","z":"c23401c4.cf92b","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"1.5","extend":false,"units":"s","reset":"","bytopic":"all","name":"long press?","x":470,"y":100,"wires":[["9a560181.5faed"]]},{"id":"3833bace.548da6","type":"change","z":"c23401c4.cf92b","name":"flow -> payload","rules":[{"t":"move","p":"presses","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"presses","pt":"flow","to":"single press","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":220,"wires":[["621fd442.e3355c"]]},{"id":"9a560181.5faed","type":"change","z":"c23401c4.cf92b","name":"long press","rules":[{"t":"set","p":"presses","pt":"flow","to":"long press","tot":"env"},{"t":"set","p":"payload","pt":"msg","to":"long press","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":100,"wires":[[]]},{"id":"621fd442.e3355c","type":"switch","z":"c23401c4.cf92b","name":"Sort payloads","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single press","vt":"env"},{"t":"eq","v":"double press","vt":"env"},{"t":"eq","v":"triple press","vt":"env"},{"t":"null"},{"t":"eq","v":"long press","vt":"env"}],"checkall":"true","repair":false,"outputs":5,"x":520,"y":280,"wires":[[],[],[],["bb24b600.e59d68"],["7c14d743.8ab428"]]},{"id":"bb24b600.e59d68","type":"change","z":"c23401c4.cf92b","name":"null -> single press","rules":[{"t":"set","p":"payload","pt":"msg","to":"single press","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":340,"wires":[[]]},{"id":"31b52fd1.ea8d1","type":"change","z":"c23401c4.cf92b","name":"reset trigger","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["6218943c.5fc54c"]]},{"id":"81be5c16.dd42a","type":"change","z":"c23401c4.cf92b","name":"reset trigger","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":260,"wires":[["7fefbd86.bcfda4"]]},{"id":"6fd796e.e5a7968","type":"change","z":"c23401c4.cf92b","name":"press timers","rules":[{"t":"move","p":"NewTime","pt":"flow","to":"OldTime","tot":"flow"},{"t":"set","p":"NewTime","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":140,"wires":[["daa2d16.c4ed63"]]},{"id":"daa2d16.c4ed63","type":"function","z":"c23401c4.cf92b","name":"Short time?","func":"if (flow.get(\"NewTime\") - flow.get(\"OldTime\") <= 400)\n{\n    msg.payload = \"Short press\";\n    return msg;\n}","outputs":1,"noerr":0,"x":230,"y":180,"wires":[["3ced6124.55172e"]]},{"id":"7c14d743.8ab428","type":"change","z":"c23401c4.cf92b","name":"set default flow.presses","rules":[{"t":"set","p":"presses","pt":"flow","to":"single press","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":380,"wires":[[]]},{"id":"8cf7c1f0.509b4","type":"comment","z":"c23401c4.cf92b","name":"Link to latest version of this subflow: https://flows.nodered.org/flow/7c76f205de0dd761a075b6cb0128b480","info":"","x":410,"y":40,"wires":[]}]

Collection Info

Flow Info

Created 4 years, 5 months ago
Updated 4 years, 4 months ago
Rating: 5 3

Owner

Actions

Rate:

Node Types

Core
  • change (x7)
  • comment (x1)
  • function (x2)
  • switch (x2)
  • trigger (x2)
Other
  • subflow (x1)

Tags

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