Deduct old payload from new payload

#1

Hi,

I am currently getting a payload that is perfectly fine to further use, but I would also like to deduct the previous payload

Ideally something like

payload=new.payload-old.payload

Is this easily done in a function somehow?

Best regards

0 Likes

Add two numbers
#2

Take a look at https://nodered.org/docs/writing-functions#storing-data

0 Likes

#3

Thank you for the link, unfortunately I wasn’t able to derive anything that worked…

Is it some sort of buffer or similar I need to do?

Best regards

0 Likes

#4

No node red doesn’t have a “buffer” of previous messages. So if you want to remember the previous message you will have to choose to store it, which is why I linked to the page that shows you how.

0 Likes

#5

Just to give a bit more of a pointer, the docs @ukmoose has linked to shows you how to store data in flow context. This can be used to store a message’s payload and retrieve it the next time a Function is called - allowing you to perform the operation you want.

0 Likes