{"id":273,"date":"2008-05-28T10:14:46","date_gmt":"2008-05-28T10:14:46","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=273"},"modified":"2009-05-17T16:16:08","modified_gmt":"2009-05-17T16:16:08","slug":"a-daily-currentcost-bill","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=273","title":{"rendered":"A daily CurrentCost &#8220;bill&#8221;"},"content":{"rendered":"<p>As I&#8217;ve finally got my <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=267\">home server<\/a> <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=272\">capturing the electric meter readings<\/a> from the <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=265\">CurrentCost<\/a>, I thought it&#8217;d be good to try doing something with it.  <\/p>\n<p>I want to start with something a bit different to graphs, because there&#8217;s already been a lot of <a href=\"http:\/\/rooreynolds.com\/2008\/05\/09\/current-cost-charting-fun\">cool<\/a> <a href=\"http:\/\/rooreynolds.com\/2008\/05\/09\/current-cost-charting-fun\">work<\/a> done in different graphing approaches. <\/p>\n<p>As I <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=272\">wrote yesterday<\/a>, I&#8217;ve got a MySQL database that is storing the watt reading from the electric meter captured once every six seconds. <\/p>\n<p>I <a href=\"http:\/\/twitter.com\/dalelane\/statuses\/821236966\">wondered<\/a> whether it makes sense to try and turn these figures into a financial cost. It might be interesting (and useful as a behaviour-altering thing) if we could get a &#8220;bill&#8221; from the CurrentCost meter each day that told us how much we spent on electricity the last day. <\/p>\n<pre style=\"font-size: 1.1em; border: thin solid silver; background-color: #eeeeee; padding: 0.8em\">+=============================================+\r\n  Your CurrentCost bill for 2008-5-27\r\n\r\n     Electricity usage   4.9802 units\r\n      Cost ==           \u00c2\u00a30.4874\r\n\r\n     Standing charge    \u00c2\u00a30.1582\r\n   ---------------------------------------\r\n     TOTAL COST FOR 2008-5-27 : \u00c2\u00a3  0.65\r\n+=============================================+<\/pre>\n<p>I&#8217;m not entirely sure of my maths here, but I thought it could be interesting to give it a try.<\/p>\n<p><!--more--><\/p>\n<h3>Turning a watt reading into a cost<\/h3>\n<p>Consider a single reading (set articificially high, to make the numbers easier to read!):<br \/>\n<code>$watts = *75000* watts<\/code><\/p>\n<p>Turn it into kW:<br \/>\n<code>$kWatts = $watts \/ 1000 = 75<\/code><\/p>\n<p>Take the unit cost from my bill:<br \/>\n<code>$unitcost = 0.0932<\/code><\/p>\n<p>Add VAT:<br \/>\n<code>$unitcostIncVAT = $unitcost * 1.05 = 0.09786<\/code><\/p>\n<p>How many hours in a year:<br \/>\n<code>$hoursInYear = 365 * 24 = 8760<\/code><\/p>\n<p>kW hours over a year:<br \/>\n<code>$kWHInYear = $kWatts * $hoursInYear = 657000<\/code><\/p>\n<p>Calculate the cost of staying at this rate all year:<br \/>\n<code>$costPerYear = $kWHInYear * $unitcostIncVAT = 64294.02<\/code><\/p>\n<p>Compare this with the values reported by the CurrentCost meter:<br \/>\n<code>$costPerMonth = $costPerYear \/ 12 = 5357.835<\/code><br \/>\n<code>$costPerDay = $costPerYear \/ 365 = 176.148<\/code><\/p>\n<p>If I put in watt values I see on the CurrentCost meter, the &#8216;Cost per day&#8217; and &#8216;Cost per month&#8217; figures agree with what I get from these sums. <\/p>\n<p>So, if I assume that a reading is valid for 6 seconds, I can work out a cost for the period of time covered by the reading:<br \/>\n<code>$costPerHour = $costPerDay \/ 24 = 7.3395<\/code><br \/>\n<code>$costPerMinute = $costPerHour \/ 60 = 0.122325<\/code><br \/>\n<code>$costPerSecond = $costPerMinute \/ 60 = 0.00203875<\/code><\/p>\n<p><code>$costPerUpdate = $costPerSecond * 6 = 0.0122325<\/code><\/p>\n<p>This can be simplified down a bit to:<br \/>\n<code>$costPerUpdate =(($watts\/1000) * $unitcostIncVAT) \/ 600<\/code><\/p>\n<h3>Getting the readings for a single day<\/h3>\n<p>This is simple &#8211; I can get the total for all readings in a single day from MySQL with a query like:<\/p>\n<pre style=\"font-size: 1.1em; border: thin solid silver; background-color: #eeeeee; padding: 0.8em\">mysql> select DATE(time) as \"Bill Date\",\r\n    ->        COUNT(power) as \"Number of updates\",\r\n    ->        SUM(power)\r\n    -> from currentcostdl\r\n    -> where (DATEDIFF(time, '2008-05-27') = 0)\r\n    -> GROUP BY DATE(time);\r\n+------------+-------------------+------------+\r\n| Bill Date  | Number of updates | SUM(power) |\r\n+------------+-------------------+------------+\r\n| 2008-05-27 |              5404 |    2988128 |\r\n+------------+-------------------+------------+\r\n1 row in set (0.93 sec)<\/pre>\n<p>I&#8217;m wondering if it might be better to use the number of updates rather than assuming how many updates I will get in a day. <strike>But for now, I&#8217;ll stick with the six seconds assumption<\/strike>.<\/p>\n<p><strong>Update:<\/strong> After Alexis&#8217; comment (below), I have switched my script to use the number of updates. It still assumes that each update is valid for approximately the same period of time, but that&#8217;s probably accurate enough for my purposes:<br \/>\n<code>$costPerUpdate = $costPerDay \/ $NumberOfUpdates;<\/code><\/p>\n<p><em>The number of updates for yesterday is very low because I only <a href=\"http:\/\/twitter.com\/dalelane\/statuses\/820896987\">started up the Perl script to capture updates yesterday<\/a>. By tomorrow, I should hopefully get a number of updates closer to 14,400.<\/em><\/p>\n<h3>Generating a &#8220;bill&#8221;<\/h3>\n<p>From here, I&#8217;ve put together a cron job on the server that will once a day at 8am. It runs a <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=272\">perl script that gets the values from MySQL<\/a> for the previous day, does the sums, turns it into a pretty &#8220;bill&#8221;, then <a href=\"http:\/\/perldoc.perl.org\/Net\/SMTP.html\">sends me an email<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I&#8217;ve finally got my home server capturing the electric meter readings from the CurrentCost, I thought it&#8217;d be good to try doing something with it. I want to start with something a bit different to graphs, because there&#8217;s already been a lot of cool work done in different graphing approaches. As I wrote yesterday, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[194,214,105,211],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-code","tag-currentcost","tag-electricity","tag-mysql","tag-perl"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/273\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}