Loading...

Control Your Home With Your iPhone

Photo of my iPhone with the home control interface web page up and workingProject 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!

Tags: , , , ,

16 Responses to “Control Your Home With Your iPhone”

  1. How to get a free iPhone Says:

    Free Mobile Phone…

    Hey man, great article, I will bookmark this and pass it on, I have a few friends who will enjoy reading this! Take care…

  2. Sven Says:

    I have the same thing! Only it does a bit more.

    http://www.youtube.com/watch?v=5q-iighX42U

    http://888macdoctor.com

  3. Dierk Says:

    We have a solution for that too. The difference is that our Software runs with Mac OS X and has a build in web server. So there is no Windows PC needed.

  4. Nick Says:

    Will this work on the apple itouch. Not the phone.

  5. boby Says:

    wiil it work on itouch

  6. chuck Says:

    This will work on any web-enabled device.

  7. Lance Says:

    Hi. This is exactly what I have been looking for but I am having some trouble. I tried to follow your directions but I dont know much about PHP. It seems like there are some steps missing like how to structure the files. I got the index.php going but it hangs when it tries to run the form handler. I think im missing some files. Would it be possible to post all of the files you are using in their exact file and folder structure? Thanks.

  8. sani izaidi Says:

    hi….good article

  9. aerotheque Says:

    It looks like if you rewrote it in PERL, queryplc would work… http://www.x10community.com/forums/index.php?topic=7851.msg67236#msg67236

  10. Rip Says:

    Hi,

    This is just what I’ve been looking for. I don’t (yet) have any PHP or MYSql experience and this is a great opportunity to learn.

    I’ve just bought as CM15 as recommended and a couple of lamp modules.

    I’ve installed everything as suggested but get a MYSQL error when opening the index.php file. Would you be prepared to give me some help to kickstart me?

    I’ll email the error to you if you replay.

    Thanks in anticipation.

  11. Rip Says:

    Sorry - that should be ‘reply’!

  12. Ash Says:

    As lance says, I think there are some files missing from the zip. The graphics files certainly are.

    I’d gladly donate for a working copy of this to get me started.

  13. Melloware Says:

    You could also use this native iPhone/iPod application instead of a webapp.

    http://melloware.com/products/x10commander/

  14. chuck Says:

    @melloware
    You could use that app, sure. There are some points that make it undesirable.
    1. It is not an attractive app.
    2. It requires an .exe install on the home PC. Who knows what kind of malware could be in it.
    3. It is not customizable under the hood. The iPHC platform can be re-skinned or re-coded by someone with the know-how.
    4. It is not accessible from all web enabled devices, just the iPhone.

  15. Melloware Says:

    @chuck
    Some counterpoints
    1. Its function over form. Its lightning fast responsiveness no web server request response roundtrip re-rendering. The reviews from users have been quite positive.

    2. No malware…I scan everything with ESET Nod32 before releasing. My other apps have been certified by CNET and Softpedia as 100% clean.

    3. True its not skinnable but it does support the CM11, Cm12, CM15, CM17 Firecracker, and CM19. Does the webapp support all of those X10 devices? Or just the CM15?

    4. This is true…iPod Touch and iPhone only.

    http://melloware.com/products/x10commander/

  16. Melloware Says:

    Sorry, I forgot a point. 90% of users won’t figure out Apache or PHP. they want a drag and drop solution. The exe is just drop in and double click to run and its all setup.

Leave a Reply