Ajuda na passagem de payload entre nodes diferentes

Tenho o meu sistema de alarme com triggers através de reconhecimento humano praticamente terminado excepto um pequeno detalhe relacionado com a payload que preciso passar por dois nós diferentes.

Aqui está um screenshot do meu flow (adicionada a seta vermelha apenas para deixar claro para onde a payload do Convert deve ser enviada e onde adicionei as condições do estado de alarme):

Aqui está o código de parte da flow :

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

Como posso passar as várias payloads do node Converter ao mesmo tempo que adiciono as condiçoes do alarmstate no meio sem perder a informaçao?

Obrigado !

Podes por exemplo colocar o payload dentro de uma variável. VÊ se isto ajuda:

http://www.steves-internet-guide.com/node-red-variables/

Em especial o capitulo “Exchange Data Between Nodes Without Wires”

@j_assuncao obrigado mas creio que neste caso a soluçao era bastante simples, bastava mudar os nomes dos payloads de cada node para conseguir reter ambos :slight_smile:


Copyright © 2017-2021. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade