Remote connection to homeseer with Perl or PHP

Pop your questions regarding Home automation Domotica hardware here.....
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Remote connection to homeseer with Perl or PHP

Post by rbmace2403 »

Hi everyone,

I have started with domotica, homeseer 6 months ago and I have all kinds of things automated, but I am building a new frontend with jquery and PHP/PERL.
But I have some difficulties with getting all devices from Homeseer. I created the below code to interact with homeseer through the COM objects in PHP and PERL.

I can turn devices on/off, run events, etc. But one thing I cant get to work is a devicelist with the function "GetDeviceEnumerator();"

I can get it to work in the sub main () {} scripts within homeseer, but on a apche webserver with perl installed/php this function wont work because the method $en->GetNext();
isnt working and results zero.

I hope someone could help me out what I am missing here?

I added the below code in perl what I am doing?

Regards

Ronald

-----
#!"C:/perl/bin/perl.exe"

use Win32::OLE ;

$hsi = Win32::OLE->new("HomeSeer2.application");
$hsi->sethost("localhost");
$hsi->connect("user","pass");

$hs=$hsi->GetHSRef();
$en=$hs->GetDeviceEnumerator();

$dev_count = $hs->DeviceCount();

for($i=1; $i<=$dev_count; $i++) {
$dv=$en->GetNext();
print $dv->name;
}

----
xanhoera
Member
Member
Posts: 159
Joined: Fri Sep 05, 2008 10:38 pm
Location: Belgium
Contact:

Re: Remote connection to homeseer with Perl or PHP

Post by xanhoera »

Not sure, but I believe this is the same problem as mentioned in the comments of this groovy scripting in homeseer post?
www.ihomeautomate.eu wrote: // interop.dll and scheduler.dll should be on the working directory path!
// in case of .NET assembly load problems, check Fuslogvw.exe
Let's hope that does the trick.
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: Remote connection to homeseer with Perl or PHP

Post by rbmace2403 »

Hi,

I have been replying twice I believe, I want to thank you because this saves my problem by copying the files in to the same directory.

Regards

Ronald
xanhoera
Member
Member
Posts: 159
Joined: Fri Sep 05, 2008 10:38 pm
Location: Belgium
Contact:

Re: Remote connection to homeseer with Perl or PHP

Post by xanhoera »

I'm glad it works :)
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

HI I hope the people who started this thread notice this!!!

I have been looking for ages trying to find how to get php and homeseer to play nicely, I found the example on cooconTech and had it working on an old laptop, went off and designed my webpage etc and when I came back to the php side of things it had stopped working, I couldn't get it to work and tried on a couple of machines.

I would like it to work in an AJAX setting, am I correct in thinking the above example is the php file that AJAX would call and display on the page the returning results??

it declares the com object different to the example I have found elsewhere for php???

Why is this different from the coocontech example is that because that was the way back in 2002?

any help anyone can offer in how to get php speaking to Homeseer would be great, I really would like to have my own custom webpage working. Thought I had the backend sorted and went and put time into the webpage design!!!!!

all thoughts greatly appreciated!!

thanks
techboy
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: Remote connection to homeseer with Perl or PHP

Post by rbmace2403 »

Hi Techboy,

The solution for me was to put the DLL files : interop.dll and scheduler.dll in the directory where you have the php.exe on windows.
When I did that the com object was working ok and I could run the homeseer API calls within PHP.

I hope this helps you.

Regards

Ronald
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

doesn't moving the DLL break homeseer????
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

I think that PHP is connecting to homeseer I don't get an error on that part


but I get the following error

Call to undefined method com::SetDeviceStatus()

here is the code I use and I think it's as simple as it can get

$hs = new COM("homeseer.clsString") or die("failed to connect!!");
$hs->SetDeviceStatus ("c8",2);

if I change "homeseer.clsString to something else then the com object line creates an error.

thanks for any help.
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: Remote connection to homeseer with Perl or PHP

Post by rbmace2403 »

Hi,

You need to copy the dll files in the same PHP directory, not move them, this way PHP can access the correct DLL functions.

After that you need to connect with:

$hs=new COM("Homeseer2.Application");
$hs->SetHost($this->hostname); // localhost or IP address of homeseer server
$hs->connect($this->user, $this->pass); // username and password from a homeseer user

if you want to toggle lights you need to use the transmit command, not the setdevicestatus command.

for example: (API calls is available in the homeseer helpfiles)

$class->hs->Transmit("c8", "On", 100,0,false, true);

Regards

Ronald
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

Hi trying your example and getting the message FATAL error. Using $this when not in object context....... on line 8

I can't see any difference between your code and mine do I need to change anything in php.ini??

thanks
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

Did some research on my error and it seems you can't use $class-> directly in PHP5 you can in version 4, I am running version 5. What changes do I need to make to get this to work??

thanks for all help
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

HI am getting an error saying the $class can't be used like that can't remember exact syntax as typing at work.

Did a bit of digging and the code is valid for php4 not version 5 and I am running 5(just my luck), could anyone help how I make it work in version 5??

thanks for all help.
rbmace2403
Starting Member
Starting Member
Posts: 32
Joined: Sun Mar 04, 2012 6:07 pm

Re: Remote connection to homeseer with Perl or PHP

Post by rbmace2403 »

Replace $class with $hs, because thats the variable you have used with the com object.

Regards

Ronald
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

so the line

$class->hs->Transmit("c8", "On", 100,0,false, true);

becomes

$hs->hs->Transmit("c8", "On", 100,0,false, true);

or

$hs->Transmit("c8", "On", 100,0,false, true);

the second one looks correct but the first swops $class for $hs??

thanks not near my test machine.
techboy
Starting Member
Starting Member
Posts: 17
Joined: Thu Jan 31, 2013 8:49 pm

Re: Remote connection to homeseer with Perl or PHP

Post by techboy »

have altered my code so it says $hs->Transmit("c8", "On", 100,0,false, true);

and I no longer get the error $class error.

now I get the error

Fatal Error Call to undefined method com::Transmit()

Checking the homeseer script help and the earlier messages this method exists.

What else can I check or alter??
thanks
Post Reply

Return to “Questions & Discussions Forum”