That was off the top of my head.
I've done similar things in the past.
I'll knock up a sample tomorrow.
In the mean time, read up on persistent context - I suspect that is all you really need.
"Working with context : Node-RED" Working with context : Node-RED.
"A guide to understanding 'Persistent Context' - General - Node-RED Forum" A guide to understanding 'Persistent Context'