Calculate two variables

I have two variables from an output of a smbs. I want to subtract them by function to be able to make an indication how much space is available on a disk (in percent).

"T1" looks like this
msg.payload = Number(msg.payload[0].value)
return msg;

The subtraction function looks like this

var numberone = msg.payload.T1;
var numbertwo = msg.payload.T2;

msg.payload = (numberone - numbertwo);
return msg;

But the output will look like this:

Thank you in advance for your help

But if I debug the numbers directly then the following comes out


Hi @dereine

A flow based programming language requires a different way of looking at the flow of data and the code which is applied to it.

A message leaving your T1 function has a msg.payload value.
A message leaving your T2 function has a different msg.payload value.

Each of these messages is processed seperately by the Subtraction node. It only knows of the msg.payload which it's processing, with no memory of previous values.

You need to pass your two messages through a Join node to combine them into one with both values.


First of all, thanks for the fast answere


Is the Output from

i add the T1 and T2. is this wrong?

Each message needs a distinct topic before the Join. In this example I use "T1" and "T2".

In your T1 and T2 function nodes set msg.topic = "T1" or "T2".

This is the Join node.

1 Like

Perfect, this works fine now. Must find out, why they gife me double outputs, but i think this is a little thing.
Thanks alot for the help and have a nice day

Test it without "and evey subsequent message" ticked

1 Like

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