# Switch Node Does not appear to be working

**URL:** <https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633>\
**Category:** Industrial\
**Created:** [7 July 2023 14:08 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633 "2023-07-07T14:08:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [7 July 2023 14:08 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/1 "2023-07-07T14:08:47Z")

</div>

I am not getting any output from the switch node even though the MQTT topic here is updating to true or false when I update the topic.

```auto
[
    {
        "id": "2731d575a67784b2",
        "type": "mqtt in",
        "z": "ce6b5df784b18300",
        "name": "",
        "topic": "HAC Line 4 Disable Node-Red Heartbeat",
        "qos": "2",
        "datatype": "utf8",
        "broker": "5d5b1756c08930e5",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 380,
        "y": 3220,
        "wires": [
            [
                "13e948f887fb3d5a",
                "1cd0fb4ec526afdd"
            ]
        ]
    },
    {
        "id": "17519ed1787f1db8",
        "type": "MC Write",
        "z": "ce6b5df784b18300",
        "name": "On",
        "topic": "",
        "connection": "8bf9ce709d0bac70",
        "data": "true",
        "address": "M4620",
        "addressType": "str",
        "dataType": "str",
        "errorHandling": "throw",
        "outputs": 1,
        "x": 870,
        "y": 3160,
        "wires": [
            []
        ]
    },
    {
        "id": "13e948f887fb3d5a",
        "type": "debug",
        "z": "ce6b5df784b18300",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 3380,
        "wires": []
    },
    {
        "id": "1be8ac11312d25d2",
        "type": "MC Write",
        "z": "ce6b5df784b18300",
        "name": "Off",
        "topic": "",
        "connection": "8bf9ce709d0bac70",
        "data": "",
        "address": "M4620",
        "addressType": "str",
        "dataType": "str",
        "errorHandling": "throw",
        "outputs": 1,
        "x": 870,
        "y": 3240,
        "wires": [
            []
        ]
    },
    {
        "id": "f08962f0bea75981",
        "type": "debug",
        "z": "ce6b5df784b18300",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 3120,
        "wires": []
    },
    {
        "id": "1cd0fb4ec526afdd",
        "type": "switch",
        "z": "ce6b5df784b18300",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 690,
        "y": 3180,
        "wires": [
            [
                "17519ed1787f1db8",
                "f08962f0bea75981"
            ],
            [
                "1be8ac11312d25d2",
                "76e040fbd05065f7"
            ]
        ]
    },
    {
        "id": "76e040fbd05065f7",
        "type": "debug",
        "z": "ce6b5df784b18300",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 3200,
        "wires": []
    },
    {
        "id": "5d5b1756c08930e5",
        "type": "mqtt-broker",
        "name": "Shop PC Broker",
        "broker": "10.3.5.126",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "8bf9ce709d0bac70",
        "type": "MC Protocol Connection",
        "name": "PLC1",
        "host": "192.168.3.39",
        "port": "3001",
        "protocol": "UDP",
        "frame": "3E",
        "plcType": "Q",
        "ascii": false,
        "PLCStation": "",
        "PCStation": "",
        "PLCModuleNo": "",
        "network": "",
        "octalInputOutput": false,
        "timeout": "1000"
    }
]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2023 14:38 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/2 "2023-07-07T14:38:12Z")

</div>

Please edit your post and remove the extra text at the end, it makes your flow un-importable.

What do you see in the debug node showing what is coming out of the MQTT node?

Then change the MQTT node to output a parsed JSON object and see what you get.

---

<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 July 2023 14:51 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/3 "2023-07-07T14:51:07Z")

</div>

Please show a debug output of the mqtt node.

---

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [7 July 2023 15:08 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/4 "2023-07-07T15:08:17Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2917555f95dc2e733b93ea73539a5bf5226fe1a.png)  
first is when I had the MQTT In Node Output Set to auto detect. the next one is when I set it to parsed JSON Object, That worked!

Thank you,

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 July 2023 15:11 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/5 "2023-07-07T15:11:56Z")

</div>

In the flow you posted you had it set to string.

Do you realise why the switch works after you changed it to parsed JSON?

---

<div class="post-metadata">

**Author:** ![jts450](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@jts450](https://discourse.nodered.org/u/jts450)\
**Post date:** [7 July 2023 19:19 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/7 "2023-07-07T19:19:27Z")

</div>

I first had it set to Auto-Detect then I change to string and finally parsed JSON object like you said.

I figured the switch node now works because just true or false are coming thru and not the whole object as a string or buffer?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 July 2023 08:27 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/8 "2023-07-08T08:27:14Z")

</div>

In javascript there are different types of data. In your Switch node you are checking Is True and Is False. That assumes that the data is of type Boolean, which is data that can only have the values true or false, and can in principle be just the value of a single bit. If you look at the first debug output you will see it says it is of type String, which means that the data is a sequence of individual letters, in your case the sequence t r u e, which is is not the same as a Boolean true value.

---

<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:** [22 July 2023 08:27 UTC](https://discourse.nodered.org/t/switch-node-does-not-appear-to-be-working/79633/9 "2023-07-22T08:27:37Z")

</div>

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