# Combining text and variables together using change node

**URL:** <https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363>\
**Category:** General\
**Created:** [7 January 2024 11:25 UTC](https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363 "2024-01-07T11:25:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![greentrees](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@greentrees](https://discourse.nodered.org/u/greentrees)\
**Post date:** [7 January 2024 11:25 UTC](https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363/1 "2024-01-07T11:25:46Z")

</div>

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?

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [7 January 2024 11:36 UTC](https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363/2 "2024-01-07T11:36:42Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![greentrees](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@greentrees](https://discourse.nodered.org/u/greentrees)\
**Post date:** [7 January 2024 12:05 UTC](https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363/3 "2024-01-07T12:05:32Z")

</div>

Perfect. Thank you. That's super cool.

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 March 2024 12:06 UTC](https://discourse.nodered.org/t/combining-text-and-variables-together-using-change-node/84363/4 "2024-03-07T12:06:00Z")

</div>

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