You may not be able to read how many batteries are currently in the train, but you can count how many drained ones came out and only put that many back in. Which can be done with 2 combinators.
Here's a blueprint: https://pastebin.com/ycVBUVKc
Check the locomotive in the blueprint for stop conditions. You don't have to have the charger right there; you can replace it with belts or chests or whatever.
I haven't gotten to space trains yet in my actual game, but I did notice and appreciate that the batteries have the same energy density per stack as all other fuel sources (except nuclear, which gets a slight boost for the sake of the 1.21 GJ joke), so I don't feel like more energy density is really necessary especially since there's already an option to double it in the settings. Plus, an extra layer of management like this is very on-brand for SE.