Issue with lights after restoring dynamic scenes

Hey everyone, I’m looking for some assistance with a script. I have scripts that capture the current state of lights using scene.create then at the end of the script it fires that scene to restore the state of the lights and lastly deletes the scene it created. The issue I’m facing is if the lights were originally off in the captured state and say the script involved the flashing of lights. Home assistant will often see these lights as still in an on state, even after the restore scene has fired to turn them back off.

Has anyone else ran into this and found a solution?