Time since last state change?

(node-red newbie)

Okay, great so we can calculate the lastChange time.
But where do I put the calculation

(var lastChange = Math.floor(msg.data.new_state.timeSinceChangedMs / 1000);

in a function node, template node? How do I use it?

Probably a very dump question but its not obvious if you are a beginner like me…