When I first wrote this, I was trying to find a better way to know that the power went out and/or came back on. There is flag on the hub is “on battery power”, but besides not finding any way to get that property in directly in the Groovy IDE, I realized it won’t help my situation, as the internet is out when the power is out. By the time the internet is connected and the script runs, the flag is back to false and the app doesn’t know it changed.
I think this app performs more consistently when internet goes down with the power. By the time the internet connects and app runs, the bulbs are connected. It the internet is up during a power failure, it’s a crap shoot.
You can probably add a delay in the checkRestore routine before it does the restoreState and that may solve the issue.
If I get a chance to play with this I will see what I can do, but I haven’t had a chance to mess with any of this in a few years…
I took a quick look and changing the checkRestore to this below should do the trick. Add the the runIn to the restoreState. I’m guessing 15 seconds would be more than enough delay, but you might have to mess with that. Change the number on the runIn call from 15 to the number of seconds you want. Hope this helps.
I’ll give that a try. But my guess is that if bulbs other than the canary bulb re-connects to the hub then the saved state ends up being not what it was when the power goes off. And thus when the restore happens it comes out wrong.
For example:
Bulb A is off.
Power goes off.
Power comes on.
Bulb A reconnects saying it is on.
Canary connects.
Restore runs, but Bulb A is believed to have been on before power off.
I have tried some various timing or delays, but so far no luck.
I’m wondering if maybe not subscribing to the bulbs but rather just do a poll every minute or so. One could still have a situation where the timing was just right (or wrong) and get a false restore. But that would probably be a rare occurence. I’m not sure on the bulbs if all of them support polling or not. I read where this may not be the case.
In any event, the best scenario is to somehow detect the power off when it happens rather than when it comes on. I have a couple ideas on hardware to do this, just haven’t worked it all out yet. And whether its worth all that much trouble. I have a trigger in Echo to turn off all the lights, so when it happens I can always use Echo to do it. Just not as wife friendly.
Another thought. I wonder if doing a refresh on the bulbs every so often to get the current state would work rather than doing a subscribe? Then hopefully the canary bulb status would update before a refresh was done again.
I just checked and I see where you do a refresh. I might try disabling the subscribe and see what happens.
I hadn’t thought about the subscribe tripping things up. Not sure what a refresh gets as a status if there is no response from the bulb. I didn’t test that.
The app was written with the expectation that internet is down when the power is down. Having the internet up kinda shoots itself in the foot!
A concept as simple as “set my lights the way they were” shouldn’t be this complex. Keep us posted if skipping the subscribe helps.
I tried to follow the directions for this, but it seems the site has changed since they were made. Does anyone have updated instructions? I have no problems sleeping through the lights coming back on after an outage, my wife on the other hand. . .
So from what I read, you installed a lamp with a smart bulb in it, that is plug in an outlet, but always off. Then when a power outage arrive, that bulb will turn on when the power is back, so that will trigger an automation to turn off all the light in the house, I understand correctly?
But I suppose that this process could take some time ? Since the light turn on before the ST hub is back on, what is the possible delay ?
I will test this solution of yours, hopefully everything will work out here at home too. Here I have Gledopto led strips and Gledopto GU10 lamps.
I was wondering if there is a possibility to make a SmartApp for some ZigBee sockets that I have. Every time I have power outages when the power comes back on, the sockets are turned off, so I have to manually turn them on one by one. I was wondering if you could make a solution based on that same app, where when the light turned on, you also turned on the sockets.