Input_number previous state [Solved]

Hi all,
I need help figuering something out if its possible.
What i want to do is to make a flow that is triggerd when i change the input_number slider in HA and what i want to do in that flow is to first subtrack the new state with the previous state and send the result forward.
Example: If i change the slider from 10 to 5 (5-10=-5) I want the payload -5 to go forward.

Anyone know if it is possible?

I don’t use Node Red, but the state_change event that Node Red uses to indicate a change in an entity includes the old and the new data. So, most likely, Node Red’s payload does too. I’d pump the data into a debug node and see what pieces are available. If you have the old and new data present, a simple function node could subtract the two and send that on the chain.

You are right, I didnt see that I got it in the debug node cause I hadnt checked the box to recive all data. Will try to make a function node.

Thanks!

Edit: Made it work with this code:

var newMsg = { payload: msg.data.new_state.state - msg.data.old_state.state };
return newMsg;