I am going to do a Raspberry Pi project and in order to know some system status I am going to have a GSM module to send text messages. In order to avoid power cuts (for example in a storm) I have a PowerBank to supply power. The point here is that I need to know if that happens and send a text message with the GSM telling me that. I don't know if there is a way to know if the RPi is getting power from the PowerBank or from the general home power to know if there is some problem with the home power and send the text message.

If you know other ways to do this I will appreciate it too!


It isn't possible using a "PowerBank" type device - they may have an LED display showing the state of charge but they don't (as far as I know) tend to make the information accessible to the connected device.

What you want a similar but more sophisticated bit of kit called a Un-interruptable Power Supply {UPS}, not only do these charge their own battery whilst connected to the external supply they will also supply power to the connect device. Most "Power-Banks" cannot charge themselves and supply power simultaneously.

There are UPS units for things like the RPi, I use a second hand UPiS originally from PiModules but I've not been impressed with the delays in firmware updates and others have had long delays in product shipments. There have been/are several projects to Kickstart such product and some have reached a production stage - as this isn't a forum for shopping recommendations I won't go on but there are such things out there.

Like the larger products designed for use with PCs most UPS devices do have a means to at least warn a connected device that the power is about to run out so the latter needs to shut-down now; more advanced options are sometimes available and monitoring the instantaneous voltage/current/state of charge (I was trying to avoid the confusing expression "current current"!) and how long the supply will last if on batteries are typically amongst what can be found out. My UPiS provides some of these, including the current drawn (including the battery charging current) via either the RPi Serial port/ it's own external micro-USB power inlet or via the RPi I2C bus - it also uses a dedicated GPIO pin with a simple monitoring python script to tell the RPi to tell the RPi to shutdown as soon as that Pin is pulled to ground by the UPiS.


  • If you can tap into the supply into the "PowerBank" or if you have a spare low-voltage (somewhere between 3 to 24 Volts) "wall-wart" you could use a pair of resistors to divide the output from that down to a 3.0V level and feed that - with the ground connected to the RPi ground (if you are tapping into the supply into the PowerBank this requires that the power bank has a common ground and any switching is done on the +5V side of the USB lead used to convey the power to the RPi) to a GPIO pin so that when the Mains "fails" and the smoothing capacitors in the Wall-wart have discharged the level will fall towards ground and at some time after the Mains Power has gone the voltage on the GPIO will also go to a logic low level which the RPi can detect.

  • If the PowerBank has an LED which is always illuminated when power is supplied to the unit - or if you have some other item nearby that has such an LED or other light - it ought to be possible to make a home-made "opto-coupler" involving an optical sensing device that connects to a GPIO pin and detects the light and when it goes out will send a signal (3.3V to 0.0C or vise-verse) to that GPIO pin...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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