Function with different values in different times

I want to calculate an equation with 3 variables. The variable are coming asynchrone so I have to stor the latest values and then calculate the equation. Then output the result. Then wait for a new next value and then calucate with the new incoming value and withthe former two values that not have been updated. And so it continious ... Any good tip how to arrange this function? I'm a rookie Node-Red guy ....

sounds like you will need to use context variables

see the example here

1 Like

Or alternatively use the Join node, which saves the hassle of working out when you have got all three values and so on. Set it to generate key/value pairs using topic as the key, waiting for three topic values before sending anything and then sending every time a new value is received. Then you get all three values in the payload and can do what you want with them.


Or alternatively use the Batch node. Configure the node to group three messages, overlapping two.

This results in the node accumulating the first 3 messages and afterward sending the last two plus the new incoming payload. In other words, do the same as Colin said about the Join node. I just wanted to make the point that there are many different ways of achieving the same result. By the way, before Colin posted I was trying a much more complex solution using function node+ storage + lots of things. Only then I realized I was overthinking.



1 Like