Concatenate?

Is there any way to concatenate in Node-RED? I’m trying to make something like the following work:

{
    "message":["Hello",
    payload.hours,
    ":",
    payload.minutes
        ]
}

Found a solution for my particular issue, but would be good to know how to concatenate strings and values, if anyone can chime in on that.

{
   "message":$join(
       [
           $substring(
               $fromMillis($millis()-21600000
   ),
               11,
               5
   ),
           " Text here."
       ]
   )
  }
{
    "message": "Hello " & payload.hours & ":" & payload.minutes
}

https://docs.jsonata.org/overview.html

2 Likes

Thank you, @Kermit. That worked! And much simpler than my solution. Two for two this week. You helped me one other time with Node-RED a week ago :grinning:

I’m still too stupid. And I’ve searched several hours.

In Node-red, I can already send an email with a text message.

But how can I send a mail with text and data?
Something like:

{
“title”: “A lot of info”,
“message”: "Temp. living is: " & sensor.temp_living & "Temp. bathroom is: " & sensor.temp_bathroom
}

The following syntax does not work:
{“title”:“Heating”,
“message”:“Temp. too low”,
“data”: “{{sensor.temp_living.number }}”
}

And the purpose is that I can concatenate several values in one single email

Node red does not have sensors, it uses messages.
Each message can contain different values.

If the message has the temperature then you can pass the temperature in the email, but if you have not told Node red in this sequence that it should read the temperature then it can’t have it.

So entities from Home Assistant is not transferred automatically, they have to be read using a current state node (as an easy example).
The current state node (if not configured differently) takes the state and places it in msg.payload.
If you need two temperatures in the same message/email then you need two current state nodes with different outputs of the states.

And then the json could look like:

{
"title": "A lot of info",
"message": "Temp. living is: " & msg.payload & "Temp. bathroom is: " & msg.payload2
}

Thanks for your answer

Finally I used a function to concatenate the different payloads

image

let num1 = msg.payload1;
let num2 = msg.payload2;
let num3 = msg.payload3;
let ans = '\nTemp naar radiator: ’ + num1
+ '\nTemp retour radiator: ’ + num2
+ '\nTemp in living: ’ + num3
;
msg.payload = ans;
return msg;