How I created my home energy monitor

My power use

The target

First things first – I’m in Ireland. The UK/Irish power system of 220V meant I had to go for a compatible power monitor. So I was out of luck with all the energy monitors I’d been reading about for the USA (T.E.D. The Energy Detective, Cent-a-meter, Blueline etc). I settled on the CurrentCost in the end, because it had a great community of people developing software.

So I bought a CurrentCost off the manufacturer’s ebay store, along with a serial to USB data cable I’d use to grab the data.

Setting up the CurrentCost is remarkably simple. Just plug the device in, attach the sensor to your electricity supply and you are done. Couldn’t be easier!

CurrentCost Monitor

CurrentCost Electricity Monitor

Having a real-time data output is great, but to be truly useful you really need to build up a history. The CurrentCost itself will save bi-hourly averages for up to 31 days, daily averages for up to 90 days and monthly averages for 7 years. Averages every couple of hours are OK, but it won’t show you the effect of turning off that light, or unplugging that TV. For that we need more data, and fortunately the CurrentCost updates every 6 seconds, as long as you can get the data out.

The device website lists a lot of software downloads written by the community. After much testing I settled on Ben Barker’s python script.

Using a laptop

Up until now I’ve been using a laptop running Linux (Ubuntu Jaunty) to record and upload the data. Obviously running a laptop 24/7 to try and help me reduce my electricity usage is a bit daft, but it got me started. After installing Jaunty I installed Python to run the script, and MySQL to record the data. Also necessary are the Python modules ’serial’ and ‘MySQLdb’. Now I need to get Ubuntu recognizing data off the serial cable. With the latest Ubuntu release modprobe is in the kernel, so add the following line to /boot/grub/menu.lst to get Ubuntu reading data off the USB serial cable with every restart:

usbserial.vendor=0×067b usbserial.vendor=0×2303

just under the first line that starts ‘initrd’ under ‘End Default Options’.
Mine looks like this:

## ## End Default Options ##
title        Ubuntu 9.04, kernel 2.6.28-14-generic
uuid        90df90b4-c89a-4bbf-968e
kernel        /boot/vmlinuz-2.6.28-14-generic root=UUID=90df90b4-c89a-4bbf-968e ro quiet splash
initrd        /boot/initrd.img-2.6.28-14-generic
usbserial.vendor=0×067b usbserial.product=0×2303

There are two versions of the CurrentCost, and as I’m on the newer one (the Envi) I had to modify Ben’s script slightly to get it working. You can get my modified script here. To run the script the database/table have to be set-up in advance – here is the sql file.

’sudo python energy.py’ got the device recording data to the MySQL database. Now the data is recording I can plot it using whatever program I want – Ben uses flotr.

I preferred to upload the data to a Plentyways.com MySQL database, and graph the data from there using Google Visualization. But before I did that, I thought I’d try and replace the laptop with something a bit less hungry…

The NSLU-2 Linux Box

Here I have to confess to being an absolute beginner with Linux. Fortunately I was able to copy a fellow CurrentCost owner’s idea of using a Network Storage Device to grab the data from the CurrentCost. Ben has done it too, not to mention a few others.

The Linksys NSLU-2 is a Network Attached Storage Device that you can connect to your router and access 2 hard disks from your home network. By installing a lite weight Linux distribution on it, we can copy what we did with our laptop earlier, but with a device which draws just a couple of watts.

Fortunately the NSLU-2 has a great community who helpfully provide some great walk-through guides. I got my NSLU-2 off eBay, and proceed to follow the instructions for installing SlugOS 5.3. All went swimmingly and after a few false starts I managed to get the device up and running.

Modprobe is alive and well in SlugOS 5.3, so to get it reading from the CurrentCost was a little different. After installing python and the various python modules I also need to install kernel modules usbserial and pl2303:

opkg install kernel-module-usbserial
opkg install kernel-module-pl2303

A quick ‘modprobe usbserial ; modprobe pl2303′ should get these modules loaded. To confirm ‘dsmeg’ should list at the very bottom:

pl2303 3-1.2:1.0: PL-2303 converter detected
usb 3-1.2: PL-2303 converter now attached to ttyUSB0

USB0 can now be read by the same python script we used for the laptop. A quick shortcut to running the script in the background is to do ‘nohup python energy.py &’. This means I can ‘exit’ out of the SSH and the python script will continue running.

And here is what she looks like:

CurrentCost and NSLU2

CurrentCost and NSLU2

I’m using Google Visualization to display the results. Here is yesterday’s electricity use. It takes a while to load, as there are data points every 6 seconds, which gives 14400 for a whole day!

Share and Enjoy:
  • email
  • Google Bookmarks
  • Digg
  • Reddit
  • Facebook
 

This post is categorized: Featured / Sam's Energy Use and tagged: / / / / / / /

4 Responses to “How I created my home energy monitor”

  1. Manu says:

    Great job!
    I have been using currentcost monitor for some time now with my CC128. Also recently got a NSLU2 running unslung. I am a bit of a newbies, do you think you could send the detail from scratch to make run the app on the NSLU2…
    Regards

  2. Sam says:

    Hi Manu,

    How far have you got? Have you got your NSLU-2 running SlugOS? If so then you need to:
    1. Install the relevant packages – python, mysql, the python modules I listed, kernel-module-usbserial and kernel-module-pl2303.
    2. wget the python file, and put it somewhere you’ll remember (mine is at /home/currentcost).
    2. Create your MySQL database by running the sql file above.
    3. Add the MySQL details to the python file.
    4. modprobe the two kernel modules.
    5. ‘python energy.py’ should then just work, print out the values and record them to the MySQL database.

    There are probably some steps I’ve missed. Email me at sam [at] this domain telling me where you are, and I can try and help.

    Sam

  3. Manu says:

    Hi,
    Just sent you a PM.
    Thanks

  4. [...] system has been fantastic for me.  The setup was a breeze in comparison to other systems such as our DIY efforts or the TED 5000, where you actually have to make electrical connections.  Admittedly this provides [...]

Leave a Reply