How to detect multiple presses on a single button

Recently I got back to this thread and learned about your improvements. So now I took the time to update my solution specialized for Shelly devices. With @BartButenaers node it is now much cleaner. Thank you for your great work.
@BartButenaers – One thing I miss a little and this is a “trippe_clicked” output. I guess that would be a easy extension of that node.

Here is my solution

[
    {
        "id": "a85fa439244b9676",
        "type": "button-events",
        "z": "811f7114.3750e",
        "name": "",
        "outputs": 4,
        "inputField": "payload",
        "inputFieldType": "msg",
        "outputField": "payload",
        "outputFieldType": "msg",
        "downValue": "1",
        "downValueType": "str",
        "upValue": "0",
        "upValueType": "str",
        "idleValue": "1",
        "clickedInterval": "500",
        "pressedInterval": "500",
        "debounceInterval": "0",
        "events": [
            {
                "type": "clicked"
            },
            {
                "type": "double_clicked"
            },
            {
                "type": "pressed"
            },
            {
                "type": "released"
            }
        ],
        "x": 460,
        "y": 1980,
        "wires": [
            [
                "e23c379d3ec280dd"
            ],
            [
                "e23c379d3ec280dd"
            ],
            [
                "cdf19b51c3385ad9"
            ],
            [
                "cdf19b51c3385ad9"
            ]
        ]
    },
    {
        "id": "cdf19b51c3385ad9",
        "type": "one-button-dimmer",
        "z": "811f7114.3750e",
        "name": "",
        "interval": "150",
        "step": "3",
        "minValue": "5",
        "maxValue": "100",
        "startCommand": "pressed",
        "stopCommand": "released",
        "x": 720,
        "y": 2020,
        "wires": [
            [
                "e23c379d3ec280dd"
            ]
        ]
    },
    {
        "id": "e23c379d3ec280dd",
        "type": "function",
        "z": "811f7114.3750e",
        "name": "click action",
        "func": "const out_ceilingLight = \"shellies/shelly1pm-C44728/relay/0/command\";\nconst out_vintageLight = \"shellies/ShellyVintage-6EE939/light/0/set\";\n\n// click action\nswitch(msg.payload)\n{\n\n    case \"clicked\": // single click action\n        node.send({topic: out_ceilingLight, payload: {\"turn\": \"toggle\"}});\n        break;\n    \n    case \"double_clicked\": // double click action\n        node.send({topic: out_vintageLight, payload: {\"turn\": \"toggle\"}});\n        break;\n    \n    case \"tripple_clicked\": // three clicks action\n        // right now not possible with Button events\n        break;\n    \n    default: // number -> dimming\n        node.send({topic: out_vintageLight, payload: {\"brightness\": msg.payload ,\"turn\": \"on\"}});\n\n        break;\n}\n\n\nnode.status({text: msg.payload});",
        "outputs": 1,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is deployed.\nconst dimmingTopic = \"dimming\";\ncontext.set(dimmingTopic, 200); ",
        "finalize": "",
        "libs": [],
        "x": 1010,
        "y": 1980,
        "wires": [
            [
                "7cba755bbd268e7e"
            ]
        ]
    },
    {
        "id": "7cba755bbd268e7e",
        "type": "mqtt out",
        "z": "811f7114.3750e",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "23a96fe8.c5ef",
        "x": 1190,
        "y": 1980,
        "wires": []
    },
    {
        "id": "5de9bb49e3bf8824",
        "type": "mqtt in",
        "z": "811f7114.3750e",
        "name": "Taster Kinderzimmer",
        "topic": "shellies/shelly1pm-C44728/input/0",
        "qos": "2",
        "datatype": "auto",
        "broker": "23a96fe8.c5ef",
        "nl": false,
        "rap": false,
        "inputs": 0,
        "x": 150,
        "y": 1980,
        "wires": [
            [
                "a85fa439244b9676"
            ]
        ]
    },
    {
        "id": "23a96fe8.c5ef",
        "type": "mqtt-broker",
        "name": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]


Hi @tsknightstorm,
It is quite the opposite. My node is based on the https://www.npmjs.com/package/button-events which doesn't support tripple clicks. If you want, you can ask the author whether he wants to add it to his library. Afterwards I can implement it into my node.
Bart

V1.1.0 of button-events is out that supports now tripple and quadruppe click events. Would it be possible for you to update also your node? In my oppinion this is the perfect solution for button clicks in Node Red.

Hi @tsknightstorm,

I assume that Bryan has added this feature on your request? But I don't see your question somewher in his Github repo... Anyway thanks a lot for making this node better!!!

I have quickly added the new features to my node, so it now should support tripple and quadrupple clicks. Here is my test flow:

[{"id":"e94468b6.358e18","type":"debug","z":"fbee74db83781e91","name":"Clicked","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1420,"y":2240,"wires":[]},{"id":"4bc6d6f0.115498","type":"inject","z":"fbee74db83781e91","name":"Inject 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ZERO","payload":"0","payloadType":"num","x":810,"y":2360,"wires":[["ecd423af.746cd"]]},{"id":"c6658632.447978","type":"button-events","z":"fbee74db83781e91","name":"","outputs":5,"inputField":"payload","inputFieldType":"msg","outputField":"payload","outputFieldType":"msg","downValue":"0","downValueType":"num","upValue":"1","upValueType":"num","idleValue":"1","clickedInterval":"2000","pressedInterval":"5000","debounceInterval":"200","events":[{"type":"clicked"},{"type":"pressed"},{"type":"double_clicked"},{"type":"triple_clicked"},{"type":"quadruple_clicked"}],"x":1180,"y":2320,"wires":[["e94468b6.358e18"],["625d6be5.811694"],["b0bd0d59.bc7cf"],["b6d3f93f86c1d86d"],["12b7543be70d8565"]]},{"id":"9130e7a8.87df08","type":"inject","z":"fbee74db83781e91","name":"Inject 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ONE","payload":"1","payloadType":"num","x":810,"y":2420,"wires":[["ecd423af.746cd"]]},{"id":"3ac673fa.12ef9c","type":"ui_chart","z":"fbee74db83781e91","name":"Poor man oscilloscope","group":"27b65cf1.24c8e4","order":3,"width":0,"height":0,"label":"Poor man oscilloscope","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":false,"ymin":"0","ymax":"2","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":1200,"y":2420,"wires":[[]]},{"id":"ecd423af.746cd","type":"switch","z":"fbee74db83781e91","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"2","vt":"num"},{"t":"lt","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":990,"y":2360,"wires":[["c6658632.447978"],["3ac673fa.12ef9c"]]},{"id":"b0bd0d59.bc7cf","type":"debug","z":"fbee74db83781e91","name":"Double clicked","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1440,"y":2320,"wires":[]},{"id":"625d6be5.811694","type":"debug","z":"fbee74db83781e91","name":"Pressed","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1420,"y":2280,"wires":[]},{"id":"b6d3f93f86c1d86d","type":"debug","z":"fbee74db83781e91","name":"Triple clicked","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1430,"y":2360,"wires":[]},{"id":"12b7543be70d8565","type":"debug","z":"fbee74db83781e91","name":"Quadruple clicked","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":2400,"wires":[]},{"id":"a5609c591f687241","type":"trigger","z":"fbee74db83781e91","name":"","op1":"0","op2":"1","op1type":"str","op2type":"str","duration":"250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":960,"y":2260,"wires":[["c6658632.447978"]]},{"id":"b282ad502bae2e6d","type":"inject","z":"fbee74db83781e91","name":"Create pulse","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":750,"y":2260,"wires":[["a5609c591f687241"]]},{"id":"27b65cf1.24c8e4","type":"ui_group","name":"HLS demo","tab":"787ed714.674938","order":1,"disp":true,"width":"12","collapse":false},{"id":"787ed714.674938","type":"ui_tab","name":"Code","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I have not tested this very deeply, so I would appreciate if you could do some more tests, and review the readme page (see triple_and_double_clicks branch on Github) and the information on the node's info panel...

This version is not available on npm yet, but you can install it directly from my Github repo (when you have git installed) from within your .node-red folder:

npm install bartbutenaers/node-red-contrib-button-events#triple_and_double_clicks

BTW I find it difficult to adjust the different timings of this node, to get it correct for real physical button clicks. Therefore at the time being I have asked Bryan (see here) whether he could add a feature for this. If you have ever ideas about this, I would appreciate a lot if you could discuss this with Bryan. I think this would make this node much more useful. But unfortunately I don't have time to do this all on my own...

Thanks!!
Bart

Any idea when this will be published ? Its actually difficult to install npm's directly when using the node-red add-on in Home Assistant, so a proper npm release would be great

Which one?

If it is the one from @bart the command is shown:
npm install bartbutenaers/node-red-contrib-button-events#triple_and_double_clicks

Nope! Bart has already said in his previous post that he has not yet published the recent changes to npm yet, and it can only be installed direct from Bart's repo.
You are unable to install the recent update direct from npm or node-RED's manage palette, which the OP has requested

Oh, sorry... I am way out of the conversation and probably should have not replied.

But I got a notification and read it as I saw it.

1 Like

Been there, done that :laughing:

@johntdyer,
I need to finish some parts, together with @tsknightstorm. But she has a very busy personal life at the moment. So I assume somewhere in august, as soon as we both have time.
Bart

Bart has now published a beta release. If someone is happy to help testing, we would appreciate it.

3 Likes

Hello all,
I also looking for a solution to dim my light in CamperVan.
I have connected to a Raspberry Pi with your Sonoff Zigbee dongle and a philips hue button via Zigbee2Mqtt learned.
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

for alternatives I am of course open (for example keep switch pressed etc.)

Finally the whole thing has to be sent via MQTT to a Wemos D2 mini. The dimming is then done via a Mosfet.

Is this feasible and can someone help me here or send a flow that I can adapt.

That shouldn't be too hard to do.
My node would go most of the way to doing what you want.

You may need to declare what the messages need to be though.

If/when I get time I could make a demo version though.

Hello,
thank you for your fast answer.
The system itself already exists.
Currently it works so that everything is controlled via a touchscreen.
I would "only" have to integrate the Zigbee button into the system.

You haven't told me what the messages need to be.

Does the Zigbee send both an up and down message when the button is pressed?
If it doesn't it will be hard to detect a long press.

Here is a NEARLY WORKING example.

[{"id":"4be6db179f2af0b9","type":"subflow","name":"Press count","info":"Used to count button presses and send the number in a message.\nSet the *timeout* value in the `delay` variable.\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":330,"wires":[{"id":"a457eafcdad07d0b"}]}],"out":[{"x":820,"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":820,"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":280,"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":300,"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":500,"y":250,"wires":[["d5314c210f7d9a76"]]},{"id":"d5314c210f7d9a76","type":"counter","z":"4be6db179f2af0b9","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":460,"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":670,"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":145,"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":415,"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":460,"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":650,"y":330,"wires":[[]]},{"id":"900476fafffa3ae3","type":"status","z":"4be6db179f2af0b9","name":"","scope":["bb0e17c295353204"],"x":670,"y":370,"wires":[[]]},{"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":"Wipe","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"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":"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":420,"wires":[["2408dde860e38d1e","a938402218c16029"],["544b88e0a5acdbc3"]]},{"id":"fce5c98a896cee68","type":"change","z":"61bbf627ae47ef79","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":320,"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":"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":470,"wires":[["248a731374d2e269","eb74d0ccc1eef85e"]]},{"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":420,"wires":[["544b88e0a5acdbc3"]]},{"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":540,"y":560,"wires":[["b1457747009dbc0b"]]},{"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":320,"wires":[["fce5c98a896cee68"]]},{"id":"b1457747009dbc0b","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":560,"wires":[["23049a79b40fe27a"]]},{"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":530,"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}]

You just need to work out how to negate the message that turns the light back on to 20% after it is turned off.

FULLY WORKING version.

You have to hold the button for 3 seconds to turn the light OFF

[{"id":"4be6db179f2af0b9","type":"subflow","name":"Press count","info":"Used to count button presses and send the number in a message.\nSet the *timeout* value in the `delay` variable.\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":330,"wires":[{"id":"a457eafcdad07d0b"},{"id":"df8cb339f3aed3ba"}]}],"out":[{"x":820,"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":820,"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":300,"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":320,"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":510,"y":250,"wires":[["d5314c210f7d9a76"]]},{"id":"d5314c210f7d9a76","type":"counter","z":"4be6db179f2af0b9","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":470,"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":670,"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":145,"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":425,"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":470,"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":650,"y":330,"wires":[[]]},{"id":"900476fafffa3ae3","type":"status","z":"4be6db179f2af0b9","name":"","scope":["bb0e17c295353204"],"x":670,"y":370,"wires":[[]]},{"id":"df8cb339f3aed3ba","type":"switch","z":"4be6db179f2af0b9","name":"","property":"reset","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":180,"y":210,"wires":[["397e91b8f88a8919"]]},{"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":310,"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":"Wipe","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"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":"fce5c98a896cee68","type":"change","z":"61bbf627ae47ef79","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":270,"wires":[["2408dde860e38d1e"]]},{"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":"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":"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":505,"y":500,"wires":[["9011504eb312ea1b"]],"l":false},{"id":"b1457747009dbc0b","type":"change","z":"61bbf627ae47ef79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":560,"wires":[["23049a79b40fe27a"]]},{"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":"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":"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":540,"y":560,"wires":[["b1457747009dbc0b","48a1be336e584b23"]]},{"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":455,"y":500,"wires":[["69ba4d7ee9b81cd5"]],"l":false},{"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}]

puuh this heavy :slight_smile:

I have imported the two flows.
and inserted the hue button.

I have many errors and am a bit overloaded

First identify which node is sending those msgs. If you click on the digits after node: in the debug, it will flash the node that sent that meg.

From the text of the message, the msg.payload needs to be a nuvmber so add a debug node to the output of the node feeding the node that spews out the debug and look to see what it contains. It could be you are sending a string that contains a number.