What's going on here - switch node

Sorry, but I seem to be missing a HUGE thing with how this is working.

Node in question:

[{"id":"a2eca75e0c71a132","type":"switch","z":"b25fd092.bcc758","name":"Is share available?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Sharename","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2640,"y":1590,"wires":[["1c9f575fb6b17307"],["c3d3a5ebe7ae8626"]]}]

switch node in the lower part.

TWO outputs! TWO!

So where's the second condition shown when I edit it?

:confused:

I've imported your flow which shows a 'switch' node with two outputs. Not sure how you have got to that situation as the default is the 'switch' node has a single output (until you add extra conditions).
With a single output it means - messages that match that condition are passed through - others are ignored. You can add a catch-all condition labelled 'otherwise' that will send other messages that fail the condition to an output. This assumes you want to do something with those messages.


If you click 'recreate' at the bottom of the 'switch' node it should rebuild the condition-tree.

Yeah, ok. But I'm confused why the node (the switch) has 2 outputs but when I open and edit it there is only 1 conditional test.

So where does the second one come from?

That's what is stumping me.

When I drag a virgin switch node onto my edit space it only has 1 output.

I'm not seeing the otherwise in the editing of the nod.e

It's at the very end of the drop-down menu.

I think you are missing my confusion.

I know where the otherwise option is.

But as shown, the switch has 2 outputs. I open to edit it and there is only ONE conditional test.

So from where does the second output get resolved.

I seem to not be explaining my concern clearly enough.

Hang on.

Clearer?

When I import your flow it shows two outputs for the 'switch' node. Then as soon as I click 'Done' the unused output disappers. Tried it on NR 3.1.0 and 4.0.9 - works fine for me

I'm using 4.0.9 (Should have declared that at the start - sorry)

But even so...... The edit screen for that node only has 1 conditional test and there are 2 outputs.

DEVELOPMENT!

New (demo) flow.

[{"id":"5783782ac991874a","type":"switch","z":"b25fd092.bcc758","name":"Is share available?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Sharename","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2950,"y":1740,"wires":[["b72b4617b122ef85"],["d5289b18c1d4f0a3"]]},{"id":"46ca7d9982268d34","type":"inject","z":"b25fd092.bcc758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Sharename","payloadType":"str","x":2750,"y":1710,"wires":[["5783782ac991874a"]]},{"id":"63c10611e155f077","type":"inject","z":"b25fd092.bcc758","name":"Something else","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2760,"y":1770,"wires":[["5783782ac991874a"]]},{"id":"b72b4617b122ef85","type":"debug","z":"b25fd092.bcc758","name":"Available","active":true,"console":"false","complete":"true","x":3160,"y":1710,"wires":[]},{"id":"d5289b18c1d4f0a3","type":"debug","z":"b25fd092.bcc758","name":"Unavailable","active":true,"console":"false","complete":"true","x":3170,"y":1760,"wires":[]}]

The something else doesn't get sent to the second output.

Strange.

I have imported your flow and see this..


Then if go inside the 'switch' node and do nothing and then click 'Done' I get this...

It will be interesting to hear/see what behaviour other people encounter.

2 Likes

BIGGER DEVELOPMENT

Machine 1:

Details:

{"nodered_version":"4.0.9","nodejs_version":"20.19.5","npm_version":"10.8.2","nr_started":"2025-10-05T15:19:59+11:00","hostname":"me-desktop","os_pretty":"Ubuntu 22.04.5 LTS","release":"Linux 5.15.0-156-generic x64 LE","os_installed":"2017-10-31T15:42:16+11:00","last_reboot":"2025-10-05T15:19:53+11:00","cpu":"Intel(R) Core(TM) i5-7260U CPU @ 2.20GHz","cores":4,"totalmem":"31.2 GB","freemem":"13.6 GB","loadAverage":{"load1min":1.08,"load5min":1.28,"load15min":1.17},"networkInterfaces":{"lo":[{"address":"127.0.0.1","netmask":"255.0.0.0","family":"IPv4","mac":"00:00:00:00:00:00","internal":true,"cidr":"127.0.0.1/8"},{"address":"::1","netmask":"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff","family":"IPv6","mac":"00:00:00:00:00:00","internal":true,"cidr":"::1/128","scopeid":0}],"eno1":[{"address":"192.168.17.6","netmask":"255.255.255.128","family":"IPv4","mac":"94:c6:91:11:55:10","internal":false,"cidr":"192.168.17.6/25"}]},"collected_at":"2025-10-05T05:49:25.096Z"}

Flow:

[{"id":"5783782ac991874a","type":"switch","z":"b25fd092.bcc758","name":"Is share available?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Sharename","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2950,"y":1740,"wires":[["b72b4617b122ef85"],["d5289b18c1d4f0a3"]]},{"id":"46ca7d9982268d34","type":"inject","z":"b25fd092.bcc758","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Sharename","payloadType":"str","x":2750,"y":1710,"wires":[["5783782ac991874a"]]},{"id":"63c10611e155f077","type":"inject","z":"b25fd092.bcc758","name":"Something else","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2760,"y":1770,"wires":[["5783782ac991874a"]]},{"id":"b72b4617b122ef85","type":"debug","z":"b25fd092.bcc758","name":"Available","active":true,"console":"false","complete":"true","x":3160,"y":1710,"wires":[]},{"id":"d5289b18c1d4f0a3","type":"debug","z":"b25fd092.bcc758","name":"Unavailable","active":true,"console":"false","complete":"true","x":3170,"y":1760,"wires":[]}]

Screen shot - cropped.

(Pressing the other inject node gets no output.)

Machine 2:

Details:

Copped screenshot

{"nodered_version":"4.0.9","nodejs_version":"18.20.6","npm_version":"10.8.2","nr_started":"2025-08-26T21:05:39+10:00","hostname":"TimePi","os_pretty":"Raspbian GNU/Linux 10 (buster)","release":"Linux 5.10.103-v7+ arm LE","os_installed":"2022-01-28T13:43:40+11:00","last_reboot":"2025-06-05T21:55:47+10:00","cpu":"ARMv7 Processor rev 4 (v7l)","cores":4,"totalmem":"0.9 GB","freemem":"364 MB","loadAverage":{"load1min":0.17,"load5min":0.07,"load15min":0.09},"networkInterfaces":{"lo":[{"address":"127.0.0.1","netmask":"255.0.0.0","family":"IPv4","mac":"00:00:00:00:00:00","internal":true,"cidr":"127.0.0.1/8"},{"address":"::1","netmask":"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff","family":"IPv6","mac":"00:00:00:00:00:00","internal":true,"cidr":"::1/128","scopeid":0}],"eth0":[{"address":"192.168.17.39","netmask":"255.255.255.0","family":"IPv4","mac":"b8:27:eb:fd:67:4e","internal":false,"cidr":"192.168.17.39/24"},{"address":"fe80::ba27:ebff:fefd:674e","netmask":"ffff:ffff:ffff:ffff::","family":"IPv6","mac":"b8:27:eb:fd:67:4e","internal":false,"cidr":"fe80::ba27:ebff:fefd:674e/64","scopeid":2}],"wlan0":[{"address":"192.168.1.1","netmask":"255.255.255.192","family":"IPv4","mac":"b8:27:eb:a8:32:1b","internal":false,"cidr":"192.168.1.1/26"},{"address":"fe80::1cb4:d0cb:4dbc:3b7e","netmask":"ffff:ffff:ffff:ffff::","family":"IPv6","mac":"b8:27:eb:a8:32:1b","internal":false,"cidr":"fe80::1cb4:d0cb:4dbc:3b7e/64","scopeid":3}]},"collected_at":"2025-10-05T05:55:42.051Z"}

Oh, $&(&$)%(&)$!

On the second machine there is an otherwise in the switch node.
So fair enough it has 2 outputs.

But machine 1's switch node doesn't have the otherwise part.

For some reason, your Machine 1 isn't telling the truth as the visual representation doesn't match the underlying logic. The visual shows two outputs, but the logic knows there is only one. So the 'switch' is behaving correctly by not sending 'something-else'. No idea why you are experiencing this strange behaviour with Machine 1 - maybe others will throw some light on the subject.

2 Likes

Thanks Dave.

I was just wanting to be sure I either was (or not) going crazy. :wink:

I just did what @dynamicdave said.

Believe it or not, it now went to only 1 output.

But strange it hadn't done it with previous attempts.

Question is how did you get it to have 2 outputs? The flow is this:

[
    {
        "id": "a2eca75e0c71a132",
        "type": "switch",
        "z": "f93e13e54f881a08",
        "name": "Is share available?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "Sharename",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,  // <<<<<<------------------ why is this 2?
        "x": 835,
        "y": 106,
        "wires": [
            [],
            []
        ]
    }
]

so when I import the flow, it shows two output ports but when I open the edit panel, Node-RED reverts that value to 1 because there is only one condition. So something went wrong when the JSON representation for the node was generated. For example, the following switch has ten outputs but on only one condition:

[{"id":"58b69efb55171242","type":"switch","z":"f93e13e54f881a08","name":"Is share available?","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Sharename","vt":"str"}],"checkall":"true","repair":false,"outputs":10,"x":751,"y":290,"wires":[[],[],[],[],[],[],[],[],[],[]]}]

