Lights back to old_state and brightness possible?

I have built my own home security in Node-RED. -> IF a door is opened, nobody is home and it is dark outside THEN all the lights go on with 100% brightness. Also a input_boolean_alarm goes from off to on

Ok, thats works fine. But now i want the lights go back to the previous state and/or brightness when the input_boolean_alarm goes from on to off. I am looking for a solution for days now but I cannot get it

someone who can help me with this or is this not possible?

If you are using Home Assistant V102 can you not create a scene on the fly to save the state of the lights before firing the alarm and then restore their state using the saved scene afterwards.