Automating such a narrow edge-case seems totally pointless. A much more likely scenario is that your battery dies while you're out, in which case you're still screwed.
A better tried-and-tested real world solution that covers all scenarios is a simple key safe.