Page 1 of 2
Plugwise and PHP
Posted: Tue Feb 21, 2012 9:11 am
by Freemann
does anyone here has a working and reliable PHP approach for plugwise?
I'm struggling for a 2 weeks now with plugwise driver from DirkEngels, and i'm getting it work (reliable).
Where Source AND Domotiga can access almost all my plugs(18 so far) within a minute, the driver from DirkEngels fails on 50-70% off the request.
I think its something with the serialport approach of the driver, but my knowledge is not going so far to fix it.
Anyone here how can help me with fixing the driver OR with a other PHP class/"driver" for plugwise?
Re: Plugwise and PHP
Posted: Tue Feb 21, 2012 11:28 am
by DJF3
Q: Why do you need a 'driver'?
Read info: using the RSS feed that the Source provides
Control: using basic HTML
Or do you want a driver that allows you to 'talk' to the Plugwise Stick directly without running the Source?
DJ
Re: Plugwise and PHP
Posted: Tue Feb 21, 2012 11:30 am
by Freemann
DJF3 wrote:Q: Why do you need a 'driver'?
Read info: using the RSS feed that the Source provides
Control: using basic HTML
Or do you want a driver that allows you to 'talk' to the Plugwise Stick directly without running the Source?
DJ
underlined (i also want a *unix server and no Windows (bad experiences from the past)

Re: Plugwise and PHP
Posted: Tue Feb 21, 2012 11:44 pm
by airox
Freemann,
I had the same reasons to use PHP. I have my own ubuntu server on which my home automation system is running. This is completely written in PHP. From Z-wave, Rfxcom to Plugwise drivers. When I started the plugwise support a month ago I also found the code from DirkEngels. I also had trouble to get it to work. I am still creating my own driver but am now just calling a python script which can also interface with the plugwise stick. But for now .. the following code is what I use to open the resource in PHP and get it right.
I used the reset line a few times and it did worked from time to time. Check if you need it.
Code: Select all
public function getDeviceResource() {
if ( !is_resource($this->serial) ) {
// reset
// @shell_exec('stty -F '.$this->device.' 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0');
// set the settings
@shell_exec("stty -F " . $this->device . " ispeed 115200 ospeed 115200 cs8 -parenb");
// connect
$this->serial = fopen($this->device, 'r+b');
stream_set_blocking($this->serial, 0);
fwrite($this->serial,Plugwise_Message::getInitStick());
$this->read();
}
return $this->serial;
}
Re: Plugwise and PHP
Posted: Sat Sep 22, 2012 9:28 pm
by hansieh
Can someone help me to start with PHP and plugwise.
I currently use an arduino in collaboration with PHP and MySQL for my home automation.
I would love to get PHP working with Plugwise on windows.
I've searched this entire plugwise forum and have a look at the driver from Dirk Engels.
Apparently my PHP knowledge is not enough to get it working.
So I am basically looking for a few examples on windows using the driver.
in advance, thanks,

Re: Plugwise and PHP
Posted: Sun Sep 23, 2012 5:04 pm
by ludom
Hi hansieh,
When you are running windows you could also use the build-in webserver that comes with the plugwise source software.
It provides an XML document with all information about your appliances. You can call this page periodically with for example file_get_contents().
Switching on, off and locking modules is also possible, herefor you can call the API action page thats also included into the source software's webserver.
I know this isn't a native solution because you still depends on the plugwise software, but it works
Anyways, I wrote a PHP class that takes care about the above actions, maybe you're interested??
Re: Plugwise and PHP
Posted: Sun Sep 23, 2012 9:07 pm
by hansieh
ludom wrote:Hi hansieh,
When you are running windows you could also use the build-in webserver that comes with the plugwise source software.
It provides an XML document with all information about your appliances. You can call this page periodically with for example file_get_contents().
Switching on, off and locking modules is also possible, herefor you can call the API action page thats also included into the source software's webserver.
I know this isn't a native solution because you still depends on the plugwise software, but it works
Anyways, I wrote a PHP class that takes care about the above actions, maybe you're interested??
Hi Ludom,
I like to receive your PHP class.
I am not yet so familiar with XML, but it gives a nice opportunity to learn some about it.
Eventually I would like a situation without the application of plugwise but first, lets fill MYSQL with some data.
Thanks in advange
Re: Plugwise and PHP
Posted: Sun Sep 23, 2012 11:15 pm
by ludom
Here you have my Plugwise PHP Class.
To get this work make shure you have enabled the webserver in the Plugwise Source software (under settings). Also make shure that your PHP installation has the SimpleXML library (
http://php.net/manual/en/book.simplexml.php) installed, this is required to fetch and process the XML data from the Plugwise software.
You'll find an example.php file where you can find some examples of usage.
Good luck!
Re: Plugwise and PHP
Posted: Mon Sep 24, 2012 12:09 am
by hansieh
Thanks,
I'm going to try it tomorrow.
Re: Plugwise and PHP
Posted: Tue Oct 02, 2012 12:23 pm
by ludom
Hi Hansieh,
I updated the class today, there was a problem with completion. When the `powerusage` or a `totalusage` of an appliance was below 1 (for example 0.62 kWh) it was printed as 0 (zero). I reformatted this value so this bug is solved now.
Re: Plugwise and PHP
Posted: Tue Oct 02, 2012 4:05 pm
by hansieh
ludom wrote:Hi Hansieh,
I updated the class today, there was a problem with completion. When the `powerusage` or a `totalusage` of an appliance was below 1 (for example 0.62 kWh) it was printed as 0 (zero). I reformatted this value so this bug is solved now.
Hi Ludom,
I like to see your change,
I have a the basic XML-PHP-mysql functioning for now, but my server has crashed after an update, it has cost me a lot of time to fix it.
When I am online again you can check the result on
http://chamiri.nl/drupal7/?q=node/
thanks for all the help.
Re: Plugwise and PHP
Posted: Tue Oct 02, 2012 4:15 pm
by ludom
hansieh wrote:ludom wrote:Hi Hansieh,
I updated the class today, there was a problem with completion. When the `powerusage` or a `totalusage` of an appliance was below 1 (for example 0.62 kWh) it was printed as 0 (zero). I reformatted this value so this bug is solved now.
Hi Ludom,
I like to see your change,
I have a the basic XML-PHP-mysql functioning for now, but my server has crashed after an update, it has cost me a lot of time to fix it.
When I am online again you can check the result on
http://chamiri.nl/drupal7/?q=node/
thanks for all the help.
Hi Hansieh,
Oh that's pity ("balen").
I updated the attachment at my previous post (a few posts above this one), there you will find the updated class. The only thing you have to do is overwrite your local Plugwise.class.php file with the one that comes with the new ZIP file.
P.S. your server is still down here..
Re: Plugwise and PHP
Posted: Wed Oct 31, 2012 2:11 pm
by hansieh
Hi Ludom,
I'am using your Plugwise class for a few weeks now and everything is working fine.
I only needed to adjust something because my solar collectors give negative values and your class corrected that to zero.
What I found out is that the Total power usage per device is only updated every hour.
I don't think this is a fault in your class because the standard plugwise XML file is giving the same problem.
Do you also noticed this problem, the default plugwise website doesn't seems to have this problem.
Maybe I will start a new topic about this.
Re: Plugwise and PHP
Posted: Wed Oct 31, 2012 2:30 pm
by ludom
Hi Hansi,
Yeah thats true, my class currently can't handle negative values.
Maybe you can send me your xml file so i can fix this. I dont have appliances that give negative values so i cant test this properly.
Re: Plugwise and PHP
Posted: Wed Oct 31, 2012 3:09 pm
by hansieh
of course, though it is not a big change.
I correct the data later by adjusting anything between 0 and-5 to zero.