Delaying a process question

Hi all trying to reproduce this.
Annotation 2022-01-31 104807

Not really sure how to do it since node-red is flow based and i cant really delay the whole of node-red or the inject node.
The delay is supposed to delay the whole process
I think im supposed to use the trigger node but im quite lost

yes .. use a trigger-node to control the flow

  1. provide input via msg.payload
  2. set trigger node like this
  3. check if msg.payload=1 and continue if true
  4. done

Are you able to describe what the flow is for in the real world? Often, when using a loop appears to be the correct solution to a problem, there is a different approach that fits the node red way better.

[{"id":"7625ae52c0987a45","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"a5f006b46ed20ea1","type":"inject","z":"7625ae52c0987a45","name":"0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":270,"y":180,"wires":[["31dbc3c1e77a5c5a"]]},{"id":"30e8f51c64eab3bf","type":"inject","z":"7625ae52c0987a45","name":"1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":270,"y":220,"wires":[["31dbc3c1e77a5c5a"]]},{"id":"31dbc3c1e77a5c5a","type":"trigger","z":"7625ae52c0987a45","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":470,"y":200,"wires":[["de4a2401b3fc3a85"]]},{"id":"de4a2401b3fc3a85","type":"switch","z":"7625ae52c0987a45","name":"? 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":200,"wires":[["98dcff3d0edd37af"],["029d64e495ef242a"]]},{"id":"98dcff3d0edd37af","type":"debug","z":"7625ae52c0987a45","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":180,"wires":[]},{"id":"029d64e495ef242a","type":"debug","z":"7625ae52c0987a45","name":"0","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":220,"wires":[]}]

no loop required :wink:

While this sort of works, 0 is not supposed to delay the flow.
Its kind of hard to make it work for some reason

x is supposed to be a motion sensor and y is supposed to be lights.

When the motion sensor is activated, it will turn on the lights for 10s and then check if the motion sensor is still activated (whether there are people still in the room). If there isn't, the lights will turn off however if it is, it will turn on the lights again for 10 seconds.

In Arduino code, it would be something like this

  if(motion sensor==1){
  }else if(motion sensor==0){

Yeah I'm still trying to learn how flow logic works instead of using loops

Yes, what smcgann99 says below. (Sorry, I didn't read the thread properly)

Move the switch node before the trigger to filter out the zeros. Trigger will then send out 1 and after 10sec send 0, unless its triggered again by pir.

flows.json (2.4 KB)

Is this something you are looking for?
0 and 1 correspond to the same input,
and PIN 35 is there only to show the status of the input.

There isn't any need to loop and check. The sensor will (I assume) tell you when there is no motion by sending a 0. So the way is to turn the lights on when you get a motion detected signal (1) and turn them off when you get a no motion signal (0). There should not be any need for the ten seconds wait as, again I assume, the motion detector has a minimum 'on' time so that it is not continually sending 1s and 0s. Mine has a minimum on time of about 1 minute in fact.

Would that solve the problem or am I missing something?

Mine is a generic PIR sensor so it just sends 1 per second. It dosent have a minimum on time so im trying to simulate that minimum on time for the LED.
As long as the LED has a minimum on time of 10s before checking the status of the PIR it will work for my case

This will make the status 0 be able to overwrite the LED delay.
I want to find a way to make the LED light up for atleast 10 seconds before allowing an input again

Yep this is what i'm looking for.
Should be easy in theory but I have a hard time trying to convert it to flow based.
Many thanks.
Here's the actual implementation with the I/O:

[{"id":"494480ef7f928ecd","type":"rpi-gpio in","z":"633f4ef1f3503bbe","name":"PIR","pin":"19","intype":"tri","debounce":"25","read":false,"bcm":true,"x":450,"y":900,"wires":[["9e57d342e51bab49"]]},{"id":"95b24554ed97b065","type":"rpi-gpio out","z":"633f4ef1f3503bbe","name":"LED","pin":"26","set":"","level":"0","freq":"","out":"out","bcm":true,"x":1250,"y":900,"wires":[]},{"id":"9e57d342e51bab49","type":"switch","z":"633f4ef1f3503bbe","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":900,"wires":[["82be3c7452937bc4"],["cf763fc29e7bc115"]]},{"id":"82be3c7452937bc4","type":"change","z":"633f4ef1f3503bbe","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":860,"wires":[["cf763fc29e7bc115","1a989388352bea02","95b24554ed97b065"]]},{"id":"cf763fc29e7bc115","type":"delay","z":"633f4ef1f3503bbe","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1000,"y":900,"wires":[["1a989388352bea02","95b24554ed97b065"]]},{"id":"70f8fc0513f46d3b","type":"group","z":"633f4ef1f3503bbe","name":"Emulated Input","style":{"label":true},"nodes":["5a4a909a98e77e5b","871dbaf4795873ca"],"env":[],"x":354,"y":939,"w":172,"h":122},{"id":"5a4a909a98e77e5b","type":"inject","z":"633f4ef1f3503bbe","g":"70f8fc0513f46d3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PIR","payload":"1","payloadType":"num","x":450,"y":980,"wires":[["9e57d342e51bab49"]]},{"id":"871dbaf4795873ca","type":"inject","z":"633f4ef1f3503bbe","g":"70f8fc0513f46d3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"PIR","payload":"0","payloadType":"num","x":450,"y":1020,"wires":[["9e57d342e51bab49"]]},{"id":"c2e3acb5471dad33","type":"group","z":"633f4ef1f3503bbe","name":"Emulated Output","style":{"label":true},"nodes":["1a989388352bea02"],"env":[],"x":1154,"y":939,"w":212,"h":82},{"id":"1a989388352bea02","type":"debug","z":"633f4ef1f3503bbe","g":"c2e3acb5471dad33","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":980,"wires":[]}]

Can you describe exactly what comes from the PIR in the case where someone goes into the room, moves about a bit, and then comes out please. I am sure it is simpler to solve than the flow you have shown.

Is the output of your pir open collector, so pullup or pulldown is needed?

PIR sensor is digital.
For as long as the person is in the room, the lights should be on.
Then when there is no one in the room, it'll wait 10 seconds before turning off.
Thanks for trying to make it simpler. I appreciate it.

Not too sure what you mean by that.
The PIR is digital so as long as someone is infront of the sensor, it'll give a 1

I didn't ask what you want to happen, I asked what the signal from the pir does.
Mine sends 1 when movement is detected, and when no movement is detected for a while (about 1 minute) it sends 0. That is the information we need to know.

My bad. It sends 1 when movement detected and 0 when there is no movement. There is no delay unlike yours