# Activate multiple "in nodes", but each with delay?

**URL:** <https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226>\
**Category:** General\
**Created:** [18 November 2024 14:59 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226 "2024-11-18T14:59:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [18 November 2024 14:59 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/1 "2024-11-18T14:59:05Z")

</div>

Is there any elegant solution to this?

 ![kép](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/662dcca36aec2ce51108312bee88ce8c965ccdac.png)

I need to call 5-8 "Node in" nodes, (each turns on relays), with different formations,  
but it's not recommended to do it all at once to reduce power overload chance and interference.  
So I need to leave some time between the actions.

- Some kind of cycle would be nice, which needs only 2-3 node.

- Can I call the "Node in" nodes directly? (From a function.)

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [18 November 2024 15:34 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/2 "2024-11-18T15:34:39Z")

</div>

You could do it with a function node outputting an increasing number, passed to a delay node for each 250ms delay, then a switch node taking the number and passing to the correct output to the correct linked in node.

It would be cleaner(ish) and maybe more manageable as you could change the message delay quicker.

```auto
[{"id":"45f356adf463df21","type":"inject","z":"c07b047ac4d1031c","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":340,"wires":[["ad27477b9db90af9"]]},{"id":"ad27477b9db90af9","type":"function","z":"c07b047ac4d1031c","name":"Counter","func":"for (var i = 0; i < 10; i++) {\n\n node.send({\n topic: i\n })\n}\n\nnode.done();\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":340,"wires":[["cd49195e7a7bd6e1"]]},{"id":"6a7e775179a436a4","type":"switch","z":"c07b047ac4d1031c","name":"Switch","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"},{"t":"eq","v":"5","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":550,"y":340,"wires":[["fd784bb2d95c6a97"],["69ca47e9c6ff8f3c"],["65ff4e4b20b239c0"],["5d7b2175d60834c4"],["99c2eb9174ee7475"]]},{"id":"69ca47e9c6ff8f3c","type":"link out","z":"c07b047ac4d1031c","name":"link out 2","mode":"link","links":[],"x":675,"y":300,"wires":[]},{"id":"65ff4e4b20b239c0","type":"link out","z":"c07b047ac4d1031c","name":"link out 3","mode":"link","links":[],"x":675,"y":340,"wires":[]},{"id":"5d7b2175d60834c4","type":"link out","z":"c07b047ac4d1031c","name":"link out 4","mode":"link","links":[],"x":675,"y":380,"wires":[]},{"id":"99c2eb9174ee7475","type":"link out","z":"c07b047ac4d1031c","name":"link out 5","mode":"link","links":[],"x":675,"y":420,"wires":[]},{"id":"fd784bb2d95c6a97","type":"link out","z":"c07b047ac4d1031c","name":"link out 6","mode":"link","links":[],"x":675,"y":260,"wires":[]},{"id":"cd49195e7a7bd6e1","type":"delay","z":"c07b047ac4d1031c","name":"Delay","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":410,"y":340,"wires":[["6a7e775179a436a4"]]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 November 2024 15:36 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/3 "2024-11-18T15:36:24Z")

</div>

You can have an object called msg.delay, where property names reflects a link in nodes name and value is the delay. Pass that through a split node set to split msg.delay, and copy key to msg.target. Then have a delay node set to msg.delay and then a link call node set to send to msg.target. Finally make sure the corresponding link in has a link out set to return to link call node.  
e.g.

```auto
[{"id":"fc83a3ec18010038","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":7540,"wires":[["d4e7238b24847c29"]]},{"id":"20e9cd21c919eddd","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"delay","v":"{\"1sec\":1000,\"2sec\":2000}","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":7540,"wires":[["fc83a3ec18010038"]]},{"id":"d4e7238b24847c29","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"target","property":"delay","x":490,"y":7540,"wires":[["d8389e93f1d5462b"]]},{"id":"d8389e93f1d5462b","type":"delay","z":"d1395164b4eec73e","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":640,"y":7540,"wires":[["3e0512e0826795b6"]]},{"id":"3e0512e0826795b6","type":"link call","z":"d1395164b4eec73e","name":"","links":[],"linkType":"dynamic","timeout":"30","x":800,"y":7540,"wires":[["8c2bf131d1114463"]]},{"id":"8c2bf131d1114463","type":"debug","z":"d1395164b4eec73e","name":"debug 2577","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":7580,"wires":[]},{"id":"7753ed2cc43a9c53","type":"link in","z":"d1395164b4eec73e","name":"1sec","links":[],"x":525,"y":7700,"wires":[["06a1fce5b237dd6f","ac2bddc364f03e86"]]},{"id":"ac2bddc364f03e86","type":"link out","z":"d1395164b4eec73e","name":"link out 10","mode":"return","links":[],"x":715,"y":7660,"wires":[]},{"id":"06a1fce5b237dd6f","type":"debug","z":"d1395164b4eec73e","name":"debug 2575","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":7700,"wires":[]},{"id":"30021a1f86c67504","type":"debug","z":"d1395164b4eec73e","name":"debug 2576","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":7760,"wires":[]},{"id":"25fde0e88350236d","type":"link in","z":"d1395164b4eec73e","name":"2sec","links":[],"x":525,"y":7760,"wires":[["30021a1f86c67504","ac2bddc364f03e86"]]}]

```

---

<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:** [18 November 2024 16:20 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/4 "2024-11-18T16:20:02Z")

</div>

This might work too

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

```auto
[{"id":"2960e1995c367865","type":"inject","z":"514b185553136619","name":"","props":[{"p":"payload"},{"p":"topic","v":"[\"relay1\", \"relay4\", \"relay5\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":90,"y":440,"wires":[["62e3f3ac43b1b4e7"]]},{"id":"3e248c5434a88c06","type":"delay","z":"514b185553136619","name":"1 msg / 5s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":390,"y":440,"wires":[["4864310377d4eb27"]]},{"id":"4864310377d4eb27","type":"switch","z":"514b185553136619","name":"Topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"relay1","vt":"str"},{"t":"eq","v":"relay2","vt":"str"},{"t":"eq","v":"relay3","vt":"str"},{"t":"eq","v":"relay4","vt":"str"},{"t":"eq","v":"relay5","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":550,"y":440,"wires":[["510af376501bf81a"],["4f70f460e1d4d93e"],["de9c4b40ea8e325d"],["d4de9e139a0c664c"],["5b58f1093a614bb1"]]},{"id":"510af376501bf81a","type":"debug","z":"514b185553136619","name":"Relay1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":360,"wires":[]},{"id":"4f70f460e1d4d93e","type":"debug","z":"514b185553136619","name":"Relay2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":400,"wires":[]},{"id":"de9c4b40ea8e325d","type":"debug","z":"514b185553136619","name":"Relay3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":440,"wires":[]},{"id":"d4de9e139a0c664c","type":"debug","z":"514b185553136619","name":"Relay4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":480,"wires":[]},{"id":"5b58f1093a614bb1","type":"debug","z":"514b185553136619","name":"Relay5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":520,"wires":[]},{"id":"62e3f3ac43b1b4e7","type":"split","z":"514b185553136619","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"topic","x":230,"y":440,"wires":[["3e248c5434a88c06"]]}]

```

The input is msg.payload, perhaps "ON" or "OFF" and msg.topic, an array of relays to be switched, in order.

```auto
{
"payload":"ON",
"topic":["relay1","relay4","relay5"]
}

```

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [18 November 2024 16:26 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/5 "2024-11-18T16:26:34Z")

</div>

> [@MyRandomThoughts](#):
>
> You could do it with a function node outputting an increasing number, passed to a delay node for each 250ms delay, then a switch node taking the number and passing to the correct output to the correct linked in node.

That was my first thought too, but than I would still need 5-7 nodes.

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [18 November 2024 16:27 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/6 "2024-11-18T16:27:11Z")

</div>

> [@E1cid](#):
>
> You can have an object called msg.delay, where property names reflects a link in nodes name and value is the delay.

Looks great!

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [18 November 2024 16:38 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/7 "2024-11-18T16:38:58Z")

</div>

True, but it would be cleaner and more manageable.

---

<div class="post-metadata">

**Author:** ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)\
**Post date:** [18 November 2024 21:09 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/8 "2024-11-18T21:09:05Z")

</div>

**Thank you very much for ALL the help!**

From the 3 (half-)solutions, I've managed to put together one, that is:

- working! _(Not all above does.)_
- needs only 3 nodes all together
- easy to change
- can be copied and reused to the other use cases

```json
[{"id":"248fd182180aba8f","type":"function","z":"2c9fbd1d.903c7a","name":"Array INs","func":"const InNodes = [\"In1\", \"In2\", \"In3 Kitchen\"];\n\nfor (let x of InNodes) {\n msg.rate = 500;\n msg.target = x;\n node.send( msg );\n}\n\nnode.done();\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":100,"wires":[["e7529b53e6c82326"]]},{"id":"e7529b53e6c82326","type":"delay","z":"2c9fbd1d.903c7a","name":"Limit Rate 0.2","pauseType":"rate","timeout":"1000","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"0.2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":true,"outputs":1,"x":760,"y":100,"wires":[["2e0db48935ca7414"]]},{"id":"2e0db48935ca7414","type":"link call","z":"2c9fbd1d.903c7a","name":"Dynamic target call","links":[],"linkType":"dynamic","timeout":"30","x":970,"y":100,"wires":[[]]}]

```

 ![kép](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8f4186b804d901405756da05b12fa4fab194704.png)

I've learned 2 important things:

- "Delay" node can be changed to work as "Rate Limiter".
- "Link call" can be "Dynamic" by changing the type!  
_(And "link-in" nodes called by name.")_

# This is the main function:

```js
const InNodes = ["8in Nappali", "7in Konyha", "6in Fürdő", "5in 1.sz Ablak", "4in 1.sz Ajtó", "3in 2.sz. Ajtó", "2in 2.sz. Ablak"];

for (let x of InNodes) {
    msg.rate = 500;
    msg.target = "Fel_" + x;
    node.send( msg );
}

node.done();

```

---

<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:** [2 December 2024 21:09 UTC](https://discourse.nodered.org/t/activate-multiple-in-nodes-but-each-with-delay/93226/9 "2024-12-02T21:09:45Z")

</div>

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