How to detect multiple presses on a single button

With reference to this thread:
Single button multiple presses

Have you ever wanted to allow multiple presses from a button do multiple things?

This flow allows that.

One "problem" the use of a flow. variable.

If you are going to use multiple versions on the one flow, you need to edit the name used in the flow.set node and the count presses node.

Oh, and you will/may need to install this node:
node-red-contrib-counter

[{"id":"47f8333.7595f4c","type":"change","z":"710ca09a.8302a8","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"foo","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":1000,"wires":[["baa481f7.8c92f"]]},{"id":"46bb072c.9ab548","type":"inject","z":"710ca09a.8302a8","name":"Reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"0.5","x":400,"y":1040,"wires":[["47f8333.7595f4c"]]},{"id":"6419695d.f444a8","type":"debug","z":"710ca09a.8302a8","name":"Four presses","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":1120,"wires":[]},{"id":"9a9ece0e.e21968","type":"inject","z":"710ca09a.8302a8","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":403.33331298828125,"y":951.111083984375,"wires":[["baa481f7.8c92f","d4d7fd43.e18b5"]]},{"id":"baa481f7.8c92f","type":"counter","z":"710ca09a.8302a8","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":590,"y":950,"wires":[["eeab3859.a0a81","1ccfa267.6709d6"]]},{"id":"cdc2f3f7.8cd668","type":"switch","z":"710ca09a.8302a8","name":"count presses","property":"count","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":790,"y":1060,"wires":[["c3a6c0e7.e7824"],["1939c1b3.49b2c6"],["7bfb6bfb.a555f4"],["c75d22c1.43a18"]],"info":"Just expand the flow.count to how ever many\npresses you want/need."},{"id":"d4d7fd43.e18b5","type":"trigger","z":"710ca09a.8302a8","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"6","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":410,"y":1000,"wires":[["47f8333.7595f4c"]]},{"id":"1ccfa267.6709d6","type":"change","z":"710ca09a.8302a8","name":"Flow set","rules":[{"t":"set","p":"count","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":910,"wires":[[]]},{"id":"d5ec0e6d.65fe68","type":"debug","z":"710ca09a.8302a8","name":"Tripple press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":1080,"wires":[]},{"id":"a4900536.188a4","type":"debug","z":"710ca09a.8302a8","name":"Double press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":1040,"wires":[]},{"id":"f7ea3f92.56f1b","type":"delay","z":"710ca09a.8302a8","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":770,"y":1000,"wires":[["cdc2f3f7.8cd668"]]},{"id":"eaa4f15.17e7a9","type":"debug","z":"710ca09a.8302a8","name":"Single Press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":1000,"wires":[]},{"id":"eeab3859.a0a81","type":"switch","z":"710ca09a.8302a8","name":"","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":760,"y":950,"wires":[["f7ea3f92.56f1b"]]},{"id":"c3a6c0e7.e7824","type":"change","z":"710ca09a.8302a8","name":"Single Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Single Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":1000,"wires":[["eaa4f15.17e7a9"]]},{"id":"1939c1b3.49b2c6","type":"change","z":"710ca09a.8302a8","name":"Double Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Double Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":1040,"wires":[["a4900536.188a4"]]},{"id":"7bfb6bfb.a555f4","type":"change","z":"710ca09a.8302a8","name":"Tripple Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Tripple Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":1080,"wires":[["d5ec0e6d.65fe68"]]},{"id":"c75d22c1.43a18","type":"change","z":"710ca09a.8302a8","name":"Four Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Four Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":1120,"wires":[["6419695d.f444a8"]]},{"id":"c0dd4310.43d0a8","type":"comment","z":"710ca09a.8302a8","name":"DELAY - Readme","info":"The DELAY time has to be a bit longer than how\nlong it takes you to press the button the\nmaximum number of times.\nRead information in the SWITCH node too!","x":790,"y":870,"wires":[]},{"id":"8caf97b8.187508","type":"comment","z":"710ca09a.8302a8","name":"Input","info":"","x":400,"y":910,"wires":[]},{"id":"70b7384.c5ce6c8","type":"comment","z":"710ca09a.8302a8","name":"Outputs","info":"Debug nodes are here now, but just connect\nthem to what ever you want.\nThe messages sent are in the nodes just before\nthe debug nodes.\n","x":1150,"y":960,"wires":[]}]
2 Likes

I've re-written the code to optimise how it works and for how long you can be pressing the button.

The old flow limits you to 6 seconds. Granted that is a long time, but it is limited.

I re-wrote how it works which allows unlimited pressing of the button.

Also with the old way you had to wait 6 seconds between sequences, which is also a bit long.

The new one takes that down to 1 second.

This new way the reset signal is kept from being sent because the button has been pressed again with an interval of less than 1 second.

This is 4 examples.
I pressed the inject node 1, 2,3 and 4 times, and got those 4 messages.
Sorry too: I haven't updated an of the comment nodes.

I was a bit over come with excitement that I got the re-write done and wanted to share.
(Yeah, I know. Not really professional.)

[{"id":"1139a03d.d1ca","type":"change","z":"184dc884.7aba5f","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"foo","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":2270,"wires":[["fcb3cb17.693a9"]]},{"id":"900577c3.9deb4","type":"inject","z":"184dc884.7aba5f","name":"Reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"0.5","x":430,"y":2230,"wires":[["1139a03d.d1ca"]]},{"id":"820bd696.fbc028","type":"debug","z":"184dc884.7aba5f","name":"Four presses","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":2370,"wires":[]},{"id":"525e3ec9.3bb6b8","type":"inject","z":"184dc884.7aba5f","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":273.33331298828125,"y":2201.111083984375,"wires":[["fcb3cb17.693a9","ba72e20d.299b8"]]},{"id":"fcb3cb17.693a9","type":"counter","z":"184dc884.7aba5f","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":620,"y":2200,"wires":[["9faf97df.4ce4a"]]},{"id":"4189a6d1.44073","type":"switch","z":"184dc884.7aba5f","name":"count presses","property":"count","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":790,"y":2310,"wires":[["83d02113.4743b8"],["fbfe53e5.4fcae8"],["e22efc97.c6b018"],["d9a249bd.1f82a8"]],"info":"Just expand the flow.count to how ever many\npresses you want/need."},{"id":"ba72e20d.299b8","type":"trigger","z":"184dc884.7aba5f","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"1","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":440,"y":2310,"wires":[["62860129.ec7bd","4189a6d1.44073"]]},{"id":"9faf97df.4ce4a","type":"change","z":"184dc884.7aba5f","name":"Flow set","rules":[{"t":"set","p":"count","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":2200,"wires":[["a018a094.13d14"]]},{"id":"ddd0ab58.0a3e58","type":"debug","z":"184dc884.7aba5f","name":"Tripple press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":2330,"wires":[]},{"id":"ed9739c.0628148","type":"debug","z":"184dc884.7aba5f","name":"Double press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":2290,"wires":[]},{"id":"8082f0.4ba02d1","type":"debug","z":"184dc884.7aba5f","name":"Single Press","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":2250,"wires":[]},{"id":"83d02113.4743b8","type":"change","z":"184dc884.7aba5f","name":"Single Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Single Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":2250,"wires":[["8082f0.4ba02d1"]]},{"id":"fbfe53e5.4fcae8","type":"change","z":"184dc884.7aba5f","name":"Double Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Double Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":2290,"wires":[["ed9739c.0628148"]]},{"id":"e22efc97.c6b018","type":"change","z":"184dc884.7aba5f","name":"Tripple Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Tripple Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":2330,"wires":[["ddd0ab58.0a3e58"]]},{"id":"d9a249bd.1f82a8","type":"change","z":"184dc884.7aba5f","name":"Four Press","rules":[{"t":"set","p":"payload","pt":"msg","to":"Four Press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":2370,"wires":[["820bd696.fbc028"]]},{"id":"a1783324.3f9f","type":"comment","z":"184dc884.7aba5f","name":"DELAY - Readme","info":"The DELAY time has to be a bit longer than how\nlong it takes you to press the button the\nmaximum number of times.\nRead information in the SWITCH node too!","x":820,"y":2120,"wires":[]},{"id":"660d35d0.b41aa4","type":"comment","z":"184dc884.7aba5f","name":"Input","info":"","x":430,"y":2160,"wires":[]},{"id":"f91932b.cacfb5","type":"comment","z":"184dc884.7aba5f","name":"Outputs","info":"Debug nodes are here now, but just connect\nthem to what ever you want.\nThe messages sent are in the nodes just before\nthe debug nodes.\n","x":1160,"y":2210,"wires":[]},{"id":"a018a094.13d14","type":"debug","z":"184dc884.7aba5f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"count","targetType":"msg","x":1000,"y":2200,"wires":[]},{"id":"62860129.ec7bd","type":"delay","z":"184dc884.7aba5f","name":"Delay","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":2270,"wires":[["1139a03d.d1ca"]]}]
2 Likes

This is an excellent flow, I've been looking for something similar for my garage. On two occasions the garage has opened and i wasn't sure why. I feel like if i put the garage switch on a double press it should eliminate that problem.

Makes me want to add secret double press and triple presses to all my room light switches now.