Project 1
Note: this tutorial has been updated, as well as the download package. If this is your first time here browse the below info and then refer to this updated tutorial for the current iphc download and reference. For a better idea of what the process has been in making this system read all the posts if you have time.
Welcome. In this project we are going to set up a home automation scheme using x10 automation hardware and a Safari/iPhone/iTouch optimized web interface controller. The cost of this project is minimal, the only monetary input was for the x10 modules ($10 and up depending on what you buy), the ActiveHome Pro USB interface (CM15A - $50), and the not so minimal cost of the iPhone/iTouch (note: this project will serve a web page to any computer but the interface design is specific for the iPhone/iTouch). I bought a simple $100 kit that included the USB module, a lamp dimming module, an appliance module and an RF light socket module among several other parts. The little kit was enough for my tests since I was new to x10 and what it could do. Now the good part about all of this is the rest of this is 100% free outside of your cost in time. Here’s what you need to do it:
The Hardware and Software
- ActiveHome Pro USB interface CM15A
- The ActiveHome Pro SDK and ActiveHome Software: the software (that comes with the USB module) includes a driver for the module and an .exe file that allows communication to the USB module allowing developers to create interfaces in C++, VB, JavaScript, PERL and in my case PHP. The SDK includes the ActiveHome Scripting Interface document which goes through the various types of commands that can be sent/received through the interface.
- PHP and Apache: in order to have a web page (accessible anywhere) as the control interface you need a server that has the USB module plugged into it. Since I am familiar with PHP I decided to go with an Apache install on my home PC to host my interface. Important: if you are installing Apache and PHP for this project use Apache 2.0 not 2.2. The latest version of PHP will work fine. Here is the tutorial I used for install. If you are opening your computer up to the internet like this please make sure you do it securely, and search around for ways to do this. Here is one of many tip lists out there.
- At least one x10 module set to any address you choose.
- iPhone/iTouch or any device that can view web pages
The Code - Please note that my mark-up is based on my basic understandings of PHP and JavaScript as well as the ActiveHome Scripting Interface. Please feel free to school me on better ways to accomplish what I have done here. Also, if anyone else is working on this or a similar project please comment below and share what you have done!
- HTML - for this project, all that is needed to trigger an event is a form submit so the HTML markup is quite simple:
Turn A1 On
<form method=”post” action=”"><input name=”input” value=”a1 on” type=”hidden” /><input name=”onein” value=”1″ type=”hidden” /><input type=”submit” /></form>
Turn A1 On and Dim A2 to 50%
<form method=”post” action=”"><input name=”input” value=”a1 on” type=”hidden” /><input name=”input2″ value=”a2 dim 50″ type=”hidden” /><input name=”2in” value=”1″ type=”hidden” /><input type=”submit” /></form>
View the example HTML file here.
- CSS - of course you can skin your project however you like it but I will share what I did using the Apple iPhone Developer Center’s tips as a basis. I also incorporate YUI’s “reset.css” into all of my projects so it is included here as well.
View the complete CSS file here.
- PHP - I am not a PHP guru, so luckily the markup is pretty simple to get codes transmitted (if anyone has any suggestions or tips to make this better please let us know):
One Input
if (isset($_POST['onein'])){
$cmdstring = $_POST['input'];
exec(”ahcmd.exe sendplc $cmdstring”);
}
Two Inputs with 10 second pause between events
if (isset($_POST['2in'])){
$cmdstring = $_POST['input'];
$cmdstring2 = $_POST['input2'];
exec(”ahcmd.exe sendplc $cmdstring”);
sleep(10);
exec(”ahcmd.exe sendplc $cmdstring2″);
}
As you can see the code uses PHP’s exec() command to push the data that was input from the HTML form. The “sendplc” part is one of the commands that is included in the ActiveHome Scripting Interface. The other available codes are: sendrf - for sending x10 codes via RF, and queryplc - which is supposed to query the on/dim state of any given x10 module (unfortunately I cannot get this one to work and it seems it is broken according to the support forums - if anyone has any ideas on how to get this to work let me know as I would like the interface to be a bit more dynamic by visually representing which lights are on and off)
- JavaScript - for this project I used the jQuery scripting library in order to submit data without a page refresh. jQuery’s AJAX form plugin worked great!
So that is pretty much all you need to know to get this done at your house. Please feel free to ask questions and make comments. I’ll add to this page as the project progresses and stay tuned for a video demo coming in the near future…
Peace!