Tuesday, 29 July 2008

Graphing Current Cost

After hooking up my Current Cost Meter to a database recently I've been logging my power usage so the next step is to look at what I can do with the data. As I mentioned when I introduced my meter lots of other people have been looking into this as well.

I like Dale's idea for creating a daily energy bill so I've decided to aim towards that but include a graph of the days usage and possibly a link to a web page where I can look at more details of that days use.

With the web page idea in mind I decided to look into what I could do graph wise in PHP since that's my web language of choice. After looking through a few options I plumped for the obvious library, that of PHP Image Graph as it's part of PEAR so should be fairly decent, complete, well used and flexible. Here's where I'm at so far:
That's just a small snipped of 1 days power usage when I was cooking dinner. You can see I turned on my steamer (approx 800 watts) at about 5:30pm then went on to turn on the oven which heated up then cut in and out while it was cooking before I turned it and the steamer off just before 6pm.

As you can see, I'm pretty much there with the graphing side of things. The only issue left is to sort out the X axis. While it might appear to be a bit crazy, the current cost meter only samples approximately every 6 seconds. Because of the different number of samples in each hour and with a few rounding errors, the X axis appears not to be linear. Hopefully, I'll solve this by ensuring a consistent number of samples in each time slot.

Overall, PHP Image Graph seems very powerful. You can graph pretty much anything with it in all sorts of formats and have relatively complete control over the way the graph looks. I'm not at all artistic so mine looks very plane! There is, however, a reasonable barrier to entry. Documentation for the API is relatively complete if you know where to start, but documentation in general seems really rather thin on the ground and very sketchy. But, thankfully someone produced a great set of demos for a PHP conference that really show off a lot of the features. The source is available too so it's easier to work out what to do with your own graphing and how to get started. I'll probably blog my source code at some point, it's not very long, but definitely requires some tidying before it's ready for a public outing.

What I want to do next is take the graph and produce some sort of daily "bill" e-mail. That will have a link back to a private area on my web site that would allow closer inspection of certain areas of the graph. This is just the next step in education for how to save electricity by learning how much different combinations of devices use together. For example, is it better to steam fish in a steamer, grill, oven cook, etc. Hopefully, I'll be able to apply those sorts of questions all around the house to work out how to be as green as possible.

No comments: