Looking for timing nodes

#1

I'm a PLC programmer, so Node-Red is new to me. I'm trying to find some nodes that would be similar to the traditional PLC TON (Timer On-Delay) and TOF (Timer Off-Delay) instructions. Below is an example of the PLC instruction.
TON%20Example

I need to monitor an input on a RPi 3 B+ with a Pimoroni Automation Hat. If the input stays on for 2 seconds, I need to trigger an output. If it goes false before 2 seconds nothing should happen and the timer should reset. As soon as the input turns off, the output should also turn off. I was able to get close with the flow below, but the output would also have a 2 second delay to turn off.

The next step of the project is that I need to ignore the input until it is off for a full, uninterrupted, 2 seconds. I'm hoping I can invert the input and use the same logic.

I would also like to find a RTO (Retentive Timer On-Delay) node, but don't have an immediate need.

I appreciate any help. If I can't find a solution this week, I'll order a PLC for pre-processing the inputs during prototyping.

[{"id":"1421fc28.6f1ad4","type":"rpi-automation-hat in","z":"ac1c406e.fda94","name":"","input":true,"analog":false,"threshold":0.01,"x":200,"y":420,"wires":[["cca6ac12.4c1cc"]]},{"id":"cca6ac12.4c1cc","type":"stoptimer","z":"ac1c406e.fda94","duration":"2","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":400,"y":420,"wires":[["e91622ea.1c101"],[]]},{"id":"dc6346fd.d78ab8","type":"rpi-automation-hat out","z":"ac1c406e.fda94","name":"","x":940,"y":420,"wires":[]},{"id":"e71c4160.7e1e6","type":"change","z":"ac1c406e.fda94","name":"Relay 2 OFF","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":440,"wires":[["dc6346fd.d78ab8"]]},{"id":"7b08be81.74407","type":"change","z":"ac1c406e.fda94","name":"Relay 2 ON","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":400,"wires":[["dc6346fd.d78ab8"]]},{"id":"e91622ea.1c101","type":"switch","z":"ac1c406e.fda94","name":"IF IN1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":420,"wires":[["7b08be81.74407"],["e71c4160.7e1e6"]]}]
#2

The trigger node is your friend - here is a simple example using inject nodes as i don't have a Hat or relays handy.

[{"id":"a64b5256.68203","type":"inject","z":"68636f36.4163c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":700,"wires":[["b132ad85.3ddce","571e17f6.660a18"]]},{"id":"b132ad85.3ddce","type":"trigger","z":"68636f36.4163c","op1":"","op2":"1","op1type":"nul","op2type":"num","duration":"2","extend":false,"units":"s","reset":"0","bytopic":"all","name":"","x":400,"y":700,"wires":[["a10d436d.48611"]]},{"id":"a10d436d.48611","type":"debug","z":"68636f36.4163c","name":"to relay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":620,"y":740,"wires":[]},{"id":"d87e4883.f3b588","type":"inject","z":"68636f36.4163c","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":740,"wires":[["b132ad85.3ddce","571e17f6.660a18"]]},{"id":"571e17f6.660a18","type":"switch","z":"68636f36.4163c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":740,"wires":[["a10d436d.48611"]]}]

Not quite sure what you mean by the second part fo the question re 2 sec delay for off - but this is my guess

[{"id":"a64b5256.68203","type":"inject","z":"68636f36.4163c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":700,"wires":[["b132ad85.3ddce","571e17f6.660a18"]]},{"id":"b132ad85.3ddce","type":"trigger","z":"68636f36.4163c","op1":"","op2":"1","op1type":"nul","op2type":"num","duration":"2","extend":false,"units":"s","reset":"0","bytopic":"all","name":"","x":360,"y":700,"wires":[["a10d436d.48611"]]},{"id":"a10d436d.48611","type":"debug","z":"68636f36.4163c","name":"to relay","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":700,"y":720,"wires":[]},{"id":"d87e4883.f3b588","type":"inject","z":"68636f36.4163c","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":740,"wires":[["b132ad85.3ddce","571e17f6.660a18"]]},{"id":"571e17f6.660a18","type":"switch","z":"68636f36.4163c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":740,"wires":[["7ad90e15.930a9"]]},{"id":"7ad90e15.930a9","type":"trigger","z":"68636f36.4163c","op1":"","op2":"0","op1type":"nul","op2type":"num","duration":"2","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":480,"y":740,"wires":[["a10d436d.48611"]]}]
#3

Thanks dceejay!

You got me going in the right direction. Below is what I came up with. I doubt it is the most efficient programming, but it works!

Start Logic:
Restart

