Saving a msg.payload and than comparing the new msg with same topic later on

Hello NodeRed community!

I am still kinda NodeRed newbie and I would appriciate some help here.

My situation is:

My messages from devices are identified via msg.topic which equals to mac address of particular device.
I want to store msg.payload.interface (one of payloads attributes) latest value. When new msg with same topic arrives, I need to compare its interface value with stored (latest) value.

Basically I need to evaluate if msg.payload.interface has changed for same topic. Any tips how to do this in steamless fashion?

Thanks!

The Filter/RBE node can be set to handle multiple topics - so if the payload isn't too complicated it can probably handle it... but if any other values of the payload change then you would need to do an extra step - eg use a change node to set msg.interface to msg.payload.interface and then send to the filter and test msg.interface.

Or you can store the value you wish in a context var, then compare then store new to context.
e.g.

[{"id":"5fd04de4.af31e4","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1234","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","x":80,"y":1020,"wires":[["10adbeec.549b39"]]},{"id":"10adbeec.549b39","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"previous","pt":"msg","to":"interface[msg.topic]","tot":"flow"},{"t":"set","p":"output","pt":"msg","to":"$$.previous = $$.payload.interface","tot":"jsonata"},{"t":"set","p":"interface[msg.topic]","pt":"flow","to":"payload.interface","tot":"msg"},{"t":"move","p":"output","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1100,"wires":[["8384a06e.08c0f"]]},{"id":"65d3e2b3.f75f44","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"12345","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","x":90,"y":1080,"wires":[["10adbeec.549b39"]]},{"id":"6a3a8b54.81785c","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1234","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","x":70,"y":1140,"wires":[["10adbeec.549b39"]]},{"id":"2200c8aa.6da738","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload.interface","v":"1235","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","x":70,"y":1180,"wires":[["10adbeec.549b39"]]},{"id":"8384a06e.08c0f","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":1120,"wires":[]}]