View unanswered posts | View active topics It is currently Mon Jun 24, 2024 2:54 am



Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Monitoring house temperature and electric consumption 
Author Message
Regular pChart user
Regular pChart user

Joined: Wed Feb 09, 2011 8:13 pm
Posts: 15
Post Monitoring house temperature and electric consumption
Hi,

Just for show my utilization of pChart library (and add a new topic to showcase :>).

Based on OpenWRT on a pogoplug (pink).

One daemon reads data from electric supplier every 30 minutes, and saves it to a SQLite database.
For temperature, another daemon reads one-wire device (ds18b20) from owfs every 30 minutes, and saves it to another SQLite database.

Thanks for this great library !


Attachments:
Capture-1.png
Capture-1.png [ 49.39 KiB | Viewed 35270 times ]
Wed Oct 26, 2011 12:38 am
Profile
pChart user
pChart user

Joined: Sun Oct 30, 2011 10:59 pm
Posts: 4
Post Re: Monitoring house temperature and electric consumption
This is fantastic! I need to do something exactly like this. Can you post your sample code for this?


Sun Oct 30, 2011 11:01 pm
Profile
Regular pChart user
Regular pChart user

Joined: Wed Feb 09, 2011 8:13 pm
Posts: 15
Post Re: Monitoring house temperature and electric consumption
I can make documentation for that.
About data from electric supplier, do you live in France ? (Or have you an example of data)

For information, on 1 Ghz (kirkwood), pChart take 2,5 seconds to generate one image.
@Jean-Damien : Do you have tips for optimization ?


Mon Oct 31, 2011 2:44 am
Profile
pChart user
pChart user

Joined: Sun Oct 30, 2011 10:59 pm
Posts: 4
Post Re: Monitoring house temperature and electric consumption
I live in the US. Our power is only provided to us in .CSV format once a month :|
From there I've written a ruby script to make it more readable, once done, I move it to a MySQL DB for now so that I can pull it from there. This is my first time around with pChart, so if you could show me some of your code I would be very appreciative.

Some data would be rack,circuit_id,read_date,read_value,
3.1.2.b.01,,423.1.1,2011-09-01,2345.01


Mon Oct 31, 2011 2:59 am
Profile
Regular pChart user
Regular pChart user

Joined: Wed Feb 09, 2011 8:13 pm
Posts: 15
Post Re: Monitoring house temperature and electric consumption
My data are not like yours.

For generate a graph, I need six variables :
$abs_x : Interval for one day/month.
$stats : Consumption for each 30 minutes.
$date : Date for title.
$opt : Because for a day I used bar, and for a month i used stacked bar, value is 0 or 1. (used for title too).
$rate_hc : price for one watt/hour between 22:30 to 6:30.
$rate_hp : same between 6:30 to 22:30.

$rate_hc & $rate_hp : It's an example, depend of your electric supplier and your contract.
$stats : The last two array is if the daemon failed to read data (I think you don't need that, so you can delete miss_* charts).

Example of data :
$abs_x :
Code:
Array
(
    [0] => 00:00
    [1] => 00:30
    [2] => 01:00
    [3] => 01:30
    [4] => 02:00
    [5] => 02:30
    [6] => 03:00
    [7] => 03:30
    [8] => 04:00
    [9] => 04:30
    [10] => 05:00
    [11] => 05:30
    [12] => 06:00
    [13] => 06:30
    [14] => 07:00
    [15] => 07:30
    [16] => 08:00
    [17] => 08:30
    [18] => 09:00
    [19] => 09:30
    [20] => 10:00
    [21] => 10:30
    [22] => 11:00
    [23] => 11:30
    [24] => 12:00
    [25] => 12:30
    [26] => 13:00
    [27] => 13:30
    [28] => 14:00
    [29] => 14:30
    [30] => 15:00
    [31] => 15:30
    [32] => 16:00
    [33] => 16:30
    [34] => 17:00
    [35] => 17:30
    [36] => 18:00
    [37] => 18:30
    [38] => 19:00
    [39] => 19:30
    [40] => 20:00
    [41] => 20:30
    [42] => 21:00
    [43] => 21:30
    [44] => 22:00
    [45] => 22:30
    [46] => 23:00
    [47] => 23:30
    [48] => 00:00
)

$stats :
Code:
Array
(
    [0] => Array
        (
            [0] => 0
            [1] => 72
            [2] => 63
            [3] => 34
            [4] => 36
            [5] => 79
            [6] => 52
            [7] => 35
            [8] => 51
            [9] => 967
            [10] => 1457
            [11] => 81
            [12] => 79
            [13] => 76
            [14] => 3
            [15] => 0
            [16] => 0
            [17] => 0
            [18] => 0
            [19] => 0
            [20] => 0
            [21] => 0
            [22] => 0
            [23] => 0
            [24] => 0
            [25] => 0
            [26] => 0
            [27] => 0
            [28] => 0
            [29] => 0
            [30] => 0
            [31] => 0
            [32] => 0
            [33] => 0
            [34] => 0
            [35] => 0
            [36] => 0
            [37] => 0
            [38] => 0
            [39] => 0
            [40] => 0
            [41] => 0
            [42] => 0
            [43] => 0
            [44] => 0
            [45] => 0
            [46] => 1103
            [47] => 839
            [48] => 29
        )

    [1] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
            [10] => 0
            [11] => 0
            [12] => 0
            [13] => 0
            [14] => 41
            [15] => 33
            [16] => 45
            [17] => 75
            [18] => 41
            [19] => 53
            [20] => 123
            [21] => 191
            [22] => 89
            [23] => 86
            [24] => 43
            [25] => 80
            [26] => 120
            [27] => 98
            [28] => 79
            [29] => 112
            [30] => 76
            [31] => 198
            [32] => 86
            [33] => 83
            [34] => 37
            [35] => 24
            [36] => 32
            [37] => 67
            [38] => 41
            [39] => 23
            [40] => 94
            [41] => 160
            [42] => 135
            [43] => 112
            [44] => 101
            [45] => 146
            [46] => 6
            [47] => 0
            [48] => 0
        )

    [2] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
            [10] => 0
            [11] => 0
            [12] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [16] => 0
            [17] => 0
            [18] => 0
            [19] => 0
            [20] => 0
            [21] => 0
            [22] => 0
            [23] => 0
            [24] => 0
            [25] => 0
            [26] => 0
            [27] => 0
            [28] => 0
            [29] => 0
            [30] => 0
            [31] => 0
            [32] => 0
            [33] => 0
            [34] => 0
            [35] => 0
            [36] => 0
            [37] => 0
            [38] => 0
            [39] => 0
            [40] => 0
            [41] => 0
            [42] => 0
            [43] => 0
            [44] => 0
            [45] => 0
            [46] => 0
            [47] => 0
            [48] => 0
        )

    [3] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
            [10] => 0
            [11] => 0
            [12] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [16] => 0
            [17] => 0
            [18] => 0
            [19] => 0
            [20] => 0
            [21] => 0
            [22] => 0
            [23] => 0
            [24] => 0
            [25] => 0
            [26] => 0
            [27] => 0
            [28] => 0
            [29] => 0
            [30] => 0
            [31] => 0
            [32] => 0
            [33] => 0
            [34] => 0
            [35] => 0
            [36] => 0
            [37] => 0
            [38] => 0
            [39] => 0
            [40] => 0
            [41] => 0
            [42] => 0
            [43] => 0
            [44] => 0
            [45] => 0
            [46] => 0
            [47] => 0
            [48] => 0
        )

)

And function :
Code:
function make_graph_conso($abs_x,$stats,$date,$opt,$rate_hc,$rate_hp) {

/* Y axis */
$MyData = new pData();
$MyData->addPoints($stats[0],"hchc");
$MyData->setSerieDescription("hchc","Heures creuses");
$MyData->setSerieOnAxis("hchc",0);

$MyData->addPoints($stats[1],"hchp");
$MyData->setSerieDescription("hchp","Heures pleines");
$MyData->setSerieOnAxis("hchp",0);

$MyData->addPoints($stats[2],"miss_hchc");
$MyData->setSerieDescription("miss_hchc","Heures creuses manquantes");
$MyData->setSerieOnAxis("miss_hchc",0);

$MyData->addPoints($stats[3],"miss_hchp");
$MyData->setSerieDescription("miss_hchp","Heures pleines manquantes");
$MyData->setSerieOnAxis("miss_hchp",0);

$MyData->setAxisName(0,"Watt/Heure");

/* X axis */
$MyData->addPoints($abs_x,"x_serie");
$MyData->setSerieDescription("x_serie","Heures");
$MyData->setAbscissa("x_serie");
$MyData->loadPalette("pchart/palettes/edf.color",TRUE);

/* Create the pChart object */
$myPicture = new pImage(900,400,$MyData);

/* Turn of Antialiasing */
$myPicture->Antialias = FALSE;

/* Add a border to the picture */
global $div_bgcolor;
$rgb = html2rgb($div_bgcolor);
$Settings = array("R"=>$rgb[0], "G"=>$rgb[1], "B"=>$rgb[2]);
$myPicture->drawFilledRectangle(0,0,900,400,$Settings);

/* Set the title */
$myPicture->setFontProperties(array("FontName"=>"pchart/fonts/verdana.ttf","FontSize"=>8));
$TitleSettings = array("Align"=>TEXT_ALIGN_TOPLEFT, "R"=>255, "G"=>255, "B"=>255);
if ($opt == 0) $myPicture->drawText(65,17,"Consommation électrique du ".dateFR($date),$TitleSettings);
if ($opt == 1) $myPicture->drawText(65,17,"Consommation électrique du mois de ".strftime('%B', strtotime("now",strtotime($date))),$TitleSettings);

/* Define the chart area */
$myPicture->setGraphArea(60,60,850,340);
$myPicture->setFontProperties(array("R"=>255,"G"=>255,"B"=>255, "FontName"=>"pchart/fonts/verdana.ttf","FontSize"=>7));

/* Draw the scale */
$AxisBoundaries = array(0=>array("Min"=>0,"Max"=>50000));
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>FALSE,"CycleBackground"=>TRUE,
"LabelRotation"=>90,"Mode"=>SCALE_MODE_START0,"ManualScale"=>$AxisBoundaries);
$myPicture->drawScale($scaleSettings);

/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

/* Draw the chart */
$Config = array("BarOffset"=>8);
if ($opt == 0) {$myPicture->drawStackedBarChart($Config);}
if ($opt == 1) {$myPicture->drawBarChart($Config);}

/* Write the chart legend */
$Config = array("FontR"=>255, "FontG"=>255, "FontB"=>255, "FontName"=>"pchart/fonts/verdana.ttf", "FontSize"=>7, "Margin"=>6, "Alpha"=>30, "BoxSize"=>$
$myPicture->drawLegend(700,11,$Config);

/* Write cost */
$day_conso_hchc = 0;
$day_conso_hchp = 0;
for($x=0;$x<=sizeof($abs_x)-1;$x++) { $day_conso_hchc += $stats[0][$x]+$stats[2][$x];}
for($x=0;$x<=sizeof($abs_x)-1;$x++) { $day_conso_hchp += $stats[1][$x]+$stats[3][$x];}

$myPicture->setFontProperties(array("FontName"=>"pchart/fonts/verdana.ttf","FontSize"=>8));
$TitleSettings = array("Align"=>TEXT_ALIGN_TOPLEFT, "R"=>255, "G"=>255, "B"=>255);

$myPicture->drawText(65,30,'Heures creuses : '.round(($day_conso_hchc/1000),2).' Kwh, heures pleines : '.round(($day_conso_hchp/1000),2).' Kwh, soit un cout de '.round((($day_conso_hchc/1000)*$rate_hc)+(($day_conso_hchp/1000)*$rate_hp),2).' euros',$TitleSettings);

$myPicture->Antialias = TRUE;

$myPicture->stroke();
}


Tue Nov 01, 2011 11:28 pm
Profile
pChart user
pChart user

Joined: Tue Jun 12, 2012 6:53 am
Posts: 4
Post Re: Monitoring house temperature and electric consumption
Hello Niii,

your chart looks really awesome !!!
Would you please Post the code for the dateselection in the header ?
THX
Andyyyy


Tue Jun 12, 2012 7:31 am
Profile
Regular pChart user
Regular pChart user

Joined: Wed Feb 09, 2011 8:13 pm
Posts: 15
Post Re: Monitoring house temperature and electric consumption
Hi,

Take a look at : http://bugsvoice.com/applications/bugsV ... erDemo.jsp


Tue Jun 12, 2012 8:10 am
Profile
pChart user
pChart user

Joined: Tue Jun 12, 2012 6:53 am
Posts: 4
Post Re: Monitoring house temperature and electric consumption
Thank You !!!!!
Andyyyy


Tue Jun 12, 2012 8:26 am
Profile
pChart user
pChart user

Joined: Tue Jun 12, 2012 6:53 am
Posts: 4
Post Re: Monitoring house temperature and electric consumption
How did you send The date to pchart ???

Andyyyy


Tue Jun 12, 2012 9:46 am
Profile
Regular pChart user
Regular pChart user

Joined: Wed Feb 09, 2011 8:13 pm
Posts: 15
Post Re: Monitoring house temperature and electric consumption
I use variable from callback "callback:function(cal)" :
cal.currentDate.getDate()
cal.currentDate.getMonth()
cal.currentDate.getFullYear()


Tue Jun 12, 2012 12:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron