Automatic switching to battery on mains failure?

So what happened? I want to do something similar...