Remember state of light after services has been called

Hi all,

Sometimes I have a wiz light becoming “unavailable” and have setup a flow in nodered which checks the state of the light (ex. kitchen wiz 1, 2, 3), then shuts off a sonoff switch and turns it on again after a bit of time. These 3 lights are in a group called “kitchen spots”. However, when I turn on the sonoff switch the lights will turn on.

Picture of my node-red flow:

Is it possible to somehow know and remember the state of any of the lights, so that it if lights 1 and 2 were off and 3 was unavailable, that they stay off after the reset? I can’t seem to figure out how node red can “remember” the state of an entity. Of course, it would be great if it could also “remember” or “know” that fx. if lights 1 and 2 were on, then it should be turned on when it’s done restarting.

I have searched for possible ways to ‘transfer’ the entity state along the flow, but I can’t get anything to work.

Thank you all very much in advance - please let me know if you need more information, if I completely butchered the explanation or anything else.

The builtin functions of Node-Red for storing data: