# Multiple instance of ui\_switch

**URL:** <https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562>\
**Category:** Dashboard\
**Created:** [7 February 2021 16:11 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562 "2021-02-07T16:11:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 16:11 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/1 "2021-02-07T16:11:10Z")

</div>

I made a sublflow which contains an ui\_switch and several other functions to let it work as I need.

Now, if I make several instances of that subflow, by clicking on one ui\_switch, each of them are toggling. How can I give each switch its own instance?

---

<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:** [7 February 2021 16:13 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/2 "2021-02-07T16:13:38Z")

</div>

Use of ui widgets in sub flows is not supported.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 16:14 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/3 "2021-02-07T16:14:22Z")

</div>

That's bad... ok, I will try to find a workaround.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 16:18 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/4 "2021-02-07T16:18:03Z")

</div>

@dceejay  
This is the subflow. As I have tenths of those controls and I need to put a switch to every one of them, you can image that without a subflow I will generate a mess on the flow design...

Suggestions?

 ![Schermata 2021-02-07 alle 17.17.38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/63461d1c882230df98096bab522ee07a8514d44d.png)

---

<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:** [7 February 2021 16:41 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/5 "2021-02-07T16:41:16Z")

</div>

Sorry, but no.

---

<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:** [7 February 2021 17:34 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/6 "2021-02-07T17:34:13Z")

</div>

But it seems to work

```auto
[{"id":"8da0329b.cc34f","type":"subflow","name":"switch sub topic","info":"","category":"","in":[{"x":120,"y":60,"wires":[{"id":"513a5204.1a1154"},{"id":"633642e4.a81e64"}]}],"out":[{"x":620,"y":200,"wires":[{"id":"adab6c12.45acd8","port":0}]}],"env":[],"color":"#DDAA99","status":{"x":480,"y":60,"wires":[{"id":"513a5204.1a1154","port":0}]}},{"id":"7f335fe0.7fd38","type":"join","z":"8da0329b.cc34f","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":150,"y":200,"wires":[["ac87d4f.44a7d28"]]},{"id":"adab6c12.45acd8","type":"change","z":"8da0329b.cc34f","name":"","rules":[{"t":"move","p":"payload.value","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"passthrough","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":200,"wires":[[]]},{"id":"513a5204.1a1154","type":"ui_switch","z":"8da0329b.cc34f","name":"","label":"{{msg.label}}","tooltip":"","group":"8b5cde76.edd58","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":340,"y":80,"wires":[["8d2bd323.bb87b8"]]},{"id":"142176af.5ef709","type":"change","z":"8da0329b.cc34f","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":140,"wires":[["7f335fe0.7fd38"]]},{"id":"ac87d4f.44a7d28","type":"switch","z":"8da0329b.cc34f","name":"","property":"passthrough","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":300,"y":200,"wires":[["adab6c12.45acd8"]]},{"id":"8d2bd323.bb87b8","type":"change","z":"8da0329b.cc34f","name":"","rules":[{"t":"set","p":"passthrough","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":140,"wires":[["142176af.5ef709"]]},{"id":"633642e4.a81e64","type":"change","z":"8da0329b.cc34f","name":"","rules":[{"t":"set","p":"passthrough","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":140,"y":100,"wires":[["142176af.5ef709"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"6","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"50b791ed.901808","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"label","v":"wwwq","vt":"str"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"q","payload":"false","payloadType":"bool","x":146.3333282470703,"y":499.3333435058594,"wires":[["27b86af6.c19f76"]]},{"id":"27b86af6.c19f76","type":"subflow:8da0329b.cc34f","z":"e4f02345.29fe9","name":"","env":[],"x":350,"y":540,"wires":[["72ac1be2.3cd63c"]]},{"id":"72ac1be2.3cd63c","type":"debug","z":"e4f02345.29fe9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":560,"wires":[]},{"id":"827f4295.22ba48","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"label","v":"wwwq","vt":"str"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"q","payload":"true","payloadType":"bool","x":140,"y":560,"wires":[["27b86af6.c19f76"]]},{"id":"1493cdf0.e5785a","type":"subflow:8da0329b.cc34f","z":"e4f02345.29fe9","name":"","x":370,"y":600,"wires":[["72ac1be2.3cd63c"]]},{"id":"1c8fefce.e3fee","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"label","v":"rrrrrt","vt":"str"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"t","payload":"false","payloadType":"bool","x":160,"y":620,"wires":[["1493cdf0.e5785a"]]},{"id":"326b66b.d1ca59a","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"label","v":"rrrrrt","vt":"str"},{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"t","payload":"true","payloadType":"bool","x":150,"y":660,"wires":[["1493cdf0.e5785a"]]}]

```

 ![Screenshot_20210207-173217](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/6982d7e5810dbf1b3d52cd68610d3a5f37de2f19.png)  
As you can see from image there are two switchs and both work independantly and have different labels and topics, with no issues.  
 ![Screenshot_20210207-173640](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/8270d307e87d5abf60f721a9b314d08e216e6169.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 February 2021 18:33 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/7 "2021-02-07T18:33:48Z")

</div>

The problems come when you want to control the layout. Any UI node inside a subflow won't show up on the dashboard sidebar so you can't lay them out our change the order they appear in.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 18:48 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/8 "2021-02-07T18:48:17Z")

</div>

Your 2 switches are in the same subflow. What if you instantiate another subflow ? You'll find that the 4 switches are no more separated, but they will work on couples.

- Sent from my mobile phone. Sorry for typos -

---

<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:** [7 February 2021 18:50 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/9 "2021-02-07T18:50:00Z")

</div>

So then you could just make multiple copies of the subflow with different names?

 ![Screenshot_20210207-184844](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2480f42ef31833ac6f3dd43d666c9b0be1b0137.png)

---

<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:** [7 February 2021 18:51 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/10 "2021-02-07T18:51:35Z")

</div>

> [@fmarzocca](#):
>
> Your 2 switches are in the same subflow. What if you instantiate another subflow ? You'll find that the 4 switches are no more separated, but they will work on couples.

No i could have four the same all independant, but with no control over individual position within a group.  
[edit]  
Just feed them different labels and/or topics

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 February 2021 18:53 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/11 "2021-02-07T18:53:50Z")

</div>

> [@E1cid](#):
>
> then you could just make multple copies of the subflow with different names?

To what purpose? They still don't show up in the dashboard sidebar.

Please consider that maybe we know what we're taking about here. It may not be clear to you, but there are problems using UI nodes in asubflows.

We've spent a lot of time looking at this. There is some work going on that should solve it in the future.

---

<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:** [7 February 2021 18:58 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/12 "2021-02-07T18:58:57Z")

</div>

> [@knolleary](#):
>
> To what purpose? They still don't show up in the dashboard sidebar.
> 
> Please consider that maybe we know what we're taking about here. It

To clear up mess as switches do not pass topic.

They do show in side bar, unless this image is not sidebar

 ![Screenshot_20210207-185637](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc83c05ad9b4baf6e332444e14ba1b9599e17266.png)

Please don't think for one minute that i think you don't know what you are talking about. I was just trying to work around the problem, and asking some questions.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 February 2021 19:12 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/13 "2021-02-07T19:12:22Z")

</div>

So now try to reorder those switches so they appear in a different order.

---

<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:** [7 February 2021 19:16 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/14 "2021-02-07T19:16:19Z")

</div>

I did, I moved one above the chart.  
the 2 above chart are same subflow, the one below is a copy of the sub flow with different name in properties.

 ![Screenshot_20210207-191428](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9a90d80973e42f9d5514698db87f6d36449cdcc.png)

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 19:32 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/15 "2021-02-07T19:32:54Z")

</div>

@E1cid  
thank you for trying to find a workaround. I confirm, my subflow contains 1 switch, but when I deploy 2 (or more) copies of the subflow, if I press one switch also the other gets pressed.  
This is how the switch is set in the subflow:

 ![Schermata 2021-02-07 alle 20.31.48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e1e5406969185086a270b905089cfc72eae8c1b1.png)

---

<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:** [7 February 2021 19:36 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/16 "2021-02-07T19:36:59Z")

</div>

I can not say much as i have no copy of your subflow. It works with mine on my device, using node-red v 1.2.9.

If you export an example of your flow, with the subflow and some injects with sample names and topics, etc, I will take a look.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [7 February 2021 20:08 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/17 "2021-02-07T20:08:05Z")

</div>

@E1cid By studying your subflow I have found a mistake in mine, thanks. Now the switches act independently. The only issue is (as @knolleary reported) the impossibility to determine a custom order of the switches on the dashboard.

---

<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:** [7 February 2021 20:14 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/18 "2021-02-07T20:14:37Z")

</div>

You can export the subflow, then import, it will give you option to make copy, do so and rename it. You can then make multiple copies if you wish. Each new subflow and switch will show in dashboard layout and can be placed where you wish. As you can see in my last two images.

---

<div class="post-metadata">

**Author:** ![fmarzocca](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fmarzocca/32/35901_2.png) [@fmarzocca](https://discourse.nodered.org/u/fmarzocca)\
**Post date:** [8 February 2021 08:40 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/19 "2021-02-08T08:40:20Z")

</div>

@E1cid : are you able also to assign the UI switch group dynamically, or should it be hard-coded into the subflow?

---

<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:** [8 February 2021 08:46 UTC](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562/20 "2021-02-08T08:46:45Z")

</div>

There are ways to code switches dynamically using the ui\_template, but I have not attempted it as i do not use dashboard for my user interface. I think there is a thread on this forum that discusses it.  
Using the subflow and/or switches you would need to hardcode each switch

[Next page](https://discourse.nodered.org/t/multiple-instance-of-ui-switch/40562.md?page=2)
