Power Outage Monitor

It’s been quite a while since my last project, so in order to gradually get things moving again, I came up with this simple project built around the PiJuice.

The PiJuice HAT is a portable power platform for the Raspberry Pi, opening the door to self-powered and portable projects. It was launched on Kickstarter over two years ago, and after the team faced various problems, the hardware is finally shipping.

The guys at PiSupply were kind enough to send me a review unit, including solar panels, to play around with.

Unfortunately, there’s not much sun in the winter, so I came up with an indoor project to tackle issues I am experiencing at home: random power cuts. As with any similar problem, being able to log the frequency and duration of such events could potentially reveal patterns, helping to find the root cause of the issue. The idea is simple: whenever a power cut would occur, the PiJuice would keep the Raspberry Pi running during the outage and keep track of the start and end of the power cut by logging everything to a simple CSV file.

Let’s take a closer look …

Useful Links

Before we start, here are some links you might find useful.


Various members of the Raspberry Pi community have posted their review of the PiJuice, check them out:


To get an estimation of how long the Pi would last on battery power, you can make use of the PiJuice Battery Discharge Time Calculator!


Alright, let’s dive in the details of my little project.

There are three components to this project:

  • Raspberry Pi A+
  • PiJuice HAT
  • PaPiRus HAT

I’ve picked the Raspberry Pi A+ for two reasons: it has the same form factor as the PiJuice, and it’s rather low power, comparable to a Raspberry Pi Zero.

The PiJuice HAT is in charge of keeping things running during the power outage. When an outage starts, the current time is stored, and a timer is started until power is restored. This data is then stored to file. Of course, the solution will not work for extremely long outages, as the battery would run out. But for smaller outages, it should work great.

Finally, the PaPiRus is used as a low power display for local reporting and the ability to trigger some actions via its buttons.

This slideshow requires JavaScript.


Raspberry Pi

Preparing the Raspberry Pi for any project, starts with the same steps: flashing the OS to an SD card, updating the packages and performing some configuration.

I’ve written a generic procedure that can be found here: Headless Raspberry Pi Setup with Raspbian Jessie

For this particular project, as the Pi won’t be connected to an HDMI screen, I’m using the Jessie Lite (no desktop) image.


Installing the base software for PiJuice is super easy, and can be done as follows:

The software can do a lot (just check the documentation, it’s impressive), but because this is a headless project, I’m using the Python API only.

There’s one value required for this project: whether the PiJuice is operating from the power supply or the battery. This information can be retrieved from the GetStatus() call:

The parameter relevant for this project, is called “powerInput5vIo”:

Isolating that value from the others, can easily be achieved as follows:

The will return PRESENT or NOT_PRESENT.


Again, it doesn’t get any easier than this. Running the following command will set up the software for you:

To control the display and make use of the buttons to have different screens and functions, I’ve reused some bits of code from my Pi Zero ePaper Badge.

The following functions have been assigned:

  • Button 1: display the power source status and keep track of downtime
  • Button 2: turn the wifi on and off for power saving
  • Button 3: future use
  • Button 4: future use


The PiJuice is a great add-on for the Raspberry Pi, and this simple project is merely scratching the surface of what it can do. It’s super easy to set up and does a great job at keeping the Pi running for quite some time. Works as advertised!


A demo log generated during testing:

Which can be imported in a spreadsheet program to create a chart:


Here’s the full code for this power logger. It’s not pretty, but it gets the job done and hopefully gives you some ideas for a project with your own PiJuice.

6 thoughts on “Power Outage Monitor

    1. It’s probably redundant indeed.

      I was having trouble displaying data and thought some Text components might be stacked on top of each other. So in a desperate attempt, I wanted to make sure the placeholders were removed as well.

  1. I was considering an “end of the world” monitor.
    It would detect information from sensor and decide if the end of the world is likely.

    If there is no power it is the start of a problem.
    If there is also no wifi signal (or internet connection) then maybe it is the end of the world (at least by kids definition).

    Other loss such as no LoRa signal or no GPS signal or no GSM signal could be interesting indicator.
    Detection from radioactivity could also be fun.

Leave a Reply

Your email address will not be published. Required fields are marked *

© Frederick Vandenbosch, 2014-2018. Unauthorised use and/or duplication of this material without express and written permission from this blog’s author and owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Frederick Vandenbosch with appropriate and specific direction to the original content.