johncassell
Posts: 5
Joined: Mon Nov 30, 2015 11:18 am

AC Power Outage Monitor

Mon Nov 30, 2015 11:26 am

Morning everyone, I have been interested in Raspberry Pi for a while but have yet to find a suitable project to warrant purchasing one but now I have (purely because I can't seem to find an 'off-the-shelf' item that does this).

I'm looking to record when our AC power has been lost and recovered. It doesn't need to be too fancy where it sends an SMS/Email when it happens. Its totally fine if I have to physically get hold of the device and by however means, be able to see the following basic information

30-Nov 11:23 Power Restored
30-Nov 11:23 Power Lost
29-Nov 10:01 Power Restored
29-Nov 09:58 Power Lost

There are a few posts out there discussing this but they seem to be going further than I need. As I am an absolute beginner, I'd like it to start off as simple as possible (I could then look at adding SMS/Email etc.. later when I'm more comfortable).

Would someone be able to guide me in the right direction on this (perhaps some specific info or a link to a forum post I may have missed that does exactly what I need)?

Thanks in Advance.

John

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: AC Power Outage Monitor

Mon Nov 30, 2015 2:57 pm

How do you plan to power your Raspberry when the mains power goes out?

It's easy to record when your RPi boots and how long it runs between reboots.

sudo apt-get install uprecords

Which gets a display like:

Code: Select all

pi@aplus /var/spool/uptimed $ uprecords
     #               Uptime | System                                     Boot up
----------------------------+---------------------------------------------------
     1    18 days, 23:39:29 | Linux 4.1.6+              Mon Aug 24 10:36:29 2015
->   2    16 days, 15:55:18 | Linux 4.1.13+             Fri Nov 13 23:00:11 2015
     3    15 days, 09:58:06 | Linux 4.1.12+             Thu Oct 29 01:22:30 2015
     4    12 days, 15:47:39 | Linux 4.1.9+              Sat Oct  3 10:01:44 2015
     5    12 days, 03:14:22 | Linux 4.0.9+              Sat Jul 25 17:15:43 2015
     6     8 days, 07:14:12 | Linux 4.0.8+              Fri Jul 17 10:01:10 2015
     7     7 days, 16:59:56 | Linux 3.18.14+            Sun May 31 01:00:17 2015
     8     7 days, 11:00:33 | Linux 3.18.11+            Tue Apr 21 11:00:22 2015
     9     7 days, 03:59:29 | Linux 3.18.14+            Sat May 23 21:00:40 2015
    10     7 days, 01:05:45 | Linux 3.18.10+            Tue Mar 31 12:58:42 2015
----------------------------+---------------------------------------------------
no1 in     2 days, 07:44:12 | at                        Wed Dec  2 22:39:39 2015
    up   244 days, 20:54:46 | since                     Sun Mar  8 19:21:37 2015
  down    21 days, 22:39:06 | since                     Sun Mar  8 19:21:37 2015
   %up               91.776 | since                     Sun Mar  8 19:21:37 2015
 As at                      |                           Mon Nov 30 14:55:28 2015
  Host name: aplus Serial:  000000005b592f7f

pi@aplus /var/spool/uptimed $
Note: I'm running a locally patched version. I've added the "As at" and "Host name" lines to the output.

The data is stored in a file /var/spool/records with dates/times and versions. You may be able to use that for your own purposes.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
mikronauts
Posts: 2794
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: AC Power Outage Monitor

Mon Nov 30, 2015 4:08 pm

Add a cheap UPS that has a USB data port.

I use inexpensive APC 600VA units on some of my Unix computers, it allows for a safe shutdown and optional notification email.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: AC Power Outage Monitor

Mon Nov 30, 2015 4:37 pm

mikronauts wrote:Add a cheap UPS that has a USB data port.

I use inexpensive APC 600VA units on some of my Unix computers, it allows for a safe shutdown and optional notification email.
I'd agree wth that. I bought a S/H UPS from ebay that gives my home monitoring/control system 2 hours backup power.

johncassell
Posts: 5
Joined: Mon Nov 30, 2015 11:18 am

Re: AC Power Outage Monitor

Wed Dec 02, 2015 1:10 pm

Hi all, thanks for the replies - I don't need the device to remain powered when the site power goes down.

We have an area of the site that hosts about 5 devices (CCTV systems and other bits) and I get an email when they don't reply to pings from the network. We continually get emails saying 'device not responding 11:01' then a minute or so later it comes back online. I can't tell if the network cable is faulty or it is the power.

The sudo apt-get install uprecords option sounds like my best bet. Whenever the main devices drop from the network I could grab the pi, plug it into a monitor, run this command and see that the device rebooted at XX:XXAM/PM.

The UPS with USB recording would have done the job perfectly I would imagine but I am looking for any excuse to get one of these pi's (this project will be the first of hopefully many going forward!)

So, with the simplicity of what I need, could you recommend which pi to get please? I'm sure the original one will work but perhaps for the difference in cost, it would be recommended that I may as well go up a couple of models?

Thanks
John

johncassell
Posts: 5
Joined: Mon Nov 30, 2015 11:18 am

Re: AC Power Outage Monitor

Wed Dec 02, 2015 1:34 pm

Just read that the pi doesn't have a real time clock and will then presumably reset to midnight whenever the power is down. Is the only option to purchase a real time clock add on component if I want to see exactly when it powered off?

Thanks
John

Return to “Beginners”