Switch Node Does not appear to be working

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.

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

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.

Please show a debug output of the mqtt node.

image
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,

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?

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?

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.

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