[How-To] Interfacing PHP and Homeseer

electron

Administrator
Staff member
<span style='font-size:14pt;line-height:100%'>How to interface Homeseer using PHP</span>
by electron

1) Configure DCOM: http://www.cocoontech.com/index.php?showtopic=294

2) Install Apache & PHP: http://www.cocoontech.com/index.php?showtopic=305

3) Create a new file in your webroot directory using notepad, name it index.php.

4) paste the following code into the index.php file (make sure you change Homeseer.Application to whatever the object is named in your DCOM configuration screen, usually the other name is Homeseer.ClsString.

Code:
<?php 
   $hs = new COM("HomeSeer.Application");
   $List=$hs->GetDeviceList();
   
   print "<table>";
   
   for($i=1; $i < $List->Count() + 1; $i++) { 
	  $What=$List->item($i);
	  $device="<tr>";
	  $device.="<td width=50>$i</td>";
	  $device.="<td>$What->Name</td>";
	  $device.="<td>$What->Location</td>";
	  $device.="<td>$What->Status</td>";
	  $device.="<td>$What->hc</td>";
	  $device.="<td>$What->dc</td>";
	  $device.="<td>$What->misc</td>";
	  $device.="<td>$What->interface</td>";
	  $device.="<td>$What->dev_type_string</td>";
	  $device.="<td>$What->buttons</td>";
	  $device.="</tr>\n";
	  print $device;
   }
   print "</table>";
   unset($hs);
?>

5) go to http://localhost (or the ip address of your machine), and you should see a listing of all the Homeseer devices you have, including all details.

6) Here are some other examples on how to control HS using PHP:

Turn on a device named A4:
Code:
$hs->ExecX10("a4","off","0","0");

Write to the HS log file:
Code:
$hs->WriteLog("PHP","This is a test");

To check the status of a device named A4:
Code:
$hs->devicestatus("A4");
 
Just tried this How-To and wanted to let you know it worked with no errors.

Can you expand on this topic a little. How would i send an off, on, and dim commands. I am using Z-wave devices. Does it make any differnece what type of device it is or are all the commands the same?

Maybe you could provid us with an example similar to the status control page that comes with homeseer
 
I added some examples to the how-to, as you can see it just uses the command syntax shown in the HS help files.
 
Heres another example whic was written by a newb (me) if i can do it than anyone here can do it.

Code:
<html>
<head> </head>
<body>
<?php
$hs = new COM("HomeSeer.Application");

$click = $_GET['click'];
$address = $_GET['address'];

if ($click==on) {
   $hs->ExecX10($address,"on","0","0");
} else {
   $hs->ExecX10($address,"off","0","0");
}
unset($hs);
?>

<?php
echo '<a href="' . $_SERVER['PHP_SELF'] . '?address=q20&click=on">Q20 On</a><p>';
echo '<a href="' . $_SERVER['PHP_SELF'] . '?address=q20&click=off">Q20 Off</a>';
?>

</body>
</html>

Change out q20 for the address code of the device you want to control
 
Hello all. My name is Dale Higgs. I was just posting to let you know that I have made a plugin for HomeSeer that allows you to easily interface PHP and HomeSeer without the use of an extra webserver, just HomeSeer's built in one. The forum topic is located on HomeSeer's message board. Here is a direct link to the topic: http://ubb.homeseer.com/eve/ubb.x?a=tpc&s=...3515#1776003515 Hope you guys find this useful! If you need to contact me for ideas, questions, or concerns, please email me at [email protected]. Please note that you do have to remove "_NO_SPAM" from the email address.
 
When i use this code i get a return of all 17's (Unknown) but i know for a fact that the status is known.

Code:
$device.="<td>$What->Status</td>";

I have come up with a temporary work around but it doesnt support Dim and I had to add some extra code in. Basically what I did was called $hs->DeviceCount and then used $hs->GetDevice(i) to create the Device Object. Then I called the function isOn and isOff and place them in an If Statement to determine if the device is on or off. $hs->isON("A1") Looks Something like this...

Code Not Tested:(WIll Test Later)
Code:
<?php
$hs = new COM("HomeSeer.Application");

$DeviceCount=$hs->DeviceCount();

for i=1,$DeviceCount+1, i < 1{
   set $Devices = $hs->GetDevice(i);

   $Device=$Devices->hc();
   $Device.=$Devices->dc();
   if ($hs->isOn($Device)) {
      ***Do Stuff***
   }
  elseif ($hs->idOff($Device)){
      ***Do Something Else***
   }
}
?>

So im happy that i figured out the work around and I can live with it but I would love to be able to read an actual status and determin the actual dim level that the light is set to. Does anyone here have an idea of what i need to do in order to get that information?
 
Squintz, according to the HS scripting docs (in the HS help file), dim level as a numeric value (%) is held on the X10 devices (A-P,1-16) in the devicevalue. You can access this using the built-in scirpting DeviceValue(), SetDeviceValue(), and DeviceValueByName() functions.

I'm not sure if the Z-Wave value is held here as well. Supposedly, for non-X10 devices, you can use this value for whatever you want.

So, your code will probably have to figure out if the device type is dimmable (which is a flag in the device object - dv.can_dim), then determine where the dim value would be found, and finally display it on your page.

There is also a series of flags in the dv.misc portion of the device object that tells what type of dim the device supports, but you'd probably only need that info if you were trying to dim the device under program control.
 
I'm trying to set this up with apache (+php) on my FreeBSD box, how do I tell it to find 'HomeSeer.Aplication' on the Windows box ?

TIA

Pete C
 
Unfortunately that isn't going to work, apache/php has to be installed on the same machine as HS.
 
not to be a PITA, but I thought DCOM could do this ? ?

(the newbie status is correct, looking for the 'why not")

Pete C
 
Pete, you are right about DCOM, it's just that I have never gotten it to work, and I have never heard of anyone else who has gotten it to work either.
 
Back
Top