How to detect multiple presses on a single button

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

1 Like

That code you posted is the subflow.

You shouldn't be changing that part.

This is the flow - again:

[{"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.

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.

1 Like

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

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

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"}}

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

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.

1 Like

with a short keystroke always three statuses:

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

"brightness_step_up"

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

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

This is becoming confusing for me.

You asked

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.

1 Like

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