but again, if I open the edit panel, Node-RED fixes the output count and its back to one output port.

So the more interesting question is how did you generate the JSON representation?

1 Like

Thanks.

But another question has come up in that I have opened that switch node a few times while posting here.

It kept the 2 outputs.

After Dave mentioned what happened on his machine, I tried and it (the node) tidied itself up and went to only having 1 output.

How did all that happen? (Rhetorical - of course.)

But it has kinda caught my interest on how it all happened.

It's the switch node - it sets the outputs based on the number of conditions. BUT only once the edit panel is opened.

Now you how did you get the outputs to be 2? That's the bug here. I know how I got the ten outputs on my flow example: I edited the JSON and set to ten by hand. It would be interesting to know how Node-RED export generated the two when there was only one condition.

But posts 1 and 4 show the switch node opened (being edited) and after that when I closed the edit window, it kept the 2 outputs.

But I can't reproduce that, neither with 3.1.x nor with 4.0.9 - if I import your flow, double click on the switch node, open the edit panel and then click "done" I get one port.

If on the other hand, I click "Cancel", I keep the two output ports - since all changes (including the fix to the outputs count change to 1) are discarded - hence you must have clicked "cancel" and not "done".

Will you now answer my question on how you generated that flow with 2 outputs when the swich only has one condition? :wink:

No worries.

That is why I am saying it has kinda got me interested in what happened.

ANOTHER UPDATE

Ok, so it was said if the switch node is opened and the done button pressed the output count is reduced to 1.

I just tested something which may have been keeping the confusion.

IF YOU PRESS THE CANCEL BUTTON
The second output remains.

IF YOU PRESS THE DONE BUTTON
The node modifies itself and only has 1 output.

However, it remains curious how it ever got the second output anyway.

But it's food for thought.

Do you happen to remember if you first created this switch node in the editor by dragging from the palette, copy and paste from another flow or by ctrl-i import?