[rrd-users] rrdtool and calculations

Simon Hobson linux at thehobsons.co.uk
Sat Jun 23 18:41:48 CEST 2012


Steve Sykes wrote:
>I am working on using rrdtool to log my water heater use.  I have a
>one-wire sensor measuring current and wish to calculate the wattage and
>eventually the KWH used.  The sensor reads from 0.09 for off and 3.36
>for 18 amps.  I am reading the data into the logging screen but don't
>know how to scale it up so that it reads amps instead of volts.

RRD just stores <stuff>

I would suggest calculating power and then storing that. In <your 
preferred flavour of shell> it would be as simple as :

>offset=0.09
>scale_in=3.36
>scale_actual=18
>volts=240
>
>reading=<some method by which you get the value>
>
>span=`echo "scale=3 ; ${scale_in} - ${offset}" | bc 2>/dev/null`
>
>current=`echo "scale=3 ; ${reading} - ${offset} / ${span} * 
>${scale_actual}" | bc 2>/dev/null`
>
>power=`echo "scale=3 ; ${current} * ${volts}" | bc 2>/dev/null`
>
>rrdtool update <some file> n:${power}


And you can of course combine all the maths into one formula and one 
call to bc - I've shown it as separate calls to make it clearer how 
you work out the power. Of course, you'll notice that power depends 
on voltage, and that varies - so your power calculation will be a 
little out, basically as accurate as your best estimate of an average 
supply voltage.

At least with a heater you can ignore power factor - I'm assuming 
it's just one or more immersion heaters and hence a resistive load. 
These clip on "energy monitors" that lecky suppliers seems to be 
giving away are even worse - not only do they not account for voltage 
variations, but they cannot measure power factor which can lead to 
some whacky results from them.

-- 
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.



More information about the rrd-users mailing list