# Node-Red start up cycle

**URL:** <https://discourse.nodered.org/t/node-red-start-up-cycle/50249>\
**Category:** General\
**Created:** [27 August 2021 06:10 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249 "2021-08-27T06:10:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [27 August 2021 06:10 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/1 "2021-08-27T06:10:24Z")

</div>

Good morning all, I need advice with the Node-Red start up cycle. I have several relay outputs controlled by a Modbus node. These outputs are controlled by several variable comparisons and calculations coming from a field MQTT device. Before node red has started up and has all the necessary information for controlling the outputs, the relays switch on and off in an erratic manner, this can obviously result in damaging equipment being switched by these relays.  
Any suggestions?

---

<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:** [27 August 2021 06:40 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/2 "2021-08-27T06:40:54Z")

</div>

Is that due to bugs in the flows causing that? Add debug nodes showing what is being done by node red and select Output to console in the debug nodes. Then the output will be written to the node red log on startup so you can check. Give the debug nodes names to make it easier to follow.

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [27 August 2021 06:58 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/3 "2021-08-27T06:58:04Z")

</div>

Hi Colin, I don't believe is is a bug. But what I would like to do is block the output's (lets say 10 seconds) from any information flow until all the information is procesed. The switchin is based on current measurements comming from different devices. So in a total start up cycle, node-red is making switching operations when not all information is available.

---

<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:** [27 August 2021 07:04 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/4 "2021-08-27T07:04:37Z")

</div>

> [@Duncan](#):
>
> node-red is making switching operations when not all information is available

Do what I suggested and work out _exactly_ what is happening. Then adjust your flow to cope properly with the startup conditions. If you use a hack like disabling output for an arbitrary period then at some point something will happen that delays the initial data setup and your system will fail unpredictably.

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [27 August 2021 07:08 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/5 "2021-08-27T07:08:35Z")

</div>

ok, thanks colin I will do what you suggested.

---

<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:** [27 August 2021 08:00 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/6 "2021-08-27T08:00:39Z")

</div>

Before Node-RED has started the IO are only under the control of the Operating system - so you really need to provide your own isolation. You would need to work out how the IOs are set by default before Node-RED gets involved, and ensure your kit stays safe in that mode.

---

<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:** [27 August 2021 11:53 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/7 "2021-08-27T11:53:47Z")

</div>

This sort of problem can often be caused by using global or flow context variables before they have been initialised. You can avoid that by using inject nodes set to trigger on startup to initialise them, or often better is to avoid the use of such variables completely.

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [31 August 2021 13:24 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/8 "2021-08-31T13:24:29Z")

</div>

Maybe not the best solution. I used a q-gate node to block all outputs until all parameters were read, and the outputs set to their normal state. I then release the gate, it works like I would expect. Thanks for advice.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 October 2021 13:24 UTC](https://discourse.nodered.org/t/node-red-start-up-cycle/50249/9 "2021-10-30T13:24:37Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
