Search code examples
node-red

Node-Red compare new and previous values


I'm new to Node-Red and I don't know if that's possible without some storage (SQL database for example).

enter image description here

So, I have an MQTT endpoint that pushes numeric value when update made.
For example - message.payload = 799.
What I want is on every new message compare this new value with the previous one (the one that was received right before) without any external storage.


Solution

  • Look at the Report By Exception (RBE) node. This will only allow a value to pass if it is different from the previous value (it can be used with multiple inputs and uses the msg.topic to distinguish between variables to track).

    You can also use the Context to store values. There are multiple levels of context that are available at different scopes to allow you to store and share information between nodes.