Passing variable in JSON data field

I am building a simple automation with some Aqara water leakage sensors. I would want to be noticed on my phone if there is a water leakage.
Enough easy… I deployed one events: state node for each water sensor connected to a call service node which calls the ios notify service.
I would like now use just one call service node which receives a message to use in the data field.
So I thought to use a chain like this:

where I change the payload with the name of the water sensor.
My problem is how to write the JSON data file which should be something like:

    {
        "message": "water leakage from sensor <payload from previous node> ",
         "title": "warning"
     }

Could you help me understanding how to do this?

Thank You

click the Render Templates Checkbox

    {
        "message": "water leakage from sensor {{payload}}",
         "title": "warning"
    }
2 Likes

Hi @Kermit

Where is the Render Templates option as I am trying to do this with Alexa TTS in Node Red. All I can see is below?

Thanks!

Sorry, that example was using the latest version of node-red-contrib-home-assistant-websocket. I would recommend updating that to that but if you choose not to you can use a template node before the call-service node.

{
    data:  {
        "message": "water leakage from sensor {{payload}}",
        "title": "warning"
    }
}
1 Like

Thanks @Kermit and happy holidays to you!

In the end I did what I was looking for like this (which is exactly as you suggested):

var message = "The next bin collection is" + context.global.daysbin + context.global.nextbin + " and is the " + context.global.bin
msg.payload = {
    "data": {message}
}
return msg

I then pass it to the JSON node then on to the Alexa tts. Works a treat.

Basically I have a dummy switch in HA that I toggle via an Alexa routine “What bin collection is it this week”. I have a node listening to the mqtt in Node Red that then triggers the TTS and iOS notification, so I get a response like “The next bin collection is tomorrow, Friday 28th December and is the black bin - landfill”

Just trying now to work out if I can get Alexa to answer from the device I asked the routine from, rather than broadcast the response all over the house.

The flow looks like below:

Thanks for your help :slight_smile:

1 Like

I can’t remember who but I helped someone the other day who was using a script to get the name of the last Alexa device used and passing that to the call-service node basically the same thing that you’re trying to achieve.

Check out https://github.com/thorsten-gehrig/alexa-remote-control

You can probably read that into HA as a command line sensor then get into node-red.

Also, you don’t really need the to JSON node it should work fine without it because the function node is returning a javascript object.

1 Like

Thanks, this suggestion worked great for me. I’m not using temples, I just went into the JSON data section of the call service and added the json below. In the code payload.process represents the process that is not responding.

{
    "data": {
        "badge": 5,
        "push": null
    },
    "message": "{{payload.process}} is down, please investigate",
    "title": "Node Red System Alert"
}

The end result looks like this