# Is there a way to spawn multiple instances of a subflow from a single sequence?

**URL:** <https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961>\
**Category:** General\
**Created:** [21 March 2021 14:04 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961 "2021-03-21T14:04:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erktrek](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@erktrek](https://discourse.nodered.org/u/erktrek)\
**Post date:** [21 March 2021 14:04 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961/1 "2021-03-21T14:04:09Z")

</div>

Have been using NR very successfully in conjunction with the Hubitat Elevation smart hub for the past year or so. Have been overwhelmed by the awesomeness of the NR platform + HE community developed nodes.. 🤯

One aspect of my home automation system is to create some sequences for home or away. In order to do this I am using the "node-red-contrib-presence-faker" node. This node sets some randomized timing for execution which I can configure and control through messages - it allows me to have lights/devices whatever turn on/off on a semi-random timer. Unfortunately for my purposes I want have to have a PF node for each device rather than a group of them. I can do this the manual way of course but it starts to get rather unwieldy the more HE device nodes I add.

I would like to be able to create a subflow and pass in a list of devices and then loop through said list and separately instantiate the PF node for each device. I've got enough experience to handle the looping/parsing etc so am not worried about that bit.

My question is - does the subflow do this already, instantiate separate PF nodes based on each message in the loop or do they get overwritten/replaced each time? I have looked at the docs and am unclear about that in terms of nodes.

If it does get overwritten is there a way to dynamically instantiate nodes in a subflow or dynamically generate multiple instances of a subflow in a sequence?

Any thoughts would be appreciated...

---

<div class="post-metadata">

**Author:** ![erktrek](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@erktrek](https://discourse.nodered.org/u/erktrek)\
**Post date:** [22 March 2021 00:25 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961/2 "2021-03-22T00:25:01Z")

</div>

Anyone have any thoughts on this? 🤔

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 March 2021 00:43 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961/3 "2021-03-22T00:43:26Z")

</div>

Each subflow is an instance of whatever you have inside.

If you have one instance of the subflow you have one pf node. If you have 2 instances of your subflow, you effectively have 2 lots of whatever is inside (i.e. 2 pf nodes).

Unless the pf node supports dynamically creatable multiple schedules, it won't be possible either in or out of a subflow.

There are potentially other solutions but will require some work on your part. For example, the cron-plus node supports as many schedules as you wish and is 100% programmable/dynamic - but you would need to handle the variance of things (e.g. if you want an output at 7:30 +/- 30 mins, you'd have to set the schedule for 7:15 with a 30min random delay) but it is definitely possible to achieve what you're asking. (note I don't use nor do I know what this pf node does so there is some speculation on my part)

---

<div class="post-metadata">

**Author:** ![erktrek](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@erktrek](https://discourse.nodered.org/u/erktrek)\
**Post date:** [22 March 2021 00:48 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961/4 "2021-03-22T00:48:06Z")

</div>

Thanks for the heads up. Yeah thats kind of what I figured. Your idea about cron-plus is an interesting one - I have used it for other things so will explore a little further...

👍

---

<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:** [5 April 2021 00:48 UTC](https://discourse.nodered.org/t/is-there-a-way-to-spawn-multiple-instances-of-a-subflow-from-a-single-sequence/42961/5 "2021-04-05T00:48:27Z")

</div>

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