IKEA motion sensor

I have a Ikea motion sensor the output from which I can access in Node-Red using zigbee2mqtt.

23/01/2020, 17:05:34node: 475f9e2.959efe

zigbee2mqtt/pirsensor : msg.payload : Object

object
occupancy: false
linkquality: 73
battery: 60

I am having difficulty using a Switch Node to process the true/false output from the sensor.
I have tried using a Split Node which delivers 3 separate outputs, occupancy (true or false), Linkquality and Battery. It is the first of these I am trying to isolate to switch a light on.

zigbee2mqtt/pirsensor : msg : Object

object

topic: "zigbee2mqtt/pirsensor"
payload: false
qos: 0
retain: false
parts: object
id: "e0ad1f30.f1d67"
type: "object"
key: "occupancy"
index: 0
count: 3
key: "occupancy"
_msgid: "ef727a8a.9ba4b8"

The Switch Node is set to detect either true or false but currently doesn't respond.
The MQTT In node is set to a parsed JSON object.
I have tried copying the path etc but no success.
Any help would be most appreciated.

Are you sure that the input is actually a boolean and not a string?

Maybe it is, here is the raw output -

23/01/2020, 19:40:23node: 475f9e2.959efe
zigbee2mqtt/pirsensor : msg.payload : string[48]
"{"occupancy":true,"linkquality":63,"battery":60}"

and after the Split Node

23/01/2020, 19:40:23node: 76c2c6d3.07b2d8
zigbee2mqtt/pirsensor : msg : Object
object
topic: "zigbee2mqtt/pirsensor"
payload: "{"occupancy":true,"linkquality":63,"battery":60}"
qos: 0
retain: false
parts: object
id: "e2e451b2.400f5"
type: "string"
ch: "↵"
index: 0
count: 1
_msgid: "ad771a69.9b2268"

I'm still unable to process this output.
Any thoughts?

BriAN

Feed that into a JSON node (or if it is coming from mqtt then tell the mqtt node to parse it as a JSON string) and feed that into a debug node. You should see a javascript object in the payload, and msg.payload.occupancy should be true or false. If you feed that through a Change node set to Move msg.payload.occupance To msg.payload then that should set the payload true or false, check that is the case with a debug node.
Now what exactly do you want to do with that? You mention a Switch node, do you mean a ui_switch node? If so then you should be able to feed what you have straight into the switch. If it doesn't work show us how you have configured the switch node.

Thanks Colin the payload is now either true or false. I am using this payload to connect to a MQTT out node which publishes to a sonoff switch with tasmota firmware. I wanted to learn how to use the Trigger node to switch the sonoff switch. The mqtt message has to be either 0/1 or ON OFF. To do this I now have to change true/false to either 0/1 or ON OFF. Have I got that right?

This works -

[
{
"id": "4b9083e5.db1c44",
"type": "mqtt in",
"z": "44ed0376.b98684",
"name": "",
"topic": "zigbee2mqtt/pirsensor",
"qos": "0",
"datatype": "json",
"broker": "af63855f.695e08",
"x": 140,
"y": 200,
"wires": [
[
"e7bc37c1.7f8e18"
]
]
},
{
"id": "eb9f6878.f02b28",
"type": "mqtt out",
"z": "44ed0376.b98684",
"name": "",
"topic": "sonofftest/cmnd/POWER",
"qos": "",
"retain": "",
"broker": "a18c05f4.86c9d",
"x": 1270,
"y": 160,
"wires":
},
{
"id": "87e24825.fb009",
"type": "trigger",
"z": "44ed0376.b98684",
"op1": "",
"op2": "OFF",
"op1type": "nul",
"op2type": "str",
"duration": "10",
"extend": false,
"units": "s",
"reset": "ON",
"bytopic": "all",
"name": "",
"x": 1030,
"y": 260,
"wires": [
[
"eb9f6878.f02b28"
]
]
},
{
"id": "e7bc37c1.7f8e18",
"type": "change",
"z": "44ed0376.b98684",
"name": "",
"rules": [
{
"t": "move",
"p": "payload.occupancy",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 430,
"y": 200,
"wires": [
[
"838fdc96.c1b3d8"
]
]
},
{
"id": "e5c02581.c68a98",
"type": "change",
"z": "44ed0376.b98684",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ON",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 160,
"wires": [
[
"eb9f6878.f02b28",
"d9aac502.1d4988"
]
]
},
{
"id": "838fdc96.c1b3d8",
"type": "switch",
"z": "44ed0376.b98684",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 650,
"y": 200,
"wires": [
[
"e5c02581.c68a98",
"4304d57f.842d04"
],
[
"f1bf5b71.0a5dd",
"4304d57f.842d04"
]
]
},
{
"id": "d9aac502.1d4988",
"type": "debug",
"z": "44ed0376.b98684",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1010,
"y": 200,
"wires":
},
{
"id": "4304d57f.842d04",
"type": "debug",
"z": "44ed0376.b98684",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 810,
"y": 200,
"wires":
},
{
"id": "f1bf5b71.0a5dd",
"type": "change",
"z": "44ed0376.b98684",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "OFF",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 240,
"wires": [
[
"87e24825.fb009",
"d9aac502.1d4988"
]
]
},
{
"id": "af63855f.695e08",
"type": "mqtt-broker",
"z": "",
"name": "MQTT",
"broker": "192.168.5.81",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "true",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": ""
},
{
"id": "a18c05f4.86c9d",
"type": "mqtt-broker",
"z": "",
"name": "MQTT",
"broker": "192.168.5.81",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "true",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": ""
}
]

You can do all that in one go using a Change node configured like this
image
That JSONata expression tests msg.payload.occupancy and if it is true sets the payload to ON, otherwise it sets it to OFF.

For future reference when you posting a flow do it as described in this post so that it is importable.

Many thanks Colin. I set this up to learn how to use the Trigger node.
Your elegant solution solves the problem without a Trigger node.
Point taken with sending code.
Thanks again.

Could you edit your previous post so that the flow is importable? I can't understand why you would use a Trigger node and would be interested to see. I can see why you would use a Switch node but not a Trigger.

Hi Colin here is my previous attempt.

[
    {
        "id": "94725b84.0e0c7",
        "type": "mqtt in",
        "z": "44ed0376.b98684",
        "name": "",
        "topic": "zigbee2mqtt/pirsensor",
        "qos": "0",
        "datatype": "json",
        "broker": "af63855f.695e08",
        "x": 180,
        "y": 260,
        "wires": [
            [
                "81b51117.2432e"
            ]
        ]
    },
    {
        "id": "81b51117.2432e",
        "type": "change",
        "z": "44ed0376.b98684",
        "name": "",
        "rules": [
            {
                "t": "move",
                "p": "payload.occupancy",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 450,
        "y": 260,
        "wires": [
            [
                "ad778b7f.1525e8"
            ]
        ]
    },
    {
        "id": "ad778b7f.1525e8",
        "type": "switch",
        "z": "44ed0376.b98684",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 690,
        "y": 260,
        "wires": [
            [
                "7e61cd22.a997e4"
            ],
            [
                "8f46b678.6417a"
            ]
        ]
    },
    {
        "id": "7e61cd22.a997e4",
        "type": "change",
        "z": "44ed0376.b98684",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "ON",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 880,
        "y": 240,
        "wires": [
            [
                "e6f210f9.632e88"
            ]
        ]
    },
    {
        "id": "8f46b678.6417a",
        "type": "change",
        "z": "44ed0376.b98684",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "OFF",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 880,
        "y": 280,
        "wires": [
            [
                "47756ef8.22bb3"
            ]
        ]
    },
    {
        "id": "47756ef8.22bb3",
        "type": "trigger",
        "z": "44ed0376.b98684",
        "op1": "",
        "op2": "OFF",
        "op1type": "nul",
        "op2type": "str",
        "duration": "15",
        "extend": false,
        "units": "s",
        "reset": "ON",
        "bytopic": "all",
        "name": "",
        "x": 1090,
        "y": 280,
        "wires": [
            [
                "e6f210f9.632e88"
            ]
        ]
    },
    {
        "id": "e6f210f9.632e88",
        "type": "mqtt out",
        "z": "44ed0376.b98684",
        "name": "",
        "topic": "sonofftest/cmnd/POWER",
        "qos": "",
        "retain": "",
        "broker": "a18c05f4.86c9d",
        "x": 1290,
        "y": 240,
        "wires": []
    },
    {
        "id": "af63855f.695e08",
        "type": "mqtt-broker",
        "z": "",
        "name": "MQTT",
        "broker": "192.168.5.81",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "true",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": ""
    },
    {
        "id": "a18c05f4.86c9d",
        "type": "mqtt-broker",
        "z": "",
        "name": "MQTT",
        "broker": "192.168.5.81",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "true",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": ""
    }
]