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:
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
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.
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.
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
Unfortunately, I was wrong. It still does not work
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.