Smart bulbs power outages

I have the same problem. I’m thinking about using this script:

to save the state of lights every x minutes and some sort of outage detection (perhaps pinging, or better yet looking for a device uptime) to trigger a restore state. The lights will still go on, but hopefully turn off in a minute or two.