With 40 minutes reported, that means roughly 20 minutes before the batteries are starting to accumulate long term damage. I'd set it to start shutting down after 10 minutes on battery at most, preferably 5 minutes. That way you leave margin for possible repeat events in one day, for example if the power goes down, comes back a couple hours later, then goes down again, you should have enough battery to safely shut down. The alternative is to allow enough time after the power comes back to fully recharge, which typically is about a 10 to 1 ratio, if you are on batteries for 20 minutes, it's going to be at least 200 minutes of power to get back to full charge. Ideally you never want to drop below 50% battery.