After even more head banging, it is so close now.
Known bug:
Sometimes when the button is released, it flashes the next one higher on the count.
Use:
Single press/hold sets off #1 flashing.
Click and press/hold sets off #2 flashing
(and so on)
But sometimes when you release the button, you get a click on the next (higher numbered) LED.
Code:
[{"id":"a1614e03.32aa68","type":"inject","z":"a941e919.4a7d88","name":"Reset","topic":"RESET","payload":"Reset","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":910,"y":360,"wires":[["9f5301cc.e8f418"]]},{"id":"9f5301cc.e8f418","type":"change","z":"a941e919.4a7d88","name":"Reset","rules":[{"t":"set","p":"topic","pt":"msg","to":"RESET","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"blah","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":400,"wires":[["c6646b5c.2ef1c8"]]},{"id":"c6646b5c.2ef1c8","type":"function","z":"a941e919.4a7d88","name":"set count","func":"let c = 0;\nif (msg.topic == \"RESET\")\n{\n context.set('count',0);\n node.status('0');\n msg.payload = \"1\";\n msg.topic = \"control\";\n return msg;\n} else\nif (msg.topic == \"down\")\n{\n c = context.get('count') || 0;\n c = c + 1;\n context.set('count',c);\n// msg.payload = c;\n// node.status(c);\n return;\n} else\nif (msg.topic == \"up\")\n{\n //\n c = context.get('count');\n \n //\n // Test line to get all gates closed\n c = c + 1;\n //\n \n msg.payload = String(c);\n msg.topic = \"CONTROL\";\n node.status(c);\n return msg;\n}\n","outputs":1,"noerr":0,"x":1270,"y":400,"wires":[["fcf665dd.ff8278","a56393cb.30da88"]]},{"id":"b7df123f.c8c96","type":"trigger","z":"a941e919.4a7d88","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"300","extend":true,"units":"ms","reset":"","bytopic":"all","name":"Repeat","x":920,"y":440,"wires":[["9f5301cc.e8f418"]]},{"id":"2ac9c835.8f4e48","type":"change","z":"a941e919.4a7d88","name":"Down","rules":[{"t":"set","p":"topic","pt":"msg","to":"down","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":440,"wires":[["c6646b5c.2ef1c8"]]},{"id":"8b7b4eb.6207b3","type":"trigger","z":"a941e919.4a7d88","op1":"","op2":"up","op1type":"nul","op2type":"str","duration":"200","extend":true,"units":"ms","reset":"","bytopic":"all","name":"","x":1250,"y":360,"wires":[["c6646b5c.2ef1c8"]]},{"id":"fcf665dd.ff8278","type":"delay","z":"a941e919.4a7d88","name":"Delay","pauseType":"delay","timeout":"2","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1410,"y":400,"wires":[["596266d5.593608","e53a6bf2.e783a"]]},{"id":"a56393cb.30da88","type":"ui_text","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","order":3,"width":2,"height":1,"name":"Click count","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1500,"y":320,"wires":[]},{"id":"44c1552b.437b1c","type":"trigger","z":"a941e919.4a7d88","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-150","extend":false,"units":"ms","reset":"up","bytopic":"all","name":"Repeat","x":710,"y":500,"wires":[["dca52edc.44544","b7df123f.c8c96"]]},{"id":"28d60a04.2aab4e","type":"switch","z":"a941e919.4a7d88","name":"Up / Down","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"up","vt":"str"},{"t":"eq","v":"down","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":400,"wires":[["7b12565f.296678"],["2ac9c835.8f4e48"]]},{"id":"7b12565f.296678","type":"change","z":"a941e919.4a7d88","name":"Up","rules":[{"t":"set","p":"topic","pt":"msg","to":"up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":360,"wires":[["8b7b4eb.6207b3"]]},{"id":"596266d5.593608","type":"debug","z":"a941e919.4a7d88","name":"Presses.","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1590,"y":400,"wires":[]},{"id":"e53a6bf2.e783a","type":"trigger","z":"a941e919.4a7d88","op1":"close","op2":"","op1type":"str","op2type":"pay","duration":"1","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":1600,"y":440,"wires":[["fff1b459.485bc8"]]},{"id":"dca52edc.44544","type":"fan","z":"a941e919.4a7d88","x":920,"y":710,"wires":[["cc67eb37.2342f8","1b0f3f80.afffa9","d9c86f9c.ad24b8","fdf69d1e.6bc6f"]]},{"id":"71a9f4f0.0d0b94","type":"trigger","z":"a941e919.4a7d88","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Try","x":720,"y":450,"wires":[["44c1552b.437b1c"]]},{"id":"fe868a29.aa1c58","type":"ui_template","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","name":"Button","order":1,"width":5,"height":1,"format":"<button ng-mousedown=\"send({payload: 'down'})\" ng-mouseup=\"send({payload: 'up'})\"><i class=\"material-icons\"> PRESS </i></button>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":720,"y":400,"wires":[["28d60a04.2aab4e","71a9f4f0.0d0b94"]]},{"id":"ecda157e.7598","type":"inject","z":"a941e919.4a7d88","name":"up","topic":"","payload":"up","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":720,"y":350,"wires":[["28d60a04.2aab4e"]]},{"id":"fff1b459.485bc8","type":"function","z":"a941e919.4a7d88","name":"","func":"// This line needs to reflect the number of outputs\nlet output = [null,null,null,null,null];\nif (msg.payload === 'close') {\n // As does this line.\n node.send([msg,msg,msg,msg,msg]);\n} else {\n output[msg.payload - 1] = msg;\n node.send(output);\n}\n","outputs":5,"noerr":0,"x":1620,"y":500,"wires":[["95db009.74a48"],["34d5daad.0eb1de"],["951dfb8a.dcca58"],["7b7a0b6d.29393c"],[]]},{"id":"cc67eb37.2342f8","type":"gate","z":"a941e919.4a7d88","name":"Gate 1","controlTopic":"control","defaultState":"closed","openCmd":"1","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1100,"y":530,"wires":[["7b998928.3599c"]]},{"id":"1b0f3f80.afffa9","type":"gate","z":"a941e919.4a7d88","name":"Gate 2","controlTopic":"control","defaultState":"closed","openCmd":"2","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1100,"y":620,"wires":[["35253efd.a0d7e2"]]},{"id":"d9c86f9c.ad24b8","type":"gate","z":"a941e919.4a7d88","name":"Gate 3","controlTopic":"control","defaultState":"closed","openCmd":"3","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1100,"y":710,"wires":[["36d58e32.58b1fa"]]},{"id":"fdf69d1e.6bc6f","type":"gate","z":"a941e919.4a7d88","name":"Gate 4","controlTopic":"control","defaultState":"closed","openCmd":"4","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1100,"y":800,"wires":[["1dba84b7.3b1623"]]},{"id":"34d5daad.0eb1de","type":"link out","z":"a941e919.4a7d88","name":"","links":["d3a88124.1c1a7","e7178238.5559e8"],"x":1885,"y":480,"wires":[]},{"id":"951dfb8a.dcca58","type":"link out","z":"a941e919.4a7d88","name":"","links":["f212e6f5.f7de6","da8d9615.654ec8"],"x":1885,"y":520,"wires":[]},{"id":"7b7a0b6d.29393c","type":"link out","z":"a941e919.4a7d88","name":"","links":["577ab48d.59899c","51891e3.14f576"],"x":1885,"y":560,"wires":[]},{"id":"95db009.74a48","type":"link out","z":"a941e919.4a7d88","name":"","links":["d3a88124.1c1a7","33f2a475.423eb4"],"x":1885,"y":430,"wires":[]},{"id":"33f2a475.423eb4","type":"link in","z":"a941e919.4a7d88","name":"","links":["95db009.74a48"],"x":1025,"y":490,"wires":[["cc67eb37.2342f8"]]},{"id":"7b998928.3599c","type":"function","z":"a941e919.4a7d88","name":"Pulse","func":"let c = context.get('count') || 0;\nc = c + 1\nc = c % 2;\nnode.status(c);\ncontext.set('count',c);\nmsg.payload = c;\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":530,"wires":[["82bb34e8.144e","c79f0100.78d4e"]]},{"id":"e7178238.5559e8","type":"link in","z":"a941e919.4a7d88","name":"","links":["34d5daad.0eb1de"],"x":1025,"y":590,"wires":[["1b0f3f80.afffa9"]]},{"id":"35253efd.a0d7e2","type":"function","z":"a941e919.4a7d88","name":"Pulse","func":"let c = context.get('count') || 0;\nc = c + 1\nc = c % 2;\nnode.status(c);\ncontext.set('count',c);\nmsg.payload = c;\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":620,"wires":[["488d0f0.53679f","8ced5380.6a4838"]]},{"id":"da8d9615.654ec8","type":"link in","z":"a941e919.4a7d88","name":"","links":["951dfb8a.dcca58"],"x":1025,"y":680,"wires":[["d9c86f9c.ad24b8"]]},{"id":"36d58e32.58b1fa","type":"function","z":"a941e919.4a7d88","name":"Pulse","func":"let c = context.get('count') || 0;\nc = c + 1\nc = c % 2;\nnode.status(c);\ncontext.set('count',c);\nmsg.payload = c;\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":710,"wires":[["4b9629c8.9d672","be31f56f.1b2218"]]},{"id":"51891e3.14f576","type":"link in","z":"a941e919.4a7d88","name":"","links":["7b7a0b6d.29393c"],"x":1025,"y":770,"wires":[["fdf69d1e.6bc6f"]]},{"id":"1dba84b7.3b1623","type":"function","z":"a941e919.4a7d88","name":"Pulse","func":"let c = context.get('count') || 0;\nc = c + 1\nc = c % 2;\nnode.status(c);\ncontext.set('count',c);\nmsg.payload = c;\nreturn msg;","outputs":1,"noerr":0,"x":1240,"y":800,"wires":[["a30d8953.a9def","45ae3ea.e65b0c"]]},{"id":"82bb34e8.144e","type":"ui_led","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","order":4,"width":2,"height":2,"label":"0","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"0","x":1370,"y":570,"wires":[]},{"id":"c79f0100.78d4e","type":"debug","z":"a941e919.4a7d88","name":"0","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1370,"y":530,"wires":[]},{"id":"488d0f0.53679f","type":"debug","z":"a941e919.4a7d88","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1370,"y":620,"wires":[]},{"id":"8ced5380.6a4838","type":"ui_led","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","order":5,"width":2,"height":2,"label":"1","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"1","x":1370,"y":660,"wires":[]},{"id":"4b9629c8.9d672","type":"debug","z":"a941e919.4a7d88","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1370,"y":710,"wires":[]},{"id":"be31f56f.1b2218","type":"ui_led","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","order":6,"width":2,"height":2,"label":"2","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"2","x":1370,"y":750,"wires":[]},{"id":"a30d8953.a9def","type":"debug","z":"a941e919.4a7d88","name":"3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1370,"y":800,"wires":[]},{"id":"45ae3ea.e65b0c","type":"ui_led","z":"a941e919.4a7d88","group":"15a0e304.1a21ad","order":7,"width":2,"height":2,"label":"3","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"3","x":1370,"y":840,"wires":[]},{"id":"15a0e304.1a21ad","type":"ui_group","z":"","name":"Group 1","tab":"e6a111dc.7a3e8","order":1,"disp":true,"width":"9","collapse":false},{"id":"e6a111dc.7a3e8","type":"ui_tab","z":"","name":"WOL Buttons","icon":"dashboard","order":46,"disabled":false,"hidden":false}]