Raspberry Pi Electricity Monitor

FORTH UPDATE: I gave a talk on this project at HN London. Here is the video:

THIRD UPDATE: I gave a talk on this project at HN London. Here are the slides:

SECOND UPDATE: I won a competition with this project: http://www.raspberrypi.org/archives/3562

UPDATE: Interactive example graphs now at jpsingleton.github.com.

I’ve built a system for monitoring the electricity consumption of my home with a Raspberry Pi.

I bought a wireless electricity monitor from Maplin. It’s one of the standard affairs which has a transmitter with a current clamp that you put around the main in-feed and a portable display unit. However, this unit has a serial connection (accessible via an RJ45 socket) which allows you to download live and historic data to a PC.

There are limitations though; the on-board memory only stores daily totals and the windows software that comes with it is awful. So I reverse engineered the communication protocol and built my own logger. A Raspberry Pi was a great choice for the host machine as it would be far too ironic to leave a power hungry PC on to monitor electricity consumption. I have a plug in power meter and have measured the draw of the whole system as negligible (barely a few watts). Here is the whole system (the Pi and receiver obviously don’t always have to be next to the transmitter). The cable was excessively long so I shortened it by crimping on a new plug.

Pi power

The Pi power monitoring system

Parts list (hardware):

  • Maplin wireless electricity monitor
  • Raspberry Pi
  • Micro USB power supply
  • SD card (mine is 32GB high speed but 2GB would be fine)
  • WiFi adapter (optional; you could just plug it into your router)
  • Case (optional; but it looks nice and stops shorts)


How to get up and running:

  • Install the Apache web server with apt  (sudo apt-get install apache2)
  • Install http://pyserial.sourceforge.net/ with apt (sudo apt-get install python-serial)
  • Download the repository from github (https://github.com/jpsingleton/Raspberry-Pi-Electricity-Monitor)
  • Copy the www folder to /var/www
  • Copy the python file to anywhere you want (e.g. home folder)
  • Plug in the receiver (the USB serial driver should already be present)
  • Execute “sudo python raspberry-pi-electricity-monitor.py &” (add this to /etc/rc.local to run at boot)
  • Visit your Pi in a browser to see the data (visit raw.html to see the noisy data)

The system has a sample period of 7 seconds as the transmitter only broadcasts this often to save power. This still results in far too much data to render (after a few days) so the software filters out the noise to reduce the data points. Future plans include using the ADC and micro-controller on my self assembled Gertboard with my new Pi to achieve a much higher sample frequency.


Gertboard with current clamp

FYI soldering zero ohm surface mount resistors is a real pain. Why Gert couldn’t have just used wire jumpers I don’t know.

Below are some screen-shots of the graphs that are produced by the system. This first image shows the filtered data over 5 days.

Filtered plot over 5 days

Filtered plot over 5 days

This next image shows a zoomed in portion of the 1st plot. You can see the thermostat in the oven on the left, an electric heater in the centre and the washing machine just after.

Filtered plot

Filtered plot over 2 days

This is a raw version of roughly the same region with the noise shown.

Raw plot over 2 days

Raw plot over 2 days

Here it is zoomed in to a high usage region where the electric oven is in use.

High usage raw plot

High usage raw plot

Here is a low usage region. You can clearly see the compressors of the fridge and freezer. Occasionally the inrush current of the motor shows up.

Low usage raw plot

Low usage raw plot

Thanks to http://dygraphs.com/ for an awesome library and http://www.raspberrypi.org/ for the great hardware.

P.S. The dygraphs library is also used at shutdownscanner.com (which is a service for monitoring how many computers have been left on out of hours). If you want to play with the interactive features of the graphs or see some of the more advanced interface options then take a look at the example dashboard.


I’ve started using GitHub to share my code, although I’m more of a Mercurial person and even use TFS when I have to. You can find it all at https://github.com/jpsingleton and there is even some stuff on there that didn’t warrant blogging about that you might like.

London Tube Status – Updated

I’ve updated the mobile London tube status at http://unop.co.uk/tube/ by tidying the code up a bit and using the official API. The code (PHP/XSLT) is on GitHub at https://github.com/jpsingleton/London-Tube-Status.

There is also a version for HTML5 smart phones which uses jQuery Mobile, but this is still a work in progress. https://github.com/jpsingleton/HTML5-London-Tube-Status or http://unop.co.uk/tube2/ if you prefer to try before you view source.

Spotify Playlist Generator

I’ve made a Spotify Playlist Generator that uses Last.fm to find songs by similar artists.

Download the Playlist Generator or as a zip with the instructions.

It’s Windows only (for now) and it requires the .NET framework v3.5 or greater.
The source code is available under the GPLv3 if you would like to build on it.

Playlist Generator Screen Shot

Playlist Generator Screen Shot


  1. Enter an artist’s name in the artist box.
  2. Click the button and wait until completion.
  3. Select all of the links then drag into a Spotify playlist.

Listen and enjoy!

Select a few tracks and paste the Spotify track links into the large box. Leave the artist box empty and then click for a compilation.

Super Advanced:
The generator will try to auto detect your region but you can override it and other settings. Create a shortcut to the executable, go to the target in the properties and add the 2 character ISO country code after a space: e.g. PlaylistGenerator.exe GB. You can also modify the maximum number of artists: e.g. PlaylistGenerator.exe GB 49. And even the maximum number of tracks per artist: e.g. PlaylistGenerator.exe GB 49 3. If you modify these then they are displayed in the main window when you first run it.

Thanks to http://www.doogal.co.uk/spotify.php and http://code.google.com/p/lastfm-sharp/

“This product uses a SPOTIFY API but is not endorsed, certified or otherwise approved in any way by Spotify. Spotify is the registered trade mark of the Spotify Group.”

MonitorES (Energy Saver) Tool

I came across this tool and think it’s awesome. I’ve been using it for a while and it works well.

MonitorES is a small windows utility that turns off your monitor when you lock your machine. It can also pause all running media programs and play when you return.


Alternatively, there is MonitorES Lite for low end & corporate machines which only has the turn off monitor feature and is also available as an MSI for easy deployment.

Outlook 2010 Email Delayed Send

Ever sent an email then instantly regretted it or hit Ctrl-Enter when you actually meant to hit Ctrl-K (check names)? You could just add a gibberish recipient to a draft email to prevent it sending, but there must be another way. Here is how to add a delay so that an email stays in your Outlook outbox for a minute before being sent.

From the Rules button on the home tab of the Outlook ribbon click Create Rule… then follow the pictures.

Remote Desktop Max Connections Fix

If you have the problem of not being able to log onto a server because it has exceed the maximum number of connections (usually 2) here is an easy fix.

Open a command prompt and type:
query user /server:{YOUR SERVER NAME}

You will get something back like this:

user1   1 Disc none 2011-03-10 20:25
user2 rdp-tcp#121 2 Active 6 2011-03-20 11:29

You can then either ask the users to log off or you can forcibly log them off by typing:

If the query user syntax doesn’t work (e.g. Win XP) you can type:
qwinsta /server:{YOUR SERVER NAME}

Home-made Soldering Iron Holder

I made this soldering iron holder a while ago. Here’s how to make one yourself from things you probably have lying around. Much cheaper than a bought one and more fun:

You will need:

  • An old hard drive
  • A wire coat hanger
  • A kitchen sponge
  • Assorted tools


  1. Gut the hard drive and keep the cast base
  2. Cut and straighten the coat hanger
  3. Wrap coat hanger around a shaft to form a coil
  4. Attach hanger to base through existing holes
  5. Solder end of hanger to form a closed loop
  6. Cut sponge to size (smaller as it will swell when wet)

Here are some pics:

Bank Holiday Calendar File

The next 2 years are a bit special, as in the UK we get a couple of extra bank holidays (Royal Wedding and Diamond Jubilee). However, a lot of calendar software doesn’t realise this.

I’ve put together an iCalendar (.ics) file from the dates on the official page of the bank holidays for England and Wales. Download it and import into whatever you use (Outlook, iCal, Google etc.).

Energy Saving Plug and Water Widget Review

I applied for a free Energy Saving Plug and Water Widget through a government sponsored scheme and here are my thoughts.

Energy Saving Plug

“Households in the UK now spend around 10% of their electricity bill on standby power annually, with the average household having up to 12 gadgets left on standby at any one time (source: Energy Saving Trust). Leaving items on standby wastes energy and money…”

I was very satisfied with the plug although there are some caveats:

  • It’s not suitable for use with broadband modems;
  • Should not be used with a PVR/Sky+/HD box etc.;
  • The appliances need to be close together; and
  • You can’t switch it more than once a minute (to protect the items).

The plug was not very complicated to install and after a while you don’t notice it anymore. It just works. I’ve fitted it to our lounge entertainment system so it can be remotely switched off. This also makes for an excellent prank if you don’t like what’s on!

I have a meter fitted to the socket and to the main feed so I’ll monitor if the draw of the plug is outweighed by the power saving from the off appliances.

Water Widget

“One fifth of a household’s carbon footprint already comes just from heating water (source: Act On CO2). This clever gadget takes less than 5 minutes to fit and reduces the amount of water used by up to 70% whilst still maintaining the performance of your shower…”

I’ve fitted the Water Widget to my shower which was very easy. It works by sucking air into the water feed which aerates the water and reduces the amount of water used whilst maintaining the same volume of fluid. Water didn’t flow out of the hole indicating that it is appropriate for use with my shower as the flow rate is high enough. The flow rate of my shower has not been reduced, but it does make a different sound now (which spooked my housemates).

We don’t have a water meter so it will be hard to measure the flow. I can monitor the gas meter to see if heating less water reduces the amount of gas we use, but it will be difficult to isolate the data from the increase due to the bloody freezing weather lately!

For more info check out: http://www.littlefoot.co.uk/