Multiple instance of ui_switch

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?

Use of ui widgets in sub flows is not supported.

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

@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?

Sorry, but no.

But it seems to work

[{"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"]]}]


As you can see from image there are two switchs and both work independantly and have different labels and topics, with no issues.

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.

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 -

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

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

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.

To clear up mess as switches do not pass topic.

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

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.

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

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.

@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:

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.

@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.

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.

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

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

1 Like