Combining text and variables together using change node

Hi,
I've recently started using node red within my home assistant setup.

I want to be able to customize notification messages by passing previous payload information with text. A simple example I want to send notifications saying something like:

Motion detected on {camera name}.

I have used various different msg payload variables for testing such as {{payload}} {{mydata}} & {{topic}}. From checking the debug logs, they all seem to contain data, but when the notifications appear they don't show any data. The text appears, but not the variables.

The flows run without error. It is possible to embed variables into the change node like I have below or should I be using another method to combine, text and variables together?

[
    {
        "id": "3521d974adb3acf6",
        "type": "change",
        "z": "71ec2bc5edd49701",
        "name": "General Notification",
        "rules": [
            {
                "t": "set",
                "p": "mydata",
                "pt": "msg",
                "to": "Change Topic",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "payload.data",
                "pt": "msg",
                "to": "{\"title\":\"Title-Theta {{mydata}} Motion\",\"message\":\"Theta {{mydata}} {{topic}} {{payload}} End\",\"data\":{\"priority\":\"-2\"}}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 360,
        "y": 160,
        "wires": [
            [
                "877badf05418c075",
                "6ba6d4a5cef54f90"
            ]
        ],
        "info": "Default value of 0 if not provided. An integer value ranging [-2, 2] representing:\n-2 Very Low\n-1 - Moderate\n0 - Normal\n1 - High\n2 - Emergency"
    }
]```

In a change node you would use the JSONata type input.

Or use a template node set to output a parsed JSON object
e.g.

[{"id":"3521d974adb3acf6","type":"change","z":"d1395164b4eec73e","name":"General Notification","rules":[{"t":"set","p":"mydata","pt":"msg","to":"Change Topic","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data","pt":"msg","to":"{    \"title\": \"Title-Theta {{mydata}} Motion\",    \"message\": \"Theta \" & mydata & \" \" & topic & \" \" & payload & \"End\",    \"data\": {        \"priority\": \"-2\"    }}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":3100,"wires":[[]],"info":"Default value of 0 if not provided. An integer value ranging [-2, 2] representing:\n-2 Very Low\n-1 - Moderate\n0 - Normal\n1 - High\n2 - Emergency"},{"id":"57e75aaba2dcd4a1","type":"template","z":"d1395164b4eec73e","name":"","field":"payload.data","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"title\": \"Title-Theta {{mydata}} Motion\",\n    \"message\": \"Theta {{mydata}} {{topic}} {{payload}} End\",\n    \"data\": {\n        \"priority\": \"-2\"\n    }\n}","output":"json","x":460,"y":3180,"wires":[[]]}]
1 Like

Perfect. Thank you. That's super cool.

I've spent hours trying to get my head round the syntax/usage on this.