[{"id":"7b2e9bff.9b5bb4","type":"switch","z":"17acf6b7.2147f9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"1500","vt":"num","v2":"6000","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1270,"y":540,"wires":[["20c6c416.63fc5c","e39e7595.5dded8"]]},{"id":"b3415a1d.de7b48","type":"comment","z":"17acf6b7.2147f9","name":"Restart Conveyor After Picture","info":"","x":1270,"y":500,"wires":[]},{"id":"e39e7595.5dded8","type":"change","z":"17acf6b7.2147f9","name":"Relay 1 ON","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.1","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1430,"y":540,"wires":[["c99ac52c.7947f8"]]},{"id":"20c6c416.63fc5c","type":"delay","z":"17acf6b7.2147f9","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1420,"y":580,"wires":[["9d4f1ebc.924e1"]]},{"id":"9d4f1ebc.924e1","type":"change","z":"17acf6b7.2147f9","name":"Relay 1 OFF","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.1","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1580,"y":580,"wires":[["c99ac52c.7947f8"]]},{"id":"c99ac52c.7947f8","type":"rpi-automation-hat out","z":"17acf6b7.2147f9","name":"","x":1790,"y":540,"wires":[]}]

Stop Logic:

[{"id":"f115304c.ccd78","type":"rpi-automation-hat in","z":"d509c0e6.089c3","name":"","input":true,"analog":false,"threshold":0.01,"x":140,"y":200,"wires":[["23b6ef30.59561","9379d344.fea7"]]},{"id":"8352719f.d963f","type":"comment","z":"d509c0e6.089c3","name":"Pallet Conveyor Stop Logic","info":"If the pallet is present for 2 consecutive seconds\n  Then stop the conveyor\n\nDon't allow the conveyor to stop again until there is\n  at least a 3 second gap without a pallet","x":150,"y":160,"wires":[]},{"id":"a67f2fa8.ca2fc","type":"rpi-automation-hat out","z":"d509c0e6.089c3","name":"","x":1520,"y":280,"wires":[]},{"id":"be9ac737.b07ca8","type":"change","z":"d509c0e6.089c3","name":"Relay 2 OFF","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":300,"wires":[["a67f2fa8.ca2fc"]]},{"id":"201a5072.df4f1","type":"change","z":"d509c0e6.089c3","name":"Relay 2 ON","rules":[{"t":"set","p":"topic","pt":"msg","to":"relay.2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":260,"wires":[["a67f2fa8.ca2fc"]]},{"id":"c7d8aeb2.e914c","type":"switch","z":"d509c0e6.089c3","name":"IF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1170,"y":300,"wires":[[],["be9ac737.b07ca8"]]},{"id":"fd0dde35.a1986","type":"trigger","z":"d509c0e6.089c3","op1":"","op2":"1","op1type":"nul","op2type":"num","duration":"2","extend":false,"units":"s","reset":"0","bytopic":"all","name":"","x":500,"y":300,"wires":[["e147816c.f50d"]]},{"id":"12863492.f8faab","type":"trigger","z":"d509c0e6.089c3","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"2","extend":false,"units":"s","reset":"0","bytopic":"all","name":"","x":1160,"y":260,"wires":[["201a5072.df4f1","c7d8aeb2.e914c"]]},{"id":"23b6ef30.59561","type":"switch","z":"d509c0e6.089c3","name":"IN1","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"automationhat/input.1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":200,"wires":[["88438461.8c58c8","fd0dde35.a1986"]]},{"id":"9379d344.fea7","type":"switch","z":"d509c0e6.089c3","name":"IN2","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"automationhat/input.2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":240,"wires":[["88438461.8c58c8"]]},{"id":"21cd21ce.f85cee","type":"trigger","z":"d509c0e6.089c3","op1":"","op2":"1","op1type":"nul","op2type":"num","duration":"3","extend":true,"units":"s","reset":"1","bytopic":"all","name":"","x":660,"y":180,"wires":[["81b4034a.4366"]]},{"id":"88438461.8c58c8","type":"switch","z":"d509c0e6.089c3","name":"IF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":180,"wires":[["21cd21ce.f85cee"],["cd16a1b9.89dcf"]]},{"id":"cd16a1b9.89dcf","type":"switch","z":"d509c0e6.089c3","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":240,"wires":[["21cd21ce.f85cee","2f103c70.0b6764"]]},{"id":"81b4034a.4366","type":"change","z":"d509c0e6.089c3","name":"Gap","rules":[{"t":"set","p":"topic","pt":"msg","to":"Gap","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":180,"wires":[["38dd2c0f.bdcc64"]]},{"id":"e147816c.f50d","type":"change","z":"d509c0e6.089c3","name":"Product","rules":[{"t":"set","p":"topic","pt":"msg","to":"Product","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":300,"wires":[["38dd2c0f.bdcc64"]]},{"id":"38dd2c0f.bdcc64","type":"and-gate","z":"d509c0e6.089c3","name":"","rules":[{"t":"eq","v":"1","vt":"num","propertyType":"msg","property":"payload","topic":"Gap"},{"t":"eq","v":"1","vt":"str","propertyType":"msg","property":"payload","topic":"Product"}],"outputTopic":"topic","gateType":"and","emitOnlyIfTrue":true,"x":1000,"y":260,"wires":[["12863492.f8faab"]]},{"id":"e6ef0ba7.3a1a18","type":"change","z":"d509c0e6.089c3","name":"Reset Product","rules":[{"t":"set","p":"topic","pt":"msg","to":"Product","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":220,"wires":[["38dd2c0f.bdcc64"]]},{"id":"c93b35b.3e3e2c8","type":"change","z":"d509c0e6.089c3","name":"Reset Gap","rules":[{"t":"set","p":"topic","pt":"msg","to":"Gap","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":260,"wires":[["38dd2c0f.bdcc64"]]},{"id":"2f103c70.0b6764","type":"switch","z":"d509c0e6.089c3","name":"IF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":630,"y":240,"wires":[["c93b35b.3e3e2c8","e6ef0ba7.3a1a18"],[]]},{"id":"e41d9208.ad50e","type":"inject","z":"d509c0e6.089c3","name":"On Boot","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":"2","x":680,"y":140,"wires":[["81b4034a.4366"]]}]