How to use msg property in notify?

Hi!
How can I use a property of message in notify call service?
I’m trying to replace nome_sensor in message, but no success. I can see that property is being sent, but is not replaced in notify message.
This is my notify json (google assistant):

{
   "title": "Movimento detectado",
   "message": "Foi detectado um movimento na casa! Sensor: {{nome_sensor}}",
   "data": {
       "color": "red",
       "channel": "alarm_stream",
       "importance": "max",
       "vibrationPattern": "1000, 1000, 1000, 1000, 1000, 1000, 1000",
       "ledColor": "red",
       "persistent": "true",
       "tag": "persistent",
       "priority": "high"
       
   }
}

The entire msg that is being into notify node is:

{"_msgid":"407e71165278f54a","payload":1639175866531,"topic":"","nome_sensor":"Fundo"}

This is my entire test flow:

[
    {
        "id": "eda7c20ecbf16c9d",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "789e9e956ac2be24",
        "type": "inject",
        "z": "eda7c20ecbf16c9d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "nome_sensor",
                "v": "Fundo",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 390,
        "y": 540,
        "wires": [
            [
                "3e44f7e6ba8539b9"
            ]
        ]
    },
    {
        "id": "3e44f7e6ba8539b9",
        "type": "api-call-service",
        "z": "eda7c20ecbf16c9d",
        "name": "Notifica",
        "server": "2ba92c0c.9dae24",
        "version": 3,
        "debugenabled": false,
        "service_domain": "notify",
        "service": "mobile_app_redmi_k20_pro",
        "entityId": "",
        "data": "{\t   \"title\": \"Movimento detectado\",\t   \"message\": \"Foi detectado um movimento na casa! Sensor: {{nome_sensor}}\",\t   \"data\": {\t       \"color\": \"red\",\t       \"channel\": \"alarm_stream\",\t       \"importance\": \"max\",\t       \"vibrationPattern\": \"1000, 1000, 1000, 1000, 1000, 1000, 1000\",\t       \"ledColor\": \"red\",\t       \"persistent\": \"true\",\t       \"tag\": \"persistent\",\t       \"priority\": \"high\"\t       \t   }\t}",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 700,
        "y": 540,
        "wires": [
            [
                "65e6fb496d9de6d9"
            ]
        ]
    },
    {
        "id": "65e6fb496d9de6d9",
        "type": "debug",
        "z": "eda7c20ecbf16c9d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 990,
        "y": 540,
        "wires": []
    },
    {
        "id": "2ba92c0c.9dae24",
        "type": "server",
        "name": "Home Assistant",
        "version": 2,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": 30
    }
]

Try:

   "message": "Foi detectado um movimento na casa! Sensor: " + {{nome_sensor}},

or possibly - I can never remember which format NodeRed uses:

   "message": "Foi detectado um movimento na casa! Sensor: {{{nome_sensor}}}",

{{ is Jinja and used in HA

In Node-Red it’s JavaScript instead, so instead of

Sensor: {{nome_sensor}}",
   "data": {

You use

Sensor:"+some_value,
  "data":{

You might also be able to use a .replace("{{none_sensor",“some_value”) function

Yeah but in NodeRed it’s called Mustache templates. Anything inside {{ }} references the msg object, so msg.item can be directly referenced with {{ item }} and payload with {{ payload }}. And you can reference subobjects like {{ payload.object1.item1 }} without having to use + msg.payload.object1.item1.

AHH, never knew that.
I always used the other method because that was the one the Node-Red copy value path function give me.

Nevermind guy’s! Totally my mistake.
Data was set to ‘expression’ instead of ‘JSON’, that’s why Mustache templates was not working!

1 Like

I was going to ask about that, but in your flow you posted it says

        "dataType": "jsonata",

Giving back. My solution works, follows a different approach, and hopefully saves time to someone else.

The goal was: Read my PV battery voltage and send it formatted to the smartphone.

The solution: I use 3 Nodes:

  1. Poll State Node to read the voltage
  2. Function Node to extract and format the data
  3. Call Service Node to send to smartphone



Thanks for your inspirations and to my colleague MK!

:slight_smile:
Greek

1 Like

cheers, Greek! this also helped me!