It can be long discussion, because there is no single solution around this, so, to cut the story short, I will tell where I stuck on my way.

It is AndroidAuto (media centre in car on raspi) project I'm currently working on, and I'm stuck on effectively powering raspberry and safely shutting it down when ignition is on/off.

Initially, I went with mausberry solution circuit, that takes 12v const/ignition/ground from car battery on input, takes care of voltage conversion and triggers safe shutdown in the event of ignition goes off. But mausberry didn't supply the circuit, so when I fed up to wait I decided to go UPS route.

I use, one of them, Geekworm (geekworm.com) UPS HATs (+ separate unit for 12v-to-5v conversion) that goes over Raspberry GPIO, takes ignition as power source, charges its battery and in parallel powers Raspberry while ignition is on. When ignition goes off, Raspberry stays on and battery on UPS starts discharging.

At this point I need to trigger safe shutdown, so that no electronics draining my car battery.

Geekworm UPS HAT, also, have annoying switch that has to be pressed to give power to Raspberry, which I don't need as I want to start Raspberry when ignition turn on. This is possible to overcome by just using a micro usb splitter that will go into UPS and Raspberry from ignition power source. That is stupid solution to my view, so if anyone can help with more elegant solution, I'd appreciate.

  • How do you tell when the ignition is off? It sounds as if power is still provided to your Pi at that point, based on your "...so that no electronics draining my car battery" comment.
    – larsks
    Jan 16, 2019 at 15:00
  • when you turn the key ignition, you get 12v, when turn it turns off. Sorry, maybe I misunderstand your question.
    – EKreger
    Jan 16, 2019 at 15:15
  • It is not clear if you are asking specifically about this Geeworm HAT, or more generally. The UPS Pico works fine for me. The way it works is the sw needs to check some register (IIRC), but this can be done once a second or whatever.
    – Tomas By
    Jan 17, 2019 at 5:48

2 Answers 2


If you're feeling handy, I'm actually in the middle of building something that meets almost the same requirements. In my case, I have a Pi running RetroPie that is powered from the USB port of our television. I want to ensure that the Pi shuts down cleanly when the TV is turned off, and I would like it to boot up automatically when the TV is turned on.

I'm solving this by using an Adafruit PowerBoost 1000c, which is a "load-sharing battery charger" -- that is, it will both power your Pi and charge a battery at the same time, and if power is removed it will use the battery to power your Pi. That's handy, but by itself it doesn't implement the necessary logic to meet my needs so I've written some code that runs on an ATtiny85 to make up the difference.

You can find the code and a brief description of things at https://github.com/larsks/pipower. It's a breadboard and a bunch of wires on my desk right now, but it seems to be working so far. I just got things working earlier this evening, so the documentation leaves a lot to be desired.

  • This definitely could be a solution for someone, but in my case I don't use micro controller that I can program. UPS PI HAT just sits on GPIO of Raspi and I can only talk to HAT via Raspi getting some basics out of it, like current voltage and battery capacity.
    – EKreger
    Jan 17, 2019 at 8:26
  • If this project sounds interesting to anyone, I put a little write-up together at blog.oddbit.com/2019/01/19/pipower-a-raspberry-pi-ups.
    – larsks
    Jan 20, 2019 at 21:30

I believe this is the same (Chinese) board: UPS HAT

Apparently there is no simple way to determine whether you are running on power (ie car battery) or the UPS battery.

1.Is there a way to know if the battery is being charged or not?
There is no direct way to know if the battery is being charged or not. BUT
you can get many time volatage in a short time, then judge the volage value.
For example: In 20 second, we get the 20 volatage value: 5.11v,
... thus we can know the battery is charging. because the voltage value is raising

So you probably need to do something like this and then call the shutdown command.

If you follow this link, there seems to be some sw solution to the power-on problem, but I do not know anything more about that.

  • Tomas, thank you. I've read about this solution, and currently it is my only option. Although, may be there is a simpler solution, i.e. figure out that micro usb stop delivering power to the socket and switches to GPIO power, where UPS is providing power, maybe?
    – EKreger
    Jan 17, 2019 at 8:14
  • @EKreger: I think your split cable sounds perfectly fine. This is not something you want to worry about too much.
    – Tomas By
    Jan 17, 2019 at 8:20
  • To be fair, there is another solution that I found recently, which is using Network UPS tools (NUT) or APC UPS (apcupsd), which apparently should run a driver that will talk to your UPS, run as service and is widely configurable. The problem with this solution is that I don't know if NUT or APCUPS will support my UPS hardware.
    – EKreger
    Jan 17, 2019 at 8:32
  • @EKreger: quick googling suggests those run over network, so no probably wont work.
    – Tomas By
    Jan 17, 2019 at 9:28
  • Not sure what you mean by that! The sufficient article I found is here: melgrubb.com/2016/12/11/rphs-v2-introduction Cannot see why this won't work for my purpose, except the fact that it could not support my UPS HAT hardware.
    – EKreger
    Jan 17, 2019 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.