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: