There is a smartapp that handles this sort of thing, but I don’t know if it is still maintained or not though: [RELEASE] SmartBulb Power Outage handler
The other option is to use something like webCoRE to trap events from hub power source and set the lights to their previous values when the hub goes from battery back to mains power.