Plugwise DIY monitoring PHP

Home_stretch20Basic I bought myself a Plugwise system. The reason for this is that I can monitor my total power-usage, but I cannot see the details. I.e. : What is my refrigerator using? What is the freezer using? I can only see the sum of the total.

Plugwise made some nice hardware that allows you to monitor each device (or multiple devices behind on the same power-socket) to give you clear insight in the usage. Unfortunate sending and logging the information online will cost you a subscription.. I think for the price of the plugwise this should be a free service to store your data online for at least 2 years.

Because the system uses XML it is fairly easy to readout the information from the plugwise system and to build something yourself.

I used the following materials :

1 x Stretch V2.0

12 x  Circle  (1 Circle +)

In short here is the idea… The stretch is the gateway between your circles (the measurement units) and your network. The Circles (measurement units) form 1 mesh peer-to-peer network (the circle+ is the coordinator) This is done with Zigbee.

The units will find each other and uses each other to reach the coordinator. There are best practices to build your zigbee network. You will find them online. In general and in short, don’t use too many nodes in between.. as the transmission speed is slow and if you have too many repeaters the network get kludged.

Once you have added all your nodes you can read out the nodes by XML using the IP address of your Stretch and the following addition : http://<strechIP>/core/modules

I use a CRON tab that reads out this information every minute and I store it in a database. I made it cumulative so my database doesn’t grow out of size.


Because the stretch uses authenication, i used PHP and CURL for it.

$url = "http://{$stretchIP}/core/modules";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, "$stretchUser:$stretchPWD");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result = curl_exec ($ch);
curl_close ($ch);

$xml = simplexml_load_string($result);

foreach ($xml->module as $module) {

#Only allow Network Router (Circle) and Network Coordinator (Circle+)
if ($module->vendor_model == "NC" || $module->vendor_model == "NR" ) {
    $query = "INSERT INTO
         stretch_appliances (`module_id`,`sum_usage`,`runtime`)
         VALUES ('".$module["id"]."','".$module->services->electricity_point_meter->measurement."','1')
         `runtime`=`runtime`+1 ,
         `sum_usage` = `sum_usage` + ".$module->services->electricity_point_meter->measurement;
         $result = mysql_query($query);

Now it’s fairly easy to calculate the average usage per hour, month and per year .. The longer the data can collect, the more accurate it will be.

This is how my monitor screen looks like. Notice that my washing machine and dryer are not turned on yet. So i have no usage there. yet 🙂

2014-06-09 00_23_17-


Good luck and hopefully this inspires people to make something nice.

This entry was posted in Green power, PHP, smartmeter, Technical and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.