# How can i build a random delayed trigger loop?

**URL:** <https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912>\
**Category:** General\
**Created:** [12 October 2018 07:34 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912 "2018-10-12T07:34:24Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [9 January 2020 20:12 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/21 "2020-01-09T20:12:45Z")

</div>

> [@dceejay](#):
>
> using an inject to start it is not unreasonable

Exactly! But for some reason @eugene objects to using an `inject` node and says it has caused problems in his flow:

> [@eugene](#):
>
> But it would go haywire/crazy when I click multiple time on inject. And I do not want the possibility of accidentally turn delay off.

I don't really see much of an issue here, but I thought I could help without much effort or added complexity in the code.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 January 2020 22:14 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/22 "2020-01-09T22:14:36Z")

</div>

Ah well, up to you. Not sure what this obsession folk have with running with the editor open is about but hey 🙂

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [10 January 2020 02:45 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/23 "2020-01-10T02:45:05Z")

</div>

Good point. You can't click what you can't see...

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [10 January 2020 04:06 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/24 "2020-01-10T04:06:54Z")

</div>

> [@dceejay](#):
>
> obsession folk have with running with the editor open

It's because it is so wonderful we need to use it every day. 😉

---

<div class="post-metadata">

**Author:** ![eugene](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@eugene](https://discourse.nodered.org/u/eugene)\
**Post date:** [16 January 2020 21:40 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/25 "2020-01-16T21:40:56Z")

</div>

> [@drmibell](#):
>
> Exactly! But for some reason @eugene objects to using an `inject` node and says it has caused problems in his flow:

Hi, I found out that when I click inject button. Timer delay would of event generator would go crazy (reset even delay is not finish)  
This is the reason, why I am looking for random generator that will run indefinitely, without inject button that could mess it up.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [16 January 2020 23:00 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/26 "2020-01-16T23:00:37Z")

</div>

> [@eugene](#):
>
> Timer delay would of event generator would go crazy (reset even delay is not finish)

If the "reset" you describe is all that you mean by "go crazy," then that is the intended behavior. Switching the generator off stops it immediately so that no more events are emitted. This seems to be the sensible thing to do, as in "stop means stop." There may be confusion because the status text shows the time until the next event, which may never occur if the generator is switched off before it is due. I thought this extra information might be useful (output messages already have the `msg.delay` property that gives the time since the previous message), but you can disable the node status display for the flow, if you wish.

---

<div class="post-metadata">

**Author:** ![eugene](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@eugene](https://discourse.nodered.org/u/eugene)\
**Post date:** [17 January 2020 03:35 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/27 "2020-01-17T03:35:42Z")

</div>

This is the problem:  
Event Node did not run after restarting Node-Red.  
But inject node run by itself. I hope I made you guys see the point.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/7079fba9a8e7a55af55d2f5e83ed0efa7fe52c72.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 January 2020 09:48 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/28 "2020-01-17T09:48:50Z")

</div>

I notice that the `inject` node **control:timestamp** does not have the circular arrow (which means it has a schedule set up) or a little number `1` (which means it runs once at startup/deploy) as is shown on the `inject` node feeding the `random` node. This tells me that it is setup ONLY to run when you click the button.

This is why the top two flows did not run when you restarted Node-RED while the bottom one did.

---

<div class="post-metadata">

**Author:** ![eugene](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@eugene](https://discourse.nodered.org/u/eugene)\
**Post date:** [17 January 2020 12:57 UTC](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912/29 "2020-01-17T12:57:23Z")

</div>

Sorry my bad. Yes. That was my mistake. I could let it start once.  
But on the first two flow, accidentally clicking inject button would stop/toggle the delay making it breakable.  
while the bottom flow, delay is unbreakable.

> [@drmibell](#):
>
> If the "reset" you describe is all that you mean by "go crazy," then that is the intended behavior. Switching the generator off stops it immediately so that no more events are emitted.

I apologized again. The crazy behavior happens when I edit logic to ignore toggle. That way, when initially accepted control, it would remain on. But after modifying code to ignore 2 input. Seems that delay messages displayed on node icon is not in sync with output.

[Previous page](https://discourse.nodered.org/t/how-can-i-build-a-random-delayed-trigger-loop/3912.md?page=1)
