Concatenate two strings into one

Hi All,

I am NEW to node red and I want to learn and understand it further deeply, I am also using hass.io and node red is NOW going to take a part in my Home Automation.

I want to be able to send a value to my MQTT broker from a Function and also send the Value to Google Mini with a prefix string of The Value was changed to followed with the returned msg value of the function

When I combine the string and the value in one function it works great BUT I need the value ONLY for my MQTT since I am doing an automation regarding it's value. So I need to ADD a string to make Google say i.e. The value was changed to 23 where the 23 is the value that was sent to the MQTT Broker and the added string that I want to be able to concatenate.

Please help me on doing that
Thank you
Aryeduino

Please read
https://nodered.org/docs/user-guide/messages

Thanks, I have read this.
Maybe I am missing something and not understanding how to apply that on my request.
I would be happy for a simple guide on what i should be looking for?

I was trying a batch but did not exactly understood why I get errors on topic.
Also installed batcher with the same result and no luck at all.

The problem (for me) is that I need to add a String to a message that I am also sending to MQTT broker. The message I sent to the Broker MUST Be a number value and in order to get a notification from google using cast node I want to add a string since I can NOT send the value directly.

Also built a simple function for number generating to test it up and I will post it below:

rnd = Math.round (Math.random() * 100);
msg.payload = rnd;
return msg;

the msg is a number that sent to my MQTT broker and I want to be able to add a prefix string to that as mentioned above.

I am sorry if I have elaborated more then I needed - since I am learning right now and that would be great to be able to understand where you went wrong logically as well.

Please do assist,
Thank you!

Would this work ?
msg.payload = "The Value was changed to "+rnd;

No, I have already did that. and it works ONLY when I tested it.
But since I need the value to be sent to MQTT Broker NO strings at all pure value the message payload can not be with The value was changed to at all. I can not send a string to my MQTT topic.

I need to be able to concatenate two strings - One is the string The value was changed to and the other is the value (maybe need to do string casting but I am not sure)

So I need to be able to combine two payloads into one string.
lets say I have 2 Functions:
Function one returns msg.payload = "The Value was changed to ";
Function two returns msg.payload = rnd;

Since the payload of F2 is ALSO needed in a topic that i am monitoring using my MQTT - IT must be NUMBER only

I would be happy to get assistant on how to do that as i have mentioned - I have truied batcher with no luck, maybe I am doing something wrong (I am sure that I do) or I maybe I am missing a node that I can use for that.

Thanks

Well then I don't understand what you are trying to do.
Capitals and bold don't work for me tbh.

Send the number value to your mqtt broker, but also send it to the function node to add the string. You can connect two wires to a node output, connect one to the mqtt node and another to the function node.

Thanks, I have made capital and bold only to be sure that i am being in the same track as you - only to be sure you have the same view on what i am trying to do same as I do.
The Bold was only to make it clear that it is a must and I can not change it. since MQTT broker can't get a string and it must be a number value.

Collin, Yes! that is what I want to be able to do.
How can I send a value from one function to another one?
should I use var value =? I would be happy to know what I should do here?
I know about msg.payload but How to pass a value from on to another function I do not know how to do.

Please assist,
Thanks

See the link I posted above.

If you set msg.payload in one function and wire it to the second function then it will be in the message received by the second function.
Perhaps what you are actually trying to do is to combine information from two messages into one. If so then you can use the Join node in key/value pair mode as described in the node red cookbook example join-streams

1 Like

Thanks, Looks like exactly what I needed. Simple but efficient. Thank you both for your help. combined I got exactly what I was looking for. Thanks bakman and Collin.