Can anybody share a node-red example double click of Ikea on/off switch?

Hi,
I’m a good replicator but a rather, sadly, bad coder :wink:
Would anyone care to share a flow where an ikea on/off triggers on double, triple clicks?

[{"id":"6a62443f.952e1c","type":"inject","z":"234ef87d.c665b8","name":"Fake Single Click ","props":[{"p":"payload.buttonevent","v":"1002","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":1760,"wires":[["b438d0e1.26708"]]},{"id":"b438d0e1.26708","type":"switch","z":"234ef87d.c665b8","name":"Ikea on/off","property":"payload.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2002","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":330,"y":1760,"wires":[["13d3a120.5f5aef"],[],[],[],[],[]],"outputLabels":["Single ON","Long ON","Long ON Release","Single OFF","Long OFF","Long OFF Release"]},{"id":"13d3a120.5f5aef","type":"function","z":"234ef87d.c665b8","name":"Missing Magic to Count","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":1700,"wires":[["e138aba1.7113d8"]]},{"id":"e138aba1.7113d8","type":"switch","z":"234ef87d.c665b8","name":"Clicks","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"double","vt":"str"},{"t":"eq","v":"triple","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":650,"y":1760,"wires":[["697073f3.c8e99c"],["45c800b7.e0ba"],["8d1547ef.273dd8"]]},{"id":"697073f3.c8e99c","type":"debug","z":"234ef87d.c665b8","name":"1 click","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":1720,"wires":[]},{"id":"45c800b7.e0ba","type":"debug","z":"234ef87d.c665b8","name":"2 clicks","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1760,"wires":[]},{"id":"8d1547ef.273dd8","type":"debug","z":"234ef87d.c665b8","name":"3 clicks","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1800,"wires":[]}]

[{"id":"6a80080f.ee7458","type":"inject","z":"f61766ce.f85398","name":"1 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":146,"y":336,"wires":[["9e21c370.12b35"]]},{"id":"40e12daf.0c5cc4","type":"calculate","z":"f61766ce.f85398","name":"","pauseType":"timed","calculation":"max","timeout":"3","timeoutUnits":"seconds","rate":"10","x":508,"y":384,"wires":[["bb864295.fd23f"]]},{"id":"9e21c370.12b35","type":"function","z":"f61766ce.f85398","name":"Simulate Clicks","func":"const arr = Array.from(Array(msg.payload), _ => msg);\nreturn [arr];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":384,"wires":[["40e12daf.0c5cc4"]]},{"id":"4da84815.786b68","type":"inject","z":"f61766ce.f85398","name":"2 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":146,"y":368,"wires":[["9e21c370.12b35"]]},{"id":"7baef360.d13b4c","type":"inject","z":"f61766ce.f85398","name":"3 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":146,"y":400,"wires":[["9e21c370.12b35"]]},{"id":"87eb6ade.97d218","type":"inject","z":"f61766ce.f85398","name":"4 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":146,"y":432,"wires":[["9e21c370.12b35"]]},{"id":"d98ac1b4.56148","type":"debug","z":"f61766ce.f85398","name":"Turn on some light","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":352,"wires":[]},{"id":"bb864295.fd23f","type":"switch","z":"f61766ce.f85398","name":"msg.points","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":678,"y":384,"wires":[["d98ac1b4.56148"],["f69dbd9.edff54"],["f0eeefca.b2a74"]]},{"id":"f69dbd9.edff54","type":"debug","z":"f61766ce.f85398","name":"change light to scene1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":384,"wires":[]},{"id":"f0eeefca.b2a74","type":"debug","z":"f61766ce.f85398","name":"change light to scene2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":416,"wires":[]},{"id":"c7851a24.5197e8","type":"timed-counter","z":"f61766ce.f85398","name":"","timelimit":"3","timeunit":"1000","withhold":true,"fixedtimeout":false,"pertopic":false,"x":528,"y":336,"wires":[[]]}]

[{"id":"6665cf22.1b048","type":"inject","z":"f61766ce.f85398","name":"1 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":178,"y":512,"wires":[["d5499fe0.9381a"]]},{"id":"d5499fe0.9381a","type":"function","z":"f61766ce.f85398","name":"Simulate Clicks","func":"const arr = Array.from(Array(msg.payload), _ => msg);\nreturn [arr];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":352,"y":560,"wires":[["26620cee.84a134"]]},{"id":"546eed85.29ce74","type":"inject","z":"f61766ce.f85398","name":"2 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":178,"y":544,"wires":[["d5499fe0.9381a"]]},{"id":"f19aace1.89a15","type":"inject","z":"f61766ce.f85398","name":"3 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":178,"y":576,"wires":[["d5499fe0.9381a"]]},{"id":"8fdf6e54.c71c7","type":"inject","z":"f61766ce.f85398","name":"4 click","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"4","payloadType":"num","x":178,"y":608,"wires":[["d5499fe0.9381a"]]},{"id":"3fe3de84.0c6282","type":"debug","z":"f61766ce.f85398","name":"Turn on some light","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":842,"y":528,"wires":[]},{"id":"89ac3c73.97fd2","type":"switch","z":"f61766ce.f85398","name":"count?","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":658,"y":560,"wires":[["3fe3de84.0c6282"],["f1bc748f.f5de78"],["a10bd1b2.963f2"]]},{"id":"f1bc748f.f5de78","type":"debug","z":"f61766ce.f85398","name":"change light to scene1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":852,"y":560,"wires":[]},{"id":"a10bd1b2.963f2","type":"debug","z":"f61766ce.f85398","name":"change light to scene2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":852,"y":592,"wires":[]},{"id":"26620cee.84a134","type":"function","z":"f61766ce.f85398","name":"","func":"const timeout = 3000;\nlet count = context.get(\"count\") || 0;\nif(count === 0) {\n    setTimeout(() => {\n        node.status({});\n        msg.count = context.get(\"count\") || 0;\n        context.set(\"count\", 0);\n        node.send(msg);\n    }, timeout);\n}\ncontext.set(\"count\", ++count);\nnode.status({text: count});","outputs":1,"noerr":0,"initialize":"","finalize":"","x":524,"y":560,"wires":[["89ac3c73.97fd2"]]}]
4 Likes

THANKS!
The last one worked for me “out of the box” - I was curious about the timed-counter but it kept shooting multiple messages - as if I needed to debounce it.
My flow with deconz event and lights etc:

[{"id":"c8c295e8.317cd8","type":"deconz-input","z":"234ef87d.c665b8","name":"Bed Button","server":"84275c62.5cd71","device":"68:0a:e2:ff:fe:78:98:b0-01-1000","device_name":"Lloyd Bed Button : ZHASwitch","topic":"","state":"0","output":"always","outputAtStartup":false,"x":80,"y":1620,"wires":[["d9eca467.a3e9e8"],[]]},{"id":"654c6319.6b847c","type":"comment","z":"234ef87d.c665b8","name":"Ikea command switch","info":"1001 long click on\n1002 single click on \n1003 release after long click on\n2001 lon click off\n2002 songle click off\n2003 release after long click off","x":120,"y":1540,"wires":[]},{"id":"d9eca467.a3e9e8","type":"switch","z":"234ef87d.c665b8","name":"Ikea on/off codes","property":"payload.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"num"},{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2002","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":270,"y":1640,"wires":[["42b84d19.a561d4"],["e743f9b6.03a3a8"],[],["58e1441d.24581c"],["60b093b7.86971c"],[]],"outputLabels":["Single ON","Long ON","Long ON Release","Single OFF","Long OFF","Long OFF Release"]},{"id":"42b84d19.a561d4","type":"api-current-state","z":"234ef87d.c665b8","name":"stone lamp","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.stone_lamp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":470,"y":1580,"wires":[["62e6be3.93c374"],["58e1441d.24581c"]]},{"id":"58e1441d.24581c","type":"api-call-service","z":"234ef87d.c665b8","name":"sleepin OFF","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.sleeping_room","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":1660,"wires":[[]]},{"id":"9512a6c.e3c1058","type":"api-call-service","z":"234ef87d.c665b8","name":"Stone ON","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.stone_lamp","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":1540,"wires":[[]]},{"id":"e743f9b6.03a3a8","type":"api-current-state","z":"234ef87d.c665b8","name":"fluffy","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.fluffy","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":450,"y":1620,"wires":[["8b876183.2c50c"],["58e1441d.24581c"]]},{"id":"8b876183.2c50c","type":"api-call-service","z":"234ef87d.c665b8","name":"sleepin ON","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sleeping_room","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":1620,"wires":[[]]},{"id":"60b093b7.86971c","type":"api-call-service","z":"234ef87d.c665b8","name":"Curved L Toggle","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.curvedlamp","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":520,"y":1700,"wires":[[]]},{"id":"62e6be3.93c374","type":"function","z":"234ef87d.c665b8","name":"Awway","func":"const arr = Array.from(Array(msg.payload), _ => msg);\nreturn [arr];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":1540,"wires":[["87dff53a.b214f8"]]},{"id":"87dff53a.b214f8","type":"function","z":"234ef87d.c665b8","name":"Count","func":"const timeout = 2000;\nlet count = context.get(\"count\") || 0;\nif(count === 0) {\n    setTimeout(() => {\n        node.status({});\n        msg.count = context.get(\"count\") || 0;\n        context.set(\"count\", 0);\n        node.send(msg);\n    }, timeout);\n}\ncontext.set(\"count\", ++count);\nnode.status({text: count});","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":1580,"wires":[["a1006242.42782"]]},{"id":"a1006242.42782","type":"switch","z":"234ef87d.c665b8","name":"Dispatch","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":840,"y":1560,"wires":[["9512a6c.e3c1058"],["70f08c9f.293be4"],["eeedff0a.ec052"]]},{"id":"70f08c9f.293be4","type":"api-call-service","z":"234ef87d.c665b8","name":"sleepin ON (Dim)","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sleeping_room","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":1600,"wires":[[]]},{"id":"eeedff0a.ec052","type":"api-call-service","z":"234ef87d.c665b8","name":"sleepin ON (bright)","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sleeping_room","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":1660,"wires":[[]]},{"id":"84275c62.5cd71","type":"deconz-server","name":"deoconz","ip":"192.168.86.67","port":"40850","apikey":"80F80F1CD0","ws_port":"8081","secure":false,"polling":"15"},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]