Control Your Home From Your iPhone 2.0 - Full Tutorial
To celebrate the release of the iPhone 2.0 this post is an expansion of my original tutorial and goes through everything you need to do, step by step, to control your lights, doors, etc… using x10 and PHP technology all from your iPhone 2.0/iTouch. This tutorial assumes that you have a working knowledge of HTML, CSS and PHP, and have downladed the iPHC v1.3 files.
Step One: Web enabled device - any device that can connect to the Internet will work once you have everything set up. (Note: The iphc1.3 package includes an iPhone/iTouch specific interface, but still looks good in a web browser on a PC.)
Step Two: Web Server with PHP - You’ll need a web server that has PHP installed on it. Most likely it will be an install on your home PC because you have to have the ActiveHome x10 USB module plugged into the computer controlling the house. The module comes with a driver download which will be necessary as well. My install is on Windows XP running Apache, PHP and MySQL. The interface can work without MySQL but it is cooler with it so I have included an SQL file in the iphc1.3 download. This is the tutorial I used for Apache, PHP, and MySQL install on a Windows PC. I also suggest installing phpMyAdmin to make working with your databse(s) and uploading the iphc1.3 SQL file easier. You will need to create a database (I called mine “fonhome” - haha) before uploading the SQL file btw.
If your install goes well you should be able to replace the contents of htdocs with the files from the iphc1.3 download, open your browser and type in localhost, and see the interface. Download the iPHC version 1.3 here (the code is not well commented yet but I will be adding more comments soon). If you are using a router you will have to configure it before you can connect to your interface from the Internet via your ip. I am not sure if this is possible for every isp but it works for me.
Look up your computer’s ip address in the command prompt by typing ipconfig. Allow that address on port 80 in your router and you should be able to get through to your interface through any web enabled device using the ip address that is currently provided to your by your isp (check your ip address here). Do this carefully! There are tons of tips on doing a safe and protected Apache install using the .htaccess and Apache’s htpasswd so check them out. Opening your computer to the public can be risky guy.
Step Three: The Hardware - There are many different modules out there that accept incoming x10 signals. For this tutorial you will need at least the ActiveHome Pro USB module plugged into your computer running PHP and into the wall, and one x10 module. I bought a package that included several modules (most importantly the USB one) that was perfect for testing. I also purchased a x10 Universal Module and Schlage Electric Door Strike for unlocking my door remotely (the code for which is included in iphc1.3).
Step Four: The Code - At this point you should at least be able to view “localhost” in your web browser and manipulate the pages in your main web folder.
The way the interface works is quite simple. There is an .exe file (ahcmd.exe) that is available in the ActiveHome SDK for the ActiveHome Pro that allows x10 signals to be sent through your house using PHP functions to trigger the events (I have included the exe file in the iphc1.3 package but not the full SDK documentation). This file will need to be included in your main web folder where your index is located (or at least somewhere that you can point to it).
The PHP: This is the line of PHP code that turns any x10 module set to address A1, off:
exec(”ahcmd.exe sendplc a1 off”);
ahcmd.exe accepts several commands, sendplc being one of them. There is more documentation on the accepted commands here but this system uses sendplc exclusively. The function is carries out by PHP’s exec command which you can learn more about here. In addition to the “off” function there is also “on” (duh), dim and bright.
The most efficient way to trigger an event using HTML and PHP is AJAX ( or AJAH more appropriately depending on who you ask). Either way, I decided to go with that in the iphc1.3 code and also featured it in my “iphc PHP and AJAX Breakdown” post which you can view here.
Macros: To make a series of x10 events, you really only need to copy the above code for as many events as is needed and change the addresses/statuses. I have found that using PHP’s sleep function to put a second or two (or more depending) between events makes for a more reliable macro. Once again, my full code is included in the iphc1.3 download.
The CSS, Javascript, HTML: I have used some Javascript to make the navigation buttons work, as well as to hide the navigation bar on the iPhone. The css provided is a “green” theme including several icons that can easily be swapped out. The HTML is well, HTML. If you think it is messed up, let me know. Everything is set up to look spiffy on the iPhone 2 interface.
That’s all folks! Let me know if you have any questions.
PS - I am still working on a little video to show the interface in action, and a iPHC version 2.0. Stay tuned.
Tags: Apache, automation, iphone, iPhone 2, itouch, MySQL, PHP, x10

14 Responses to “Control Your Home From Your iPhone 2.0 - Full Tutorial”
July 2nd, 2008 at 11:40 pm
I’d like to know if this can be made to function with the Insteon 2414u USB controler (considered an upgrade to X10 technology, yet maintaining backward compatibility).
Insteon modules are a little more expensive but the added features and increased security should make it worth the additional cost.
July 3rd, 2008 at 8:33 pm
@Mo: It doesn’t look like there is an SDK out for that module.
July 8th, 2008 at 8:42 pm
[...] 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 [...]
September 19th, 2008 at 12:58 am
Would it be possible for you to Post your Apache tutorial again? the link is broken.
September 19th, 2008 at 9:03 am
The link to the Apache tutorial is fixed.
September 19th, 2008 at 12:01 pm
This is excellent. I’ve managed to install apache and mysql server and can access the index.php page on my iPhone! A great start. But it says “Unknown database ‘fonhome’”, and I’m cluless where to go from here. Any help would be appreciated. I’m a complete novice at this stuff.
September 19th, 2008 at 12:38 pm
@Ash - install phpmyadmin, create a database called fonhome and then upload the iphc 1.3 mysql file to the database.
September 23rd, 2008 at 9:39 am
THANKS CHUCK! (And Joe Hewitt for iUI, upon which this depends.)
Managed to port this to bottlerocket on Linux (http://www.linuxha.com/bottlerocket/) with the CM17A.
I’m moving the commands (ahcmd.exe and bottlerocket have _similar_, but not identical command line arguements) and DB settings out to a config.inc. and will send the diffs to Chuck. It’ll probably be a couple days.
Chuck, have you considered moving all the x10 controller names into the db and keying off the house code/id number instead of hardcoding into ajaxget.js and getstatus.php?
September 23rd, 2008 at 9:52 am
Thanks Bengt-Erik!
I actually think it makes the most sense to move the addresses to a DB like you suggest and create a user admin for adding lights and changing addresses. Look for those additions in iPHC 1.4.
I appreciate your enthusiasm and look forward to see what you have been working on.
September 30th, 2008 at 4:20 am
Take a look at this:
http://www.iphone-home-automation.com/
Maybe you should join!
October 1st, 2008 at 6:52 pm
Will this work with an ocelot controller.
October 2nd, 2008 at 6:04 pm
@Darby: Not that I can tell. That has it’s own special interface. It does not seem to be web based.
October 6th, 2008 at 11:08 pm
@Bengt-Erik Norum
Hey, I’m using bottlerocket (db9 transceiver) on a linux box — have you successfully ported this for br? Could you share a source for d/l?
Thanks!
July 8th, 2010 at 11:50 am
[...] jeg er jo ikke Denonbuster, men i mitt etterhvert rikholdige bokmerkebibliotek har jeg disse: Control Your Home From Your iPhone 2 | iPhone Home Controller og Melloware - Creative And Useful Software __________________ Anti-Pesto
Leave a Reply