# Delaying a process question

**URL:** https://discourse.nodered.org/t/delaying-a-process-question/57530
**Category:** General
**Created:** [31 January 2022 02:58 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530 "2022-01-31T02:58:16Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [31 January 2022 02:58 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/1 "2022-01-31T02:58:16Z")

</div>

Hi all trying to reproduce this.  
 ![Annotation 2022-01-31 104807](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97a879b208508bd729c69b96d66b2a5129923948.png)

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

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [31 January 2022 03:18 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/2 "2022-01-31T03:18:04Z")

</div>

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

1. provide input via msg.payload
2. set trigger node like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e4effeee60ef3ae0f80822386f0658a7d541128.png)
3. check if msg.payload=1 and continue if true
4. done

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 January 2022 07:06 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/3 "2022-01-31T07:06:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [31 January 2022 07:11 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/4 "2022-01-31T07:11:18Z")

</div>

```auto
[{"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":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8dcbacf83d3544ffb3dc5b751ea2064aa2a64d7a.png)

no loop required 😉

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [31 January 2022 15:02 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/5 "2022-01-31T15:02:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [31 January 2022 15:07 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/6 "2022-01-31T15:07:01Z")

</div>

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

```auto
while(1){
  if(motion sensor==1){
    lights=1;
    delay(10000);
  }else if(motion sensor==0){
    lights=0;
  }
}

```

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

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [31 January 2022 15:27 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/7 "2022-01-31T15:27:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)
#### Post date: [31 January 2022 16:47 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/8 "2022-01-31T16:47:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [31 January 2022 18:44 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/9 "2022-01-31T18:44:21Z")

</div>

![billede_2022-01-31_193925](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6d9c713d1577730457346159dc67dd54f0bb5dcd.png)

[flows.json](https://discourse.nodered.org/uploads/short-url/f31ElyZA4kJgvvoAt04vn8T5JsC.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.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 January 2022 20:54 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/10 "2022-01-31T20:54:33Z")

</div>

> [@subwayfootlong](#):
>
> then check if the motion sensor is still activated

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?

---

<div class="post-metadata">

### Author: ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)
#### Post date: [31 January 2022 21:28 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/11 "2022-01-31T21:28:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2afcd7fe9fe7c8d947594b9452bf8c0f9a57900c.png)

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [1 February 2022 05:04 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/12 "2022-02-01T05:04:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [1 February 2022 05:06 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/13 "2022-02-01T05:06:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [1 February 2022 05:24 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/14 "2022-02-01T05:24:19Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2a9397cffbed9344cae659865a9a3be414426fa.png)

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [1 February 2022 09:22 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/15 "2022-02-01T09:22:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [1 February 2022 20:27 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/16 "2022-02-01T20:27:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [2 February 2022 06:51 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/17 "2022-02-02T06:51:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [2 February 2022 06:54 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/18 "2022-02-02T06:54:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [2 February 2022 07:21 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/19 "2022-02-02T07:21:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![subwayfootlong](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subwayfootlong/32/42037_2.png) [@subwayfootlong](https://discourse.nodered.org/u/subwayfootlong)
#### Post date: [2 February 2022 10:06 UTC](https://discourse.nodered.org/t/delaying-a-process-question/57530/20 "2022-02-02T10:06:15Z")

</div>

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

[Next page](https://discourse.nodered.org/t/delaying-a-process-question/57530.md?page=2)
