Faster way to get single click / double clicks?

I currently have this:

where function node is:

if (msg.payload.length == 1){
    return [msg, null];
}else{
    return [null, msg];
}

and the loin joins in array.

[{"id":"14fe5df7b273b2be","type":"join","z":"a787a77.9c16458","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":290,"y":840,"wires":[["4b03e6dd16fe4c62"]]},{"id":"4b03e6dd16fe4c62","type":"function","z":"a787a77.9c16458","name":"","func":"if (msg.payload.length == 1){\n    return [msg, null];\n}else{\n    return [null, msg];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":840,"wires":[["e3cccd4158d914d9"],["d2fcd6e1a6abc0ec"]]},{"id":"e3cccd4158d914d9","type":"api-call-service","z":"a787a77.9c16458","name":"Hallen on","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.hallen","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":800,"wires":[[]]},{"id":"d2fcd6e1a6abc0ec","type":"api-call-service","z":"a787a77.9c16458","name":"Köket on","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kokslampa","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":860,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

But it feels unresponsive. You click and it feels like something is wrong and then the light goes on.
Is there any way to get the click /double click faster to make it not feel sluggish.
It’s the join timeout that makes it feel slow. Anyone has a different solution?

It’s not too beautiful but it should work

you’ll need: node-red-contrib-stoptimer-varidelay : stoptimer-varidelay

[{"id":"f253a18d.d5879","type":"stoptimer-varidelay","z":"ebd7f2e4.a2afc","duration":"1","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","reporting":"none","persist":true,"x":620,"y":880,"wires":[["4c71e1f8.df367"],["d24f394c.e71248","17019563.99a0cb"],[]]},{"id":"c19c0204.dfaca","type":"counter","z":"ebd7f2e4.a2afc","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":340,"y":880,"wires":[["e46c02c4.cea9c"]]},{"id":"24d7a857.803498","type":"debug","z":"ebd7f2e4.a2afc","name":"2 clicks","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":900,"wires":[]},{"id":"4c71e1f8.df367","type":"debug","z":"ebd7f2e4.a2afc","name":"1 click","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":860,"wires":[]},{"id":"e46c02c4.cea9c","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"count","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":435,"y":880,"wires":[["efb22bb8.a009c8"]],"l":false},{"id":"efb22bb8.a009c8","type":"change","z":"ebd7f2e4.a2afc","name":"","rules":[{"t":"change","p":"count","pt":"msg","from":"2","fromt":"num","to":"stop","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":495,"y":880,"wires":[["f253a18d.d5879"]],"l":false},{"id":"d24f394c.e71248","type":"change","z":"ebd7f2e4.a2afc","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":960,"wires":[["c19c0204.dfaca"]]},{"id":"c3086a1d.f0a7f8","type":"inject","z":"ebd7f2e4.a2afc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":880,"wires":[["c19c0204.dfaca"]]},{"id":"17019563.99a0cb","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":795,"y":900,"wires":[["24d7a857.803498"]],"l":false}]

Thank you for the suggestion.
I tried it with the inject since I’m currently at work, but it seems to be based on the same think, a fixed delay.
I will test it live when I get home.
It feels about the same, which seems correct since they both have one second timer (I could set it lower but it also makes it harder to double click). And that is what I don’t like.

alternative without varidelay, trigger instead. Looks prettier.

[{"id":"c19c0204.dfaca","type":"counter","z":"ebd7f2e4.a2afc","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":340,"y":880,"wires":[["e46c02c4.cea9c"]]},{"id":"24d7a857.803498","type":"debug","z":"ebd7f2e4.a2afc","name":"2 clicks","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":900,"wires":[]},{"id":"4c71e1f8.df367","type":"debug","z":"ebd7f2e4.a2afc","name":"1 click","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":860,"wires":[]},{"id":"e46c02c4.cea9c","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"count","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":435,"y":880,"wires":[["efb22bb8.a009c8"]],"l":false},{"id":"efb22bb8.a009c8","type":"change","z":"ebd7f2e4.a2afc","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"count","tot":"msg"},{"t":"change","p":"delay","pt":"msg","from":"1","fromt":"num","to":"1000","tot":"num"},{"t":"change","p":"delay","pt":"msg","from":"2","fromt":"num","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":495,"y":880,"wires":[["c780511d.58faf"]],"l":false},{"id":"d24f394c.e71248","type":"change","z":"ebd7f2e4.a2afc","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":960,"wires":[["c19c0204.dfaca"]]},{"id":"c3086a1d.f0a7f8","type":"inject","z":"ebd7f2e4.a2afc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":880,"wires":[["c19c0204.dfaca"]]},{"id":"c780511d.58faf","type":"trigger","z":"ebd7f2e4.a2afc","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":590,"y":880,"wires":[["56943a47.b5cca4","d24f394c.e71248"]]},{"id":"56943a47.b5cca4","type":"switch","z":"ebd7f2e4.a2afc","name":"clicks","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":740,"y":880,"wires":[["4c71e1f8.df367"],["24d7a857.803498"]]}]

EDIT

if you want to change the 1 second delay, you should do it whithin the change node, second rule. Probably 750 ms would suffice.

2 Likes