Long press before release

Hi all,

I am making a coffee grinder that has a short press to turn the grinder on and a long press on the same gpio button that will start a 4min timer.

How do I make the flow with the desired logic? It is important that the code flows on once the internal long press timer (eg. 1 sec) has been reached an not when the button itself is released.

I have included some flow code but it needs the logic part.

Boiled down the logic is something like this

If button has been pressed down for more than 1 second then go immediately to output 1 (long press)
If button has been released within 1 second then go to output 2 (short press)

Thanks
Mathias

[{"id":"abecf103.a2149","type":"rpi-gpio in","z":"670f6ab3.f74a04","name":"","pin":"12","intype":"up","debounce":"25","read":false,"x":120,"y":220,"wires":[["31c3e88.b99fa18"]]},{"id":"632828bc.b82138","type":"rpi-gpio out","z":"670f6ab3.f74a04","name":"","pin":"13","set":true,"level":"0","freq":"","out":"out","x":560,"y":180,"wires":[]},{"id":"18694305.67c49d","type":"rpi-gpio out","z":"670f6ab3.f74a04","name":"","pin":"16","set":true,"level":"0","freq":"","out":"out","x":560,"y":260,"wires":[]},{"id":"31c3e88.b99fa18","type":"switch","z":"670f6ab3.f74a04","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"","vt":"str"},{"t":"eq","v":"","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":220,"wires":[["632828bc.b82138"],["18694305.67c49d"]]},{"id":"2e27f540.45fcda","type":"comment","z":"670f6ab3.f74a04","name":"Desired logic","info":"If button has been pressed down for more than 1 second then go imediately to output 1 (long press)\n\nIf button has been released within 1 second then go to ouput 2 (short press)","x":410,"y":140,"wires":[]},{"id":"ab3e274e.c68dd8","type":"inject","z":"670f6ab3.f74a04","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":150,"y":360,"wires":[["31c3e88.b99fa18"]]},{"id":"b3c32bd8.1489c8","type":"inject","z":"670f6ab3.f74a04","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":400,"wires":[["31c3e88.b99fa18"]]},{"id":"72a22fcc.90af5","type":"comment","z":"670f6ab3.f74a04","name":"Simulated gpio press","info":"","x":120,"y":320,"wires":[]},{"id":"55081202.311eac","type":"comment","z":"670f6ab3.f74a04","name":"Relay 2","info":"","x":610,"y":140,"wires":[]},{"id":"7789d5d0.ac47fc","type":"comment","z":"670f6ab3.f74a04","name":"Relay 2","info":"","x":610,"y":220,"wires":[]}]

Try this...

[{"id":"ac6a38fc.7a4058","type":"inject","z":"c7164579.39cd78","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":500,"y":440,"wires":[["ec332bcd.dfd158"]]},{"id":"2194e923.160d16","type":"inject","z":"c7164579.39cd78","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":500,"y":480,"wires":[["6dc67dc0.8cf714"]]},{"id":"898d8409.5c98b8","type":"comment","z":"c7164579.39cd78","name":"Simulated gpio press","info":"","x":480,"y":400,"wires":[]},{"id":"b095250c.05cf58","type":"debug","z":"c7164579.39cd78","name":"RELAY 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":420,"wires":[]},{"id":"80b1513c.55d07","type":"debug","z":"c7164579.39cd78","name":"RELAY 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":500,"wires":[]},{"id":"ec332bcd.dfd158","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"release","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["5ea211ee.03b66"]]},{"id":"6dc67dc0.8cf714","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":480,"wires":[["5ea211ee.03b66"]]},{"id":"5ea211ee.03b66","type":"join","z":"c7164579.39cd78","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":860,"y":460,"wires":[["37bf1b69.577f44"]]},{"id":"37bf1b69.577f44","type":"function","z":"c7164579.39cd78","name":"","func":"if(msg.payload.press < msg.payload.release) {\n    //good, release came after press :)\n    var diff = msg.payload.release - msg.payload.press;\n    \n    //output 1: when button press between 0 ~ 1 sec\n    //output 2: when button press between 1 ~ 3 sec\n    \n    if(diff > 0 && diff <= 1000) {\n        return [msg, null]; //fire output 2\n    } else if (diff > 1000 && diff <= 3000) {\n        return [null, msg]; //fire output 2\n    } \n    \n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1020,"y":460,"wires":[["b095250c.05cf58"],["80b1513c.55d07"]]},{"id":"c7e137eb.864838","type":"comment","z":"c7164579.39cd78","name":"Set payload to timestamp","info":"","x":690,"y":520,"wires":[]},{"id":"41ca66db.6b8c08","type":"comment","z":"c7164579.39cd78","name":"join them into one object","info":"","x":850,"y":400,"wires":[]},{"id":"73e95d73.dcca04","type":"comment","z":"c7164579.39cd78","name":"compare time stamps","info":"","x":1020,"y":520,"wires":[]}]

Hi Steve,

Thanks. I tried it and hooked it up to my pin12 but it doesn't seem to fire the long press output while I am still holding the button pressed in. In your simulated gpio press this equates to sending the 0 and then I need to trigger the Relay 2 once 1 second has passed (ignoring the button release (1) on afterwards).

Hope this makes sense.

Try this instead...

[{"id":"ac6a38fc.7a4058","type":"inject","z":"c7164579.39cd78","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":500,"y":440,"wires":[["ec332bcd.dfd158","261c6466.a5a16c"]]},{"id":"2194e923.160d16","type":"inject","z":"c7164579.39cd78","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":500,"y":480,"wires":[["6dc67dc0.8cf714"]]},{"id":"898d8409.5c98b8","type":"comment","z":"c7164579.39cd78","name":"Simulated gpio press","info":"","x":460,"y":400,"wires":[]},{"id":"b095250c.05cf58","type":"debug","z":"c7164579.39cd78","name":"Short Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":400,"wires":[]},{"id":"80b1513c.55d07","type":"debug","z":"c7164579.39cd78","name":"Long Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":480,"wires":[]},{"id":"ec332bcd.dfd158","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"release","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["5ea211ee.03b66"]]},{"id":"6dc67dc0.8cf714","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":480,"wires":[["5ea211ee.03b66","37b95f96.2a217"]]},{"id":"5ea211ee.03b66","type":"join","z":"c7164579.39cd78","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":910,"y":400,"wires":[["37bf1b69.577f44"]]},{"id":"37bf1b69.577f44","type":"function","z":"c7164579.39cd78","name":"","func":"if(msg.payload.press < msg.payload.release) {\n    //good, release came after press :)\n    var diff = msg.payload.release - msg.payload.press;\n    \n    //when button press between 0 ~ 1 sec\n\n    if(diff > 0 && diff <= 1000) {\n        msg.payload = true\n        msg.topic = \"short-press\"\n        return msg; //fire output 1\n    } \n    \n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1060,"y":400,"wires":[["b095250c.05cf58"]]},{"id":"37b95f96.2a217","type":"delay","z":"c7164579.39cd78","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":920,"y":480,"wires":[["2136c7d.ed6bf38"]]},{"id":"261c6466.a5a16c","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":400,"wires":[["37b95f96.2a217"]]},{"id":"2136c7d.ed6bf38","type":"change","z":"c7164579.39cd78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"long-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":480,"wires":[["80b1513c.55d07"]]}]

Brilliant. Thanks.

I am just seeing if I can come up with a neater solution. Which way up is your button? Normally you would have a pullup so 0 is pressed and 1 is released.

Well spotted - it is as you describe. 0 on press 1 on release. (which means that in Steve's code I need to reverse the 0-1 before it enters his flow)

Here is another implementation, I don't know whether it is an improvement. It avoids using a function node though, which is generally worth doing if the same functionality can be done easily with standard nodes. It does use node-red-contrib-simple-gate though.

[{"id":"c1c5c340.d39768","type":"inject","z":"bdd7be38.d3b55","name":"Press 0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":90,"y":1580,"wires":[["c8336735.61d09"]]},{"id":"ef7552ad.74313","type":"inject","z":"bdd7be38.d3b55","name":"Release 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":100,"y":1620,"wires":[["c8336735.61d09"]]},{"id":"caf24fc8.b6f0c8","type":"debug","z":"bdd7be38.d3b55","name":"Short Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":1700,"wires":[]},{"id":"2319a6a3.a0dcd2","type":"debug","z":"bdd7be38.d3b55","name":"Long Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":1560,"wires":[]},{"id":"3c9642ff.7e9136","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":1560,"wires":[["7ad58bf8.67e754"]]},{"id":"c8336735.61d09","type":"switch","z":"bdd7be38.d3b55","name":"Press?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":1580,"wires":[["3c9642ff.7e9136"],["3e1c7632.c31512","52e5fb05.e7585c"]]},{"id":"2f8b1620.54195a","type":"comment","z":"bdd7be38.d3b55","name":"Press","info":"","x":350,"y":1540,"wires":[]},{"id":"3e1c7632.c31512","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":1600,"wires":[["3c9642ff.7e9136"]]},{"id":"a5574be2.a40f1","type":"status","z":"bdd7be38.d3b55","name":"","scope":["3c9642ff.7e9136"],"x":580,"y":1600,"wires":[["b4c4b240.23e4a8"]]},{"id":"b4c4b240.23e4a8","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"status.fill  ? 'open' : 'close'","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":1660,"wires":[["52e5fb05.e7585c"]]},{"id":"52e5fb05.e7585c","type":"gate","z":"bdd7be38.d3b55","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":510,"y":1700,"wires":[["fcca8c7d.9b518"]]},{"id":"fcca8c7d.9b518","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"short-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":1700,"wires":[["caf24fc8.b6f0c8"]]},{"id":"7ad58bf8.67e754","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"long-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1560,"wires":[["2319a6a3.a0dcd2"]]},{"id":"7ffbab9e.b6570c","type":"comment","z":"bdd7be38.d3b55","name":"Release","info":"","x":290,"y":1640,"wires":[]},{"id":"41e03420.c49ed4","type":"comment","z":"bdd7be38.d3b55","name":"Simulated gpio press","info":"","x":110,"y":1540,"wires":[]}]

You avoid a function by adding a contrib node (gate) - I'd stick with a function tbh Colin. It wasn't really doing anything more than checking time difference.

And it also looks like you're using the status node for part of the process? Not sure that is wise (not sure why I think that's not wise but I do :wink: )

@matisok
As for the logic inversion, that's a simple fix.

I wasn't sure about using the Status either, but as long as the status output is considered part of the stable spec then it shouldn't be a problem.
The simple gate node is one of the few contrib nodes that I consider essential. I use it regularly, along with its sibling queue-gate.
The reason I prefer to avoid a function node is that it is much more likely to have a hidden bug than other nodes. Also there are significant overheads in the runtime using a function node, though that is not normally an issue. On the other hand there are advantages in encouraging new users to use function nodes as a way of learning javascript, so there are pros and cons.
I did start my post saying that I wasn't sure which was preferable, but thought it worth posting as an alternative.

RE: contrib node vs built in function - I'd put money on the function being lighter and faster than any contrib node (no additional require / on.event overheads etc). I like to think of the function node as a lean custom node - doing its sole singular purpose.

Dont get me wrong, the gate node is a great node (i use it too) but i dont think the overhead is worth it here (dont mid being proven wrong though)

No worries Colin, I don't mid being challenged - I've learned a lot myself from you guys.

I believe the function node sets up some sort of VM or something each time it runs which makes it a lot slower than a normal node.

It sets up a sandbox first time it is called, and then reuses it after that. So yes there is some small overhead going in and out.

1 Like

In this instance of course it is completely irrelevant.

1 Like

My alternative flow was not intended in any way to challenge yours. I started off thinking that I might end up with a significantly simpler flow using the trigger node, but in the end it worked out very similar in complexity, due to having to mess about with the status. I still have a feeling there aught to be a neater way though.

Both flow works beautifully here so thanks. There's definitely and advantage for me if it can be done without any custom nodes, but I am equally fond of as simple node structures as possible. Performance is purely academic in this application as noted. (Therefore of interest of course).

Now the next logic step presents itself for me: once the relays are "on" then I want the subsequent press to turn the relay off. And to make matters a little bit more challenging then I would like the "off" press to be a short click for both the Short Relay and Long Relay.

Mathias

Before looking at that, I have improved mine a bit by removing the status node requirement. Still a bit messy though.

[{"id":"43cfd67a.6bce5","type":"inject","z":"bdd7be38.d3b55","name":"Press 0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":90,"y":1840,"wires":[["ae7961b0.d87628"]]},{"id":"3121ec58.1c8b94","type":"inject","z":"bdd7be38.d3b55","name":"Release 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":100,"y":1880,"wires":[["ae7961b0.d87628"]]},{"id":"30b3f9ca.009afe","type":"debug","z":"bdd7be38.d3b55","name":"Short Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":1980,"wires":[]},{"id":"32c4ac95.0e2774","type":"debug","z":"bdd7be38.d3b55","name":"Long Press RELAY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":1820,"wires":[]},{"id":"974d9aac.eeea18","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":1820,"wires":[["f349caf0.3891a","80b6ab31.a6c12"]]},{"id":"ae7961b0.d87628","type":"switch","z":"bdd7be38.d3b55","name":"Press?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":250,"y":1840,"wires":[["974d9aac.eeea18","6b81f375.1d19ac"],["92ada8bb.384bb","217c4822.1be01"]]},{"id":"68fb2663.33c2c","type":"comment","z":"bdd7be38.d3b55","name":"Press","info":"","x":350,"y":1800,"wires":[]},{"id":"92ada8bb.384bb","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":1860,"wires":[["974d9aac.eeea18"]]},{"id":"80b6ab31.a6c12","type":"change","z":"bdd7be38.d3b55","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1880,"wires":[["217c4822.1be01"]]},{"id":"217c4822.1be01","type":"gate","z":"bdd7be38.d3b55","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":530,"y":1980,"wires":[["c51688d7.e998b","80b6ab31.a6c12"]]},{"id":"c51688d7.e998b","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"short-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":1980,"wires":[["30b3f9ca.009afe"]]},{"id":"f349caf0.3891a","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"long-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1820,"wires":[["32c4ac95.0e2774"]]},{"id":"b9b74edf.41abf8","type":"comment","z":"bdd7be38.d3b55","name":"Release","info":"","x":290,"y":1900,"wires":[]},{"id":"3cd5e5ab.1532aa","type":"comment","z":"bdd7be38.d3b55","name":"Simulated gpio press","info":"","x":110,"y":1800,"wires":[]},{"id":"6b81f375.1d19ac","type":"change","z":"bdd7be38.d3b55","name":"open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":1900,"wires":[["217c4822.1be01"]]}]

I find Dave (annoyingly) does that often :wink:

Bad choice of words Colin - all in good faith

Are you using MQTT to keep the state of the relays?

I am not - would that be a good idea? Right now the output of your flow goes directly to my other code which is a bit of timer countdown and a grinder motor on/off (simulated). I included the code here, but the timer bit is really messy. But it is this timer flow that I need to be able to get out off (reset) with a single short press.

[{"id":"5611aceb.191cc4","type":"rpi-gpio out","z":"f50f27f5.e841b8","name":"","pin":"35","set":true,"level":"0","freq":"100","out":"out","x":300,"y":240,"wires":[]},{"id":"aa7429d7.50f5e8","type":"inject","z":"f50f27f5.e841b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":220,"wires":[["5611aceb.191cc4"]]},{"id":"a1406b66.73a3a8","type":"inject","z":"f50f27f5.e841b8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":130,"y":260,"wires":[["5611aceb.191cc4"]]},{"id":"6952c2ca.d7f98c","type":"rpi-gpio out","z":"f50f27f5.e841b8","name":"","pin":"37","set":true,"level":"0","freq":"100","out":"out","x":1280,"y":140,"wires":[]},{"id":"5084f185.5092a","type":"inject","z":"f50f27f5.e841b8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":1170,"y":240,"wires":[["6952c2ca.d7f98c"]]},{"id":"53e9e007.d6208","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"short-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":220,"wires":[["de178924.06e208"]]},{"id":"3cc2b3c6.b2b5fc","type":"gate","z":"f50f27f5.e841b8","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":530,"y":220,"wires":[["53e9e007.d6208"]]},{"id":"f71f3524.8f0598","type":"switch","z":"f50f27f5.e841b8","name":"Press?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":100,"wires":[["cdc7e7d9.ed1cf8"],["3cc2b3c6.b2b5fc","bfb5c4d4.f33ca8"]]},{"id":"6cbe7ec3.94877","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"status.fill  ? 'open' : 'close'","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":180,"wires":[["3cc2b3c6.b2b5fc"]]},{"id":"2c288744.30d318","type":"inject","z":"f50f27f5.e841b8","name":"Press 0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":100,"wires":[["f71f3524.8f0598"]]},{"id":"255b9cb5.6513e4","type":"inject","z":"f50f27f5.e841b8","name":"Release 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":120,"y":160,"wires":[["f71f3524.8f0598"]]},{"id":"cdc7e7d9.ed1cf8","type":"trigger","z":"f50f27f5.e841b8","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":80,"wires":[["8b1771c8.ed13a"]]},{"id":"bfb5c4d4.f33ca8","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":120,"wires":[["cdc7e7d9.ed1cf8"]]},{"id":"9bb69aab.7d6398","type":"rpi-gpio in","z":"f50f27f5.e841b8","name":"","pin":"36","intype":"up","debounce":"25","read":false,"x":100,"y":40,"wires":[["f71f3524.8f0598"]]},{"id":"b28b1e5f.e8614","type":"status","z":"f50f27f5.e841b8","name":"","scope":["cdc7e7d9.ed1cf8"],"x":620,"y":120,"wires":[["6cbe7ec3.94877"]]},{"id":"8b1771c8.ed13a","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"long-press","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":80,"wires":[["fb4151e9.0dfe8"]]},{"id":"cdb28524.f35bd8","type":"rpi-gpio out","z":"f50f27f5.e841b8","name":"","pin":"33","set":true,"level":"0","freq":"100","out":"out","x":1060,"y":940,"wires":[]},{"id":"7a12ca40.1ce0f4","type":"inject","z":"f50f27f5.e841b8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":870,"y":940,"wires":[["cdb28524.f35bd8"]]},{"id":"2a878da6.5bc182","type":"countdown","z":"f50f27f5.e841b8","name":"red 4","topic":"Timer1","payloadTimerStart":"true","payloadTimerStartType":"bool","payloadTimerStop":"false","payloadTimerStopType":"bool","timer":"10","resetWhileRunning":false,"setTimeToNewWhileRunning":false,"startCountdownOnControlMessage":false,"x":510,"y":540,"wires":[["721a4d2f.265804","1a798e86.ae4b21","cdb28524.f35bd8"],[]]},{"id":"721a4d2f.265804","type":"trigger","z":"f50f27f5.e841b8","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"400","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1300,"y":900,"wires":[["e98fa94.3f87a58"]]},{"id":"1a798e86.ae4b21","type":"switch","z":"f50f27f5.e841b8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":400,"wires":[["ee1f961e.33d1c8"],["ef97e484.696558","a323366b.a64d38","ee1f961e.33d1c8"]]},{"id":"a323366b.a64d38","type":"InterruptFlowUltimate","z":"f50f27f5.e841b8","name":"Gok","triggertopic":"Timer1","x":470,"y":660,"wires":[["2a878da6.5bc182"]]},{"id":"e98fa94.3f87a58","type":"rpi-gpio out","z":"f50f27f5.e841b8","name":"","pin":"13","set":true,"level":"0","freq":"","out":"out","x":1560,"y":680,"wires":[]},{"id":"ef97e484.696558","type":"InvertUltimate","z":"f50f27f5.e841b8","name":"Invert","x":870,"y":400,"wires":[["495854.a1d847ac","e1da5fc0.c280e"]]},{"id":"ee1f961e.33d1c8","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"trigger","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":520,"wires":[["ca21a163.17be"]]},{"id":"e1da5fc0.c280e","type":"BlinkerUltimate","z":"f50f27f5.e841b8","name":"Blinker","blinkfrequency":"250","x":1020,"y":500,"wires":[["cdb28524.f35bd8"]]},{"id":"fb4151e9.0dfe8","type":"switch","z":"f50f27f5.e841b8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":800,"wires":[["a323366b.a64d38","2766c3e3.e4fa8c"],[]]},{"id":"d2d90d90.b1448","type":"delay","z":"f50f27f5.e841b8","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":630,"y":880,"wires":[["a323366b.a64d38"]]},{"id":"495854.a1d847ac","type":"trigger","z":"f50f27f5.e841b8","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1360,"y":540,"wires":[["e98fa94.3f87a58"]]},{"id":"ca21a163.17be","type":"InvertUltimate","z":"f50f27f5.e841b8","name":"Invert","x":830,"y":640,"wires":[["95c6dccb.47cc5"]]},{"id":"1cc1395c.d51647","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":700,"wires":[["e1da5fc0.c280e","669fca85.5cdeb4"]]},{"id":"2766c3e3.e4fa8c","type":"delay","z":"f50f27f5.e841b8","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":470,"y":780,"wires":[["95c6dccb.47cc5"]]},{"id":"b138bb54.bf0038","type":"change","z":"f50f27f5.e841b8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Timer1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":800,"wires":[["d2d90d90.b1448"]]},{"id":"95c6dccb.47cc5","type":"InterruptFlowUltimate","z":"f50f27f5.e841b8","name":"Interrupt Flow","triggertopic":"trigger","x":800,"y":760,"wires":[["1cc1395c.d51647"]]},{"id":"669fca85.5cdeb4","type":"InvertUltimate","z":"f50f27f5.e841b8","name":"Invert","x":1070,"y":760,"wires":[["b138bb54.bf0038"]]},{"id":"de178924.06e208","type":"trigger","z":"f50f27f5.e841b8","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"4","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":940,"y":220,"wires":[["6952c2ca.d7f98c"]]},{"id":"cfd18b02.490998","type":"ui_button","z":"f50f27f5.e841b8","name":"","group":"50ee66b2.914c18","order":0,"width":0,"height":0,"passthru":false,"label":"Reset now","tooltip":"","color":"","bgcolor":"","icon":"","payload":"false","payloadType":"bool","topic":"","x":290,"y":540,"wires":[["2a878da6.5bc182"]]},{"id":"7018b3b1.d2eeec","type":"comment","z":"f50f27f5.e841b8","name":"Buzzer","info":"","x":1550,"y":640,"wires":[]},{"id":"5c5f4658.b6a7e8","type":"comment","z":"f50f27f5.e841b8","name":"GREEN LED ","info":"","x":1070,"y":900,"wires":[]},{"id":"1d2e3eeb.435d11","type":"comment","z":"f50f27f5.e841b8","name":"BLUE LED ","info":"","x":1280,"y":100,"wires":[]},{"id":"51dae61b.b85af8","type":"comment","z":"f50f27f5.e841b8","name":"RED LED ","info":"","x":300,"y":200,"wires":[]},{"id":"f068e672.c59168","type":"comment","z":"f50f27f5.e841b8","name":"Simulate grinder motor (4s)","info":"","x":990,"y":180,"wires":[]},{"id":"50ee66b2.914c18","type":"ui_group","z":"","name":"Reset all timers","tab":"37955e3d.2fd1b2","order":3,"disp":true,"width":"6","collapse":false},{"id":"37955e3d.2fd1b2","type":"ui_tab","z":"","name":"QuickTimer","icon":"dashboard","disabled":false,"hidden":false}]