Consider a battery-backed lighting system:

The lights run on 24V, an AC adapter provide 25V, a stepped-down 30-odd V battery provide 24V.
Due to diodes in series, when AC power is present the battery does not provide any power and does not back-charge either:

If AC power goes out, then the same diodes allow the battery to power the lights without feeding back through the AC adapter:

Makes sense so far, and is as simple as it could be.
But you might have noticed that the battery is not charged from anywhere.
What i want to is to hook up the (36V DC) charger to the same 24V bus (with suitable step-up converter), to be powered by the surplus from the AC adapter.

However, if the power was to go out, then the charger would try to pull it's input from the same battery it's trying to charge:

This would then attempt to produce large amounts of free energy, which is strictly illegal in this universe.
So, the question is - how do you connect the charger to the same bus?
I can think of some straightforward solutions, like an AC relay opening the line to the charger when AC goes away.
Or even less straightforward ways that would allow you to call the whole design
Arduino-powered.
However, i can't shake the feeling that i'm missing some very simple solution.
It being 3AM here does not help.