The quarterly bill tumbled through the letter plate. Normally I just leave in the heap of unopened mail nearby but I decided to open it. Quarterly electricity bill – £430!! After uttering some choice expletives at high volume, I decided something needed to be done. A hour or two on a few money saving websites (mostly moneysavingexpert.com), I found a better tarrif, and more interestingly for the geek inside, a tarrif that included a free currentcost envi energy meter! These normally retail at about £45 and consist of two units 1) a current clamp which you clip around the cable going into your fuse box and 2) a receiving unit that can be placed within 100ft (it’s wireless). It displays current watt usage, local temperature. More importantly it has a serial port on the back which spits out XML data every 6 seconds.
A serial port to usb adapter is available from the manufacturers for about £10, but a quick trip to google revealed that many mobile phones shipped with a USB cable that was in fact a USB – serial converter. I never throw anything away – to my wife it’s my deepest character flaw. Needless to say a quick rummage in my man drawer yielded 6 mobile phone USB cables. A win for the man drawer! (If the portuguese escudos ever gets reintroduced, I’m quids in by the way). Plugging them into the laptop and checking dmesg showed that 2 were indeed usb-serial cables. 10 mins with a soldering iron and an rj45 plug, I had a rather ugly, but free, usb-currentcost adapter. It’s now plugged into my revo running ubuntu 10.04.
There’s loads of info on the interweb about the structure of the XML feed that the currentcost device produces.
- http://stanford-clark.com/power/
http://chemicaloliver.net/programming/mqtt-mosquitto-and-php/
http://code.google.com/p/currentcostgui/wiki/MQTT
http://andypiper.wordpress.com/2008/04/27/current-cost/
I am not a natural coder, but when I do, python is my language of choice. It’s pretty simple to get at the serial port with the python serial module and then parse the xml data into something useful. Here’s the code I’m using – you have been warned, it’s ugly!!
#!/usr/bin/python -u
import re
import MySQLdb
dbName = "db"
tblName1 = "power"
uName = "username"
pswd = "password"
hostName = "mysql_server_IP"
import serial
import shlex
import subprocess
pub_cmd = "mosquitto_pub -t cc128/raw -l -q 2"
pub_args = shlex.split(pub_cmd)
pub = subprocess.Popen(pub_args, stdin=subprocess.PIPE)
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=57600)
db = MySQLdb.connect(host=hostName, user=uName, passwd=pswd,db=dbName)
c = db.cursor()
prevWatts = 0
deltaT = 0
prevTemp = 0
while 1:
line=""
line = ser.readline() #read a '\n' terminated line
pub.stdin.write(line)
pub.stdin.flush()
print line #prints the output so you can see it working
m = re.search('.*[0]*([1-9][0-9]*).*',line)
n = re.search('.*([0-9][0-9]):([0-9][0-9]):([0-9][0-9]).*',line)
o = re.search('.*([0-9\.]*).*',line)
if m is not None:
watts = m.group(1)
hours = n.group(1)
mins = n.group(2)
secs = n.group(3)
temp = o.group(1)
totalTime = (int(hours)*3600) + (int(mins)*60) + int(secs)
if deltaT == 0:
deltaT = 6
else:
deltaT = int(totalTime) - int(prevTime)
prevTime = totalTime
deltaTemp = float(temp) - float(prevTemp)
deltaW = int(watts) - int(prevWatts)
joules = (prevWatts + int(watts))*0.5*deltaT
if (deltaW >= 40) or (deltaW <= -40):
c.execute("INSERT INTO power (watts, joules) VALUES (%s, %s)",(watts,joules))
print watts+"W"
print hours+":"+mins+":"+secs
print temp+"C"
print deltaT
print deltaW
prevWatts = int(watts)
else:
print "No Change"
pub.stdin.close()
pub.wait()
Where does this put the data? Mainly it’s into a MYSQL database with three columns – stamp (timestamp, default value current_timestamp), watts, and joules. It’s also publishing it to a mosquitto instance running on the same machine. Mosquitto is an mqtt message broker as used by Andy Stanford-Clark in his twittering house. I’m just messing around with mqtt and I’m not entirely sure what I’m going to do with it, but what the heck.
The next stage is to graph this data to get some meaningful power usage pattern and display it on a webpage. Initially I used matplotlib, but nice as the graphs were, they loaded way too slow. I’ve now moved to using google visualizations, the associated python API and an addon for it called dygraphs. This now produces rather nice interactive graphs that can be seen here.
Rather worryingly it shows that the house has a ‘resting’ power need of about 400w. It was probably more – I used to leave two ‘servers’, the laptop and a macmini, powered on 24/7. I now use wakeonlan to power these up if needed. So now the only PC’s permanently on are the revo and a viglen mpc-l. Between them they probably only account for about 35W. I’ve also installed granola on all my machines, which seems to be improving energy use.
On the domestic appliance front, the main energy gobblers are the oven, tumbledryer and dishwasher. I rather think the chest freezer in the garage may be accounting for some of the baseline consumption – it’s about 10 years old so may need replacing. To further isolate power usage, CurrentCost have some new “Individual Appliance Monitors” coming out soon, which will link into the CurrentCost Envi base unit. I will be first in the queue.
In the meantime, I’m taking the plugs off the tumbledryer, dishwasher, wife’s hair straighteners and her hairdryer. In retrospect, maybe not the last two…………I’m not quite that stupid.
Cool, but please bear in mind that currentcost and all other units on sale that have a clampon amp-meter do not actually know how many watts you are using and of course you are billed in Killo Watt Hours (unless a business then you may have a VA meter billing you for VoltxAmps used).
Thus the reading from these devices can be way out e.g. Currentcost says 420watts when really the true load is under 250watts.
In the USA you can get TED, The Energy Detective and its transmitter unit records all the time and has a voltage signal so it can determine the power factor and thus calculate an accurate watt reading.
Pingback: CurrentCost Envi CC128 (Part 2) | Bob's Blog
Pingback: CurrentCost Envi CC128 (Part 2) | Bob's Blog
Pingback: Watering the Garden OSS style – A Year with (some) Open Hardware | Open Source Medicine