Node-Red help with passing payload across different nodes

Hi guys,

Almost have my human recognition alarm system fully working in node-red except for a small detail related to a payload I need to pass across 2 different nodes .

Here is a screenshot of my flow (added the red arrow just to make it clear where the Convert payload should be sent to and where I added the alarm state conditions) :

[
    {
        "id": "1f106aac.627ac5",
        "type": "change",
        "z": "5bee2e87.e0fc5",
        "name": "Convert",
        "rules": [
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "data.base_id",
                "pt": "msg",
                "to": "$match(topic, /binary_sensor.(\\w{3})/).groups[0].$string()",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "data.camera",
                "pt": "msg",
                "to": "\"camera.\" & $.data.base_id",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "data.image_processing",
                "pt": "msg",
                "to": "\"image_processing.rekognition_person_\" & $.data.base_id",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "data.camera_snapshot",
                "pt": "msg",
                "to": "\"https://hassio.duckdns.org/local/camera_snapshot/snapshot_\" & $.data.base_id & \".jpg\"",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload.entity_id",
                "pt": "msg",
                "to": "\"image_processing.rekognition_person_\" & $.data.base_id",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 300,
        "y": 340,
        "wires": [
            [
                "59df5b16.db7964",
                "22f6ac5c.e83384",
                "fe673483.603ed8"
            ]
        ]
    },
    {
        "id": "59df5b16.db7964",
        "type": "template",
        "z": "5bee2e87.e0fc5",
        "name": "Set Snapshot",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "{\n\t\"data\": {\n\t\t\"entity_id\": \"{{data.camera}}\",\n\t\t\"filename\": \"/config/www/camera_snapshot/snapshot_{{data.base_id}}.jpg\"\n\t}\n}",
        "output": "json",
        "x": 620,
        "y": 400,
        "wires": [
            [
                "e6176341.cacbb"
            ]
        ]
    },
    {
        "id": "e6176341.cacbb",
        "type": "api-call-service",
        "z": "5bee2e87.e0fc5",
        "name": "Snapshot",
        "server": "e94c8527.3f2d08",
        "version": 1,
        "debugenabled": false,
        "service_domain": "camera",
        "service": "snapshot",
        "entityId": "{{data.camera}}",
        "data": "{\"filename\":\"{{data.camera_snapshot}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 900,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "fe673483.603ed8",
        "type": "delay",
        "z": "5bee2e87.e0fc5",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 420,
        "y": 520,
        "wires": [
            [
                "c5666c97.b2e0b"
            ]
        ]
    },
    {
        "id": "c5666c97.b2e0b",
        "type": "api-call-service",
        "z": "5bee2e87.e0fc5",
        "name": "Rekognition",
        "server": "e94c8527.3f2d08",
        "version": 1,
        "debugenabled": true,
        "service_domain": "image_processing",
        "service": "scan",
        "entityId": "",
        "data": "{\"entity_id\":\"{{data.image_processing}}\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 590,
        "y": 520,
        "wires": [
            [
                "ca5283b3.37de5"
            ]
        ]
    },
    {
        "id": "ca5283b3.37de5",
        "type": "api-current-state",
        "z": "5bee2e87.e0fc5",
        "name": "Person Check",
        "server": "e94c8527.3f2d08",
        "version": 1,
        "outputs": 2,
        "halt_if": "0",
        "halt_if_type": "num",
        "halt_if_compare": "gt",
        "override_topic": false,
        "entity_id": "",
        "state_type": "num",
        "state_location": "",
        "override_payload": "none",
        "entity_location": "aws_data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 900,
        "y": 500,
        "wires": [
            [
                "4e9b5265.4a9c2c"
            ],
            []
        ]
    },
    {
        "id": "22f6ac5c.e83384",
        "type": "debug",
        "z": "5bee2e87.e0fc5",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 570,
        "y": 320,
        "wires": []
    },
    {
        "id": "fdb92e2a.3d32",
        "type": "catch",
        "z": "5bee2e87.e0fc5",
        "name": "",
        "scope": null,
        "uncaught": false,
        "x": 640,
        "y": 460,
        "wires": [
            [
                "ca5283b3.37de5"
            ]
        ]
    },
    {
        "id": "cdd5f4b8.f59c68",
        "type": "server-state-changed",
        "z": "5bee2e87.e0fc5",
        "name": "Camera Motion",
        "server": "e94c8527.3f2d08",
        "version": 1,
        "entityidfilter": "binary_sensor.\\w{3}",
        "entityidfiltertype": "regex",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": false,
        "x": 100,
        "y": 340,
        "wires": [
            [
                "1f106aac.627ac5"
            ],
            []
        ]
    },
    {
        "id": "a3999516.0c89f8",
        "type": "switch",
        "z": "5bee2e87.e0fc5",
        "name": "Filter Alarm Status",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "armed_home",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "armed_away",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "disarmed",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "triggered",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 430,
        "y": 220,
        "wires": [
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "4c399fa.3b3036",
        "type": "api-current-state",
        "z": "5bee2e87.e0fc5",
        "name": "alarmstate",
        "server": "e94c8527.3f2d08",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "alarm_control_panel.home_alarm",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 210,
        "y": 220,
        "wires": [
            [
                "a3999516.0c89f8"
            ]
        ]
    },
    {
        "id": "e94c8527.3f2d08",
        "type": "server",
        "z": "",
        "name": "Home Assistant"
    }
]

I need to add the condition of halting the flow based on the state of my alarm before the Rekognition node but I am not sure how to do it without breaking the payload sent from the Convert Node .

How can I pass the multiple payloads in the Convert node while adding an halt condition in between ?

Thanks !

Assuming I’m understanding you, and correctly remembering the config for the current state node…

In the alarmstate node, you can configure where you want the state to be put, which defaults to msg.payload. You could change it to store the state in msg.alarm, which therefore would not overwrite msg.payload from Convert. You would then have to change Filter Alarm Status to check against msg.alarm instead of msg.payload.

You can also configure where you want the entity data, which defaults to msg.data. So you could have Camera Motion and alarmstate store their data in different msg locations, if useful.

1 Like