[rrd-users] Accumulative power usage graph

Rob Conway rjconway at bigpond.com
Sun Feb 22 11:43:44 CET 2009


I do exactly the same thing to calculate my total house power however I
count the disc rotations of my kwh meter.  

See www.rjconway.homeip.net select power.  You will need Internet Explorer
to use the controls.


You will need a couple of scripts and text files, cannot guarantee this is
100% however should get you underway with the idea.


This is what I used to create the rrd.  Change it to suite your needs,
cannot remember exactly how this works however do not change the step of
600.  create an rrd for kw and kwh

rrdtool create /var/rrd/kw.rrd --start ?????????? --step 600
DS:P1:GAUGE:1300:0:100 RRA:AVERAGE:0.5:1:1440 RRA:AVERAGE:0.5:4:2160
RRA:AVERAGE:0.5:12:8760 RRA:MIN:0.5:144:1825 RRA:MAX:0.5:144:1825




1) 
Script to capture the counter at midnight and store its value in a file
(discday.txt), also this script if its Sunday will store the counter in a
file called discweek.txt.  This script needs to run at midnight, use crontab
to schedule the script to run.

This is a sample crontab from my NSLU2, last entry triggers a script in this
case flowread to run at 11:50pm.  You will also see my scripts that create
my trends (Aqua7D etc)

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/
# ---------- ---------- Default is Empty ---------- ---------- #
0 0-23/8 * * * root /usr/sbin/CheckDiskFull &>/dev/null
0 0 * * * root /usr/sbin/WatchDog &>/dev/null
*/15 * * * * root /public/Aqua2D &>/dev/null
1 * * * * root /public/Aqua7D &>/dev/null
2 * * * * root /public/Aqua1W &>/dev/null
5 * * * * root /public/Aqua1M &>/dev/null
12 * * * * root /public/Aqua2M &>/dev/null
50 23 * * * root /public/flowread &>/dev/null


THIS SCRIPT RUNS AT MIDNIGHT VIA CRONTAB AND STORES THE COUNTER IN A TEXT
FILE

#!/bin/bash
S1=$(/bin/date +%a)
S2='Sun'
OWR="/opt/owfs/bin/owread -s 3001"


### Read 1wire data ###
disc=$($OWR 1D.EBEF0900000034/counters.B)


### Place current reading in storage ###
echo $disc $('date')>/var/scripts/discday.txt

### Write Sundays flow to calculate total weekly KWH (NOT CURRENTLY USED)###
if [ $S1 == $S2 ];
 then
    echo $disc $('date')>/var/scripts/discweek.txt
fi



OK so we now capture the counter at midnight (11:50pm) and store the counter
in a text file.  You will need to make sure your file permissions are OK for
the script and txt files so that they can be read.



2)a script that calculates the kw and stores the data in a file.  This
script just loops around every 5 minutes.  You will see to calculate the kw
you need to take the current counts and subtract them from the last count
then do your maths..  Thus this script also saves the count as disc_10.txt
so next time it runs it knows the difference between the last count and the
new count thus how many kw have been measured in that time interval, 300
seconds

This script pushes two readings into the rrd every 300 seconds which get
averaged together every 600 seconds within the rrd.


A note on AWK.  Awk enables you to do maths functions, The first value in
the txt file (ie /var/scripts/disc_10.txt ) becomes variable $0 within the
calc.  Thus (DR-$0) provides you with the number of counts in the last 300
seconds.  You will need to change the subsequent maths to suit your counter.
I am measuring the disc rotations of my power meter thus my calc *3600/45000
is not what you want.

THIS IS THE MAIN SCRIPT THAT LOOPS EVERY 300 second TO GET DATA INTO AN RRD.
I generally started these files with a program called "nohup" which enables
you to start a script and let it run in the background.  nohup /scriptname
&>/dev/null  nohup was tricky to find for the nslu2, cannot remember how I
got it.  Anyway you just need to start this program and get it to
continuously run.

#!/bin/bash
OWWRITE="/opt/owfs/bin/owwrite -s 3001"
OWREAD="/opt/owfs/bin/owread -s 3001"
AWK="/usr/bin/awk"

while true
do

### Read 1wire data ##
disc=$($OWREAD 1D.EBEF0900000034/counters.B)

### Calculations based upon Data ###
KW=$($AWK -v DR="$disc" '{printf "%g\n",(((DR-$0)*3600)/45000)}'
/var/scripts/disc_10.txt)
echo $disc >/var/scripts/disc_10.txt
Todaykwh=$($AWK -v DR="$disc" '{printf "%g\n",((DR-$0)/150)}'
/var/scripts/discdy.txt)

### Push Data into NEW Trend Files ###
rrdtool update /var/www/rrd/kw.rrd N:$KW
rrdtool update /var/www/rrd/kwh_daily.rrd N:$Todaykwh:1

sleep 300
done



I hope this helps

rob


-----Original Message-----
From: rrd-users-bounces at lists.oetiker.ch
[mailto:rrd-users-bounces at lists.oetiker.ch] On Behalf Of gm_sjo
Sent: Sunday, February 22, 2009 7:28 AM
To: Alex van den Bogaerdt
Cc: rrd-users at lists.oetiker.ch
Subject: Re: [rrd-users] Accumulative power usage graph

2009/2/21 Alex van den Bogaerdt <alex at vandenbogaerdt.nl>:

> Looking good, albeit a bit high.  If you think 500W is the true power
> consumption, then OK. Else make sure you aren't confused between what you
> think you are storing and what you are actually storing here. I'm talking
> about units.

Thanks Alex. Yes 500W is about right for my average load (workstation,
server, media centre, some heating sometimes etc).

> The problem here is that you define a day as midnight local time to
midnight
> local time.  This is not how RRDtool works. The problem is bigger when you
> start talking about months and quarters.
>
> Unless you are willing to look at more normalized intervals (midnight UTC
to
> midnight UTC, intervals of 30 days starting at well defined moments in
time,
> and so on) you cannot display more than one of such interval at a time.

I'll look into it. I was aware it uses unix timestamps so i'll see
what I can come up with. It doesn't need to be super accurate, i'm
just trying to get a reasonable comparative figure to what my
electricity company thinks i've used :-)


Thanks

_______________________________________________
rrd-users mailing list
rrd-users at lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.0.237 / Virus Database: 270.11.2/1965 - Release Date: 02/21/09
15:36:00



More information about the rrd-users mailing list