Plugwise and PHP

Plugwise Forum about Plugwise devices and the Source software.
Freemann
Member
Member
Posts: 54
Joined: Tue Jan 03, 2012 12:21 am

Plugwise and PHP

Post 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?
DJF3
Advanced Member
Advanced Member
Posts: 895
Joined: Thu Jul 12, 2007 9:28 am
Contact:

Re: Plugwise and PHP

Post 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
Freemann
Member
Member
Posts: 54
Joined: Tue Jan 03, 2012 12:21 am

Re: Plugwise and PHP

Post 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) :wink: :D
airox
Member
Member
Posts: 214
Joined: Sat May 15, 2010 10:42 pm

Re: Plugwise and PHP

Post 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;
        }

hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post 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, :-)
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Plugwise and PHP

Post 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 :D

Anyways, I wrote a PHP class that takes care about the above actions, maybe you're interested??
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post 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 :D

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
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Plugwise and PHP

Post 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!
Attachments
Plugwise class.zip
(2.54 KiB) Downloaded 531 times
Last edited by ludom on Thu Nov 01, 2012 9:00 pm, edited 3 times in total.
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post by hansieh »

Thanks,
I'm going to try it tomorrow.
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Plugwise and PHP

Post 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.
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post 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.
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Plugwise and PHP

Post 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..
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post 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.
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
User avatar
ludom
Member
Member
Posts: 90
Joined: Fri Jun 11, 2010 12:30 am
Location: Netherlands

Re: Plugwise and PHP

Post 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.
Home-brewed HA system based on Linux, PHP5, MySQL and Beanstalkd
hansieh
Starting Member
Starting Member
Posts: 25
Joined: Sun Nov 26, 2006 12:27 pm
Location: Netherlands
Contact:

Re: Plugwise and PHP

Post 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.
Attachments
Plugwise.class.rar
(1.48 KiB) Downloaded 565 times
(domotica, arduino, MySQL, PHP, electronics)
http://www.chamiri.nl
Post Reply

Return to “Plugwise Forum”