Combining Messages

Hello all,

I'm new to Node-RED and Java Script programming, so maybe there is a trivial solution to my problem, but I could not find anything yet.

I would like to retrieve data from my Loxone smart home "Miniserver" and log some data to an InfluxDB.
The general flow is working, but for storing meaningful data, I would like to combine message contents.

For example, the "Comfort Temperature" is sent by Loxone in the following format:

payload: 22
topic: "Temperature Sleeping Room"
state: "comfortTemperature"
room: "Sleeping Room"
category: "Heating"

Additionally, the allowed tolerance to this Temperature is sent seperately in another message:

payload: 0.5
topic: "Temperature Sleeping Room"
state: "comfortTolerance"
room: "Sleeping Room"
category: "Heating"

Instead of "comfortTemperature" and "comfortTolerance", I would like to store the actual range, e.g.

payload: 21.5
topic: "Temperature Sleeping Room"
state: "comfortMin"
room: "Sleeping Room"
category: "Heating"


payload: 22.5
topic: "Temperature Sleeping Room"
state: "comfortMax"
room: "Sleeping Room"
category: "Heating"

Therefore, I would like to store "comfortTemperature" and "comfortTolerance" for each "topic" to some data structure in the context and send the new messages once both values are received / changed.

Is there a way to store data referenced by a string?
Something like



The way I do this is with the JOIN node configured in manual node to output the joined messages as an array of message objects.

Then I write a FUNCTION node to process that array as required.

I have some doubt my method is "the best way" to do this but it works flawlessly for me.

Hope this helps.

Alternatively use the join node in key/value pairs mode, which I prefer. If you look in the node red cookbook there is a description of how to do this under the heading Joining Streams if I remember correctly.

Top, thanks a lot, that helped me a lot to find a solution! :slight_smile:

You are welcome, @stefan.

Glad to have helped you in some small way.

There is still one issue left.

I have used the join node and configured it to send when 2 messages are received.
This works when I deploy, because then both messages (temperature and offset) are sent.
But later, if only one of those values is changed, only one message is received and the join node does not send an update.
Do you have an idea how to solve this?


One simple approach is to make sure you send both message objects to JOIN each time; even it it means repeating a prior message when it has not changed. JOIN will wait, as you have learned, for both message objects to arrive.

There are probably better solutions, so this is only one idea. However, based on my experience, JOIN needs consistency in receiving message objects; so my "off the top of my head" approach would be to always send both message objects, even if that means finding a way to repeat the one which has not changed.

Just an idea ..... :slight_smile:

You just have to select And On Every Subsequent Message.

1 Like

Great, thanks, that worked!
I have used the output as arrays and the option for subsequent messages was not available.
But with key/value pairs it is exactly as I need it :slight_smile:


Unfortunately, I was wrong. It still does not work :slightly_frowning_face:
The join node combines the temperature and the offset value, but it does not consider the "topic" or room.
For example, if the first sent message sends the temperature 22°C for the living room and the second message sends the offset of 1°C for the sleeping room, the output message contains temperature 22°C / offset 1°C for the sleeping room.
I guess I will still need this array requested in my first post ...

I think I had misunderstood the problem in the first place. I think your original thought might be what you want, saving the information to the node context. msg.topic is a string so you can do things like context.get(msg.topic). So if you save an object containing the properties you want to remember using msg.topic as the context key then that might do what you want.

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