D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Energy Monitoring

 

Yes... I did this four years ago for home, and then again for work.Â

You can get a currentcost device which either clamps onto the incoming live wire, or covers the flashing light on the meter (the latter is more accurate if you have such a meter, but the former I found was good too)

That unit is powered by two D-cell batteries and transmits wirelessly to a receiver unit which has a display. That's the consumer part - they cost about Â30 to Â50. If that's all you want to do, fine. If you want to record this on a linux machine, read on.

Now, there is a serial wire you can get on ebay that plugs into that receiver and then into a USB socket on your computer. Linux picks this up without any special drivers, and you can simply read data from that device (which comes as a one line packet of various fields which are updated every few seconds, one of which is the watts per channel - it can support several input channels)

Below is a perl script I used to strip out the data from the usb/serial adapter into a text file. I have other files that read this and put it into an rrd database so I can draw a pretty graph of the current power. Over time this shows various patterns such as when a kettle goes on, washing machine etc. (I don't have any pic of that as the system's been disabled for a while though).Â

If you want more help or a copy of those files, let me know.


#!/usr/bin/perl -w

# 20101009
# designed to run constantly in background. captures data from
# currentcost and writes to rrd and logfile
# Ncked from george by Simon

`stty -F /dev/ttyUSB1 57600`;

open SERIAL, "<", "/dev/ttyUSB1" or die $!;

while (1) {
# run forever

while ($line = <SERIAL>) {

    if ($line =~ m!<tmpr>\s*(-*[\d.]+)</tmpr>.*<ch3><watts>0*(\d+)</watts>!)
        {
        open (LOGFILE,">/var/www/house/power.log");
        $temp = $1;
        $power = $2;
        #print LOGFILE "Got $power W $temp C \n";
        print LOGFILE $power;

        close LOGFILE;
# print "hit: $temp / $power\n";
        last;
        }
    }
  }
close(SERIAL);



On 17 January 2015 at 07:13, Richard Brown <rich@xxxxxxxxxxx> wrote:
Hi

Does anyone know how to measure energy use through Linux please?

ThanksÂ

RichÂ




--
Richard Brown
Community Organiser
0747 343637
http://swco.org.uk/



--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq


-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq