I have created flows to start a counter using function node when the sensor is sensing an object and I need to restart the counter when the sensor is sensing an object again. I'm new to NODE-RED. Any tips ??
[{"id":"70589088.60c16","type":"source_in","z":"58e02bdc.9c0da4","device":"New Device - MODBUSRTU.1","sensor":"IR Sensor - 03_MODBUS_04","x":141,"y":656,"wires":[["d869c0a6.8b4e9"]]},{"id":"31e02fd2.6acb9","type":"debug","z":"58e02bdc.9c0da4","name":"","active":true,"console":"false","complete":"false","x":300,"y":847,"wires":},{"id":"cdfba21b.03b0a","type":"trigger","z":"58e02bdc.9c0da4","op1":"","op2":"1","op1type":"nul","op2type":"num","duration":"5","extend":false,"units":"s","reset":"","name":"","x":289,"y":737,"wires":[["f81110ec.91fd6"]]},{"id":"d869c0a6.8b4e9","type":"function","z":"58e02bdc.9c0da4","name":"Trigger Trial","func":"var HtoD = parseInt(msg.payload, 16);\n\n\n\n msg.payload=HtoD; \n return msg;\n","outputs":1,"noerr":0,"x":121,"y":714,"wires":[["4245d83.4c69f28"]]},{"id":"4245d83.4c69f28","type":"switch","z":"58e02bdc.9c0da4","name":"Switch","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"5000","vt":"num"},{"t":"else"}],"checkall":"true","outputs":2,"x":278,"y":700,"wires":[["cdfba21b.03b0a"],]},{"id":"f81110ec.91fd6","type":"function","z":"58e02bdc.9c0da4","name":"Counter","func":"for (var i=0; i<400; i++)\n{\n node.send({payload:i});\n}\n","outputs":1,"noerr":0,"x":289,"y":773,"wires":[["74870591.3229bc"]]},{"id":"74870591.3229bc","type":"delay","z":"58e02bdc.9c0da4","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":299,"y":809,"wires":[["31e02fd2.6acb9"]]}]