Save color and brightness of a light whenever is changed. Apply last color and brightness after an automation changed them

I would create a scene when the light is turned on or changed and apply the scene after your other script runs.

See this thread: