# How to detect multiple presses on a single button

**URL:** <https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560>\
**Category:** Share Your Projects\
**Created:** [19 January 2020 07:44 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560 "2020-01-19T07:44:08Z")\
**Posts on this page:** 8\
**Page:** 4

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 January 2023 18:34 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/62 "2023-01-17T18:34:42Z")

</div>

So which node is generating the error?  
What are you doing to that node?

The more information you provide, the easier it will be to help you

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 January 2023 19:18 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/63 "2023-01-17T19:18:47Z")

</div>

That code you posted is the `subflow`.

You shouldn't be changing that part.

This is the flow - again:

```auto
[{"id":"4be6db179f2af0b9","type":"subflow","name":"Press count","info":"2023 01 17\n==========\nUsed to count button presses and send the number in a message.\n\nIf `msg.payload` == `reset` then `0` is sent out.\nHandy if you want to also include a *reset* ability.\n\nSet the *timeout* value in the `delay` variable.\n_This controls how long between presses before it stops counting._\n\nThen send the output message into a `switch` node to do wonderful things.\n\nThe output message is a `number`.","category":"","in":[{"x":60,"y":270,"wires":[{"id":"df8cb339f3aed3ba"}]}],"out":[{"x":870,"y":210,"wires":[{"id":"900cc4787c0480a4","port":0}]}],"env":[{"name":"delay","type":"num","value":"","ui":{"type":"input","opts":{"types":["num"]}}}],"meta":{},"color":"#D8BFD8","icon":"node-red-dashboard/ui_button.png","status":{"x":870,"y":370,"wires":[{"id":"900476fafffa3ae3","port":0}]}},{"id":"c2137fa8aec03468","type":"inject","z":"4be6db179f2af0b9","name":"Reset","repeat":"","crontab":"","once":true,"onceDelay":"0.5","topic":"","payload":"","payloadType":"date","x":350,"y":290,"wires":[["5188ca7c92884164"]]},{"id":"de02a7b5bf7954d2","type":"trigger","z":"4be6db179f2af0b9","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"0.5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":370,"y":250,"wires":[["a14dd5822f1f6015","900cc4787c0480a4"]]},{"id":"5188ca7c92884164","type":"change","z":"4be6db179f2af0b9","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":560,"y":250,"wires":[["d5314c210f7d9a76"]]},{"id":"d5314c210f7d9a76","type":"counter","z":"4be6db179f2af0b9","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":520,"y":330,"wires":[["6a5f10e31345b897","bb0e17c295353204"]]},{"id":"6a5f10e31345b897","type":"change","z":"4be6db179f2af0b9","name":"Flow set","rules":[{"t":"set","p":"count","pt":"flow","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":280,"wires":[[]]},{"id":"a457eafcdad07d0b","type":"change","z":"4be6db179f2af0b9","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":275,"y":330,"wires":[["d5314c210f7d9a76","de02a7b5bf7954d2"]],"l":false},{"id":"a14dd5822f1f6015","type":"change","z":"4be6db179f2af0b9","name":"","rules":[{"t":"delete","p":"delay","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":250,"wires":[["5188ca7c92884164"]],"l":false},{"id":"900cc4787c0480a4","type":"function","z":"4be6db179f2af0b9","name":"","func":"msg.payload = flow.get(\"count\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":210,"wires":[[]]},{"id":"bb0e17c295353204","type":"function","z":"4be6db179f2af0b9","name":"CounterValue","func":"node.status({text: \"Counting \" + msg.count});\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":330,"wires":[[]]},{"id":"900476fafffa3ae3","type":"status","z":"4be6db179f2af0b9","name":"","scope":["bb0e17c295353204"],"x":720,"y":370,"wires":[[]]},{"id":"df8cb339f3aed3ba","type":"switch","z":"4be6db179f2af0b9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"reset","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":150,"y":270,"wires":[["397e91b8f88a8919"],["a457eafcdad07d0b"]]},{"id":"397e91b8f88a8919","type":"delay","z":"4be6db179f2af0b9","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":360,"y":210,"wires":[["900cc4787c0480a4"]]},{"id":"368441726da6ee2d","type":"switch","z":"61bbf627ae47ef79","name":"","property":"payload","propertyType":"msg","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"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":6,"x":530,"y":370,"wires":[["eb54e503b5d97e8c"],["f181fd63da81183e"],["160f7a1381ce6497"],["4a85fa0b5cdb8740"],["14373e93f065b9ac"],["b7b26884eb6dad18"]]},{"id":"2408dde860e38d1e","type":"subflow:4be6db179f2af0b9","z":"61bbf627ae47ef79","name":"","env":[{"name":"delay","value":"500","type":"num"}],"x":360,"y":370,"wires":[["8c5f32e93ce2032d","368441726da6ee2d"]]},{"id":"eb54e503b5d97e8c","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"20% brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":310,"wires":[["3fd47f6616a9cca0","23049a79b40fe27a"]]},{"id":"f181fd63da81183e","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"40% brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":350,"wires":[["3fd47f6616a9cca0","23049a79b40fe27a"]]},{"id":"160f7a1381ce6497","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"60% brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":390,"wires":[["3fd47f6616a9cca0","23049a79b40fe27a"]]},{"id":"4a85fa0b5cdb8740","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"80% brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":430,"wires":[["3fd47f6616a9cca0","23049a79b40fe27a"]]},{"id":"14373e93f065b9ac","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"100% brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":470,"wires":[["3fd47f6616a9cca0","23049a79b40fe27a"]]},{"id":"b7b26884eb6dad18","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Light OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":520,"wires":[["23049a79b40fe27a","3fd47f6616a9cca0"]]},{"id":"a8a93eacebc03ec5","type":"inject","z":"61bbf627ae47ef79","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":370,"wires":[["2408dde860e38d1e"]]},{"id":"b1457747009dbc0b","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":580,"wires":[["2408dde860e38d1e"]]},{"id":"fce5c98a896cee68","type":"change","z":"61bbf627ae47ef79","name":"Reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":270,"wires":[["2408dde860e38d1e","c5be9bf8e7969338"]]},{"id":"9011504eb312ea1b","type":"gate","z":"61bbf627ae47ef79","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":340,"y":440,"wires":[["2408dde860e38d1e"]]},{"id":"8c5f32e93ce2032d","type":"debug","z":"61bbf627ae47ef79","name":"debug 54","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":310,"wires":[]},{"id":"3fd47f6616a9cca0","type":"debug","z":"61bbf627ae47ef79","name":"Light brightness","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":380,"wires":[]},{"id":"23049a79b40fe27a","type":"ui_text","z":"61bbf627ae47ef79","group":"d646d4608d936642","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","className":"","x":940,"y":470,"wires":[]},{"id":"544b88e0a5acdbc3","type":"delay","z":"61bbf627ae47ef79","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":400,"y":580,"wires":[["b1457747009dbc0b","48a1be336e584b23"]]},{"id":"08eed27cd045d4d0","type":"inject","z":"61bbf627ae47ef79","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":270,"wires":[["fce5c98a896cee68"]]},{"id":"c5be9bf8e7969338","type":"debug","z":"61bbf627ae47ef79","name":"debug 57","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":540,"y":260,"wires":[]},{"id":"eb74d0ccc1eef85e","type":"switch","z":"61bbf627ae47ef79","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Up","vt":"str"},{"t":"eq","v":"Down","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":480,"wires":[["a938402218c16029","9011504eb312ea1b"],["544b88e0a5acdbc3"]]},{"id":"69ba4d7ee9b81cd5","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":365,"y":520,"wires":[["9011504eb312ea1b"]],"l":false},{"id":"a938402218c16029","type":"change","z":"61bbf627ae47ef79","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":480,"wires":[["544b88e0a5acdbc3"]]},{"id":"48a1be336e584b23","type":"trigger","z":"61bbf627ae47ef79","name":"","op1":"close","op2":"open","op1type":"str","op2type":"str","duration":"3","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":315,"y":520,"wires":[["69ba4d7ee9b81cd5"]],"l":false},{"id":"c6f481318e118641","type":"ui_template","z":"61bbf627ae47ef79","group":"d646d4608d936642","name":"vol -","order":79,"width":1,"height":1,"format":"<div id=\"VolDown\">\n <md-button class=\"md-button TV-HDMI\" aria-label=\"VolDown\">\n <span style=\"color:{{msg.colour}}\" class=\"fa fa-minus remote-icon\"> </span>\n </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n \n$('#VolDown').on('touchstart mousedown', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"VolDown\",\"payload\": \"Down\"});\n});\n\n$('#VolDown').on('touchend mouseup', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"VolDown\",\"payload\": \"Up\"});\n});\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":190,"y":530,"wires":[["248a731374d2e269","eb74d0ccc1eef85e"]]},{"id":"248a731374d2e269","type":"debug","z":"61bbf627ae47ef79","name":"debug 55","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":200,"y":590,"wires":[]},{"id":"d646d4608d936642","type":"ui_group","name":"Group 1","tab":"1f97ed5dea097aaa","order":1,"disp":true,"width":6},{"id":"1f97ed5dea097aaa","type":"ui_tab","name":"Example","icon":"dashboard","order":45,"disabled":false,"hidden":false}]

```

There are some non-standard nodes.  
`node-red-contrib-simple-gate`

Your _BUTTON_ goes where the `template` node is.

 ![Screenshot from 2023-01-18 06-31-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/394da081747e3b27c389281f2ec8cdc018f48c43.png)

The red box, by the way.

The two `inject` nodes:  
The top one is more for resetting. (with 1 cross over it)  
The second one (with 2 crosses) was used for testing.  
But it was replaced by the `template` node because it sends both `up` and `down` messages.

Sorry I didn't explain that better at the start.  
But the flow (as posted) does what you said you wanted.  
So if you look at the GUI side and press the button you would see what you asked for happening.

---

<div class="post-metadata">

**Author:** ![ChrisF](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisF](https://discourse.nodered.org/u/ChrisF)\
**Post date:** [18 January 2023 19:20 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/64 "2023-01-18T19:20:11Z")

</div>

Hello,  
I am making some progress.  
When the button is pressed, these three statuses are set:

 ![Bildschirm­foto 2023-01-18 um 20.06.18](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4a62e4cf73c19be166c66864608d92b903d9a295.png)

However, I do not know exactly what I have to enter at the COUNTER. the Node I had to install first.

The gate is open.

Do the button and the lamp have to be inserted in the Press Count? There I get the Device inserted, but these do not go online. But in the normal node it works.

Furthermore I have always after the deploy an error: Error: , Remote I/O error

 ![Bildschirm­foto 2023-01-18 um 20.14.36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/adaceae1b06cc93ec3025b0b88ee589449b92e70.jpeg)

when i press the button, i let send only the action from button via the setting: payload output. this works: on/off  
but a debug after the lamp always sends:

{"brightness":144,"linkquality":196,"state":"ON","update":{"state":"idle"}}

 ![Bildschirm­foto 2023-01-18 um 20.28.08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ecc19ef6c6f18774c36ef4761a3751ec13501974.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [18 January 2023 19:30 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/65 "2023-01-18T19:30:12Z")

</div>

I need to see what `debug 59` is sending you.

Honestly though that second screen shot: WRONG!  
You should NOT be touching the contents of the `subflow` (`press counter`).

![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d52806a7c9f9226b6cffe95d6edf5712fd14cb4a.jpeg)

This is how you use the flow I posted.

The messages coming from the `Hue Button (what ever)` node should be `Up` and `Down` when the button is pressed and released.

Can you do that?  
If you can't: This whole things is USELESS.  
Ok, slight clarification:  
There needs to be DIFFERENT messages when the button is pressed and released.

---

<div class="post-metadata">

**Author:** ![ChrisF](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisF](https://discourse.nodered.org/u/ChrisF)\
**Post date:** [18 January 2023 19:38 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/66 "2023-01-18T19:38:01Z")

</div>

with a short keystroke always three statuses:

 ![Bildschirm­foto 2023-01-18 um 20.34.59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/62bed605bbc726ba6d0ab0864fd3aaa44f013002.png)

with long keystroke 7x this status and then it changes to:

 ![Bildschirm­foto 2023-01-18 um 20.34.16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96a344cc8fad5b11c75746e3a61d418dfd03aece.png)

"brightness\_step\_up"

---

<div class="post-metadata">

**Author:** ![ChrisF](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisF](https://discourse.nodered.org/u/ChrisF)\
**Post date:** [18 January 2023 19:42 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/67 "2023-01-18T19:42:47Z")

</div>

- 

"The workspace contains some nodes that are not set properly:

[Press count] counter (counter)  
Are you sure that you want to deploy?"

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [18 January 2023 19:45 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/68 "2023-01-18T19:45:43Z")

</div>

This is becoming confusing for me.

You asked

> [@ChrisF](#):
>
> I would like to control it so that:  
> 1x press = light on 20%  
> 2x press = 40%  
> 3x press = 60%  
> 4x press = 80%  
> 5x press = 100%  
> Press 1x long = light off

Now it is declared that the button sends more than two messages.

And those other messages come from....... _somewhere magical_ of which you have not explained.

This has become TOO complicated (for me). I can't no longer help you.

There are too many things happening in the background that are way outside my ability.

the flow - as I posted (three times now from memory) WORKS as given.  
You press the GUI button once, twice, (etc) and the _light brightness_ is set depending on how many times you press it.  
Press/Holding the button for .... I think it is 5 second, turns the _light_ off - with message shown that it is turned off.

Good luck.

---

<div class="post-metadata">

**Author:** ![ChrisF](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ChrisF](https://discourse.nodered.org/u/ChrisF)\
**Post date:** [18 January 2023 20:15 UTC](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560/69 "2023-01-18T20:15:04Z")

</div>

you are right. ☹  
I thank you anyway for your help.  
sorry for the confusion.

[Previous page](https://discourse.nodered.org/t/how-to-detect-multiple-presses-on-a-single-button/20560.md?page=3)
