Loading...

Posts Tagged ‘automation’

Control Your Home From Your iPhone 2.0 - Full Tutorial

Wednesday, July 2nd, 2008

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.

iPhone Home Controller - Project 1 v1.2

Wednesday, November 28th, 2007

iPhone Home Controller version 1.2

We have upgraded version 1.1 with a re-vamp of the AJAX form submit. Goodbye jQuery (for now). I was able to get all the same functionality (and more) out of a smaller script that required no additional JavaScript library to be available for it to work. Now, when a light is turned on/off, the form is posted with AJAX and then the appropriate style of light icon is pulled up and replaces its opposite. The script I made for this purpose is a bit repetitive and therefore bigger than I think it needs to be, but it works so I am happy with that for now. If anyone can suggest a better way to code this please let me know.

Another change in this version is the addition of a MySQL database to hold the status of the lights. This allowed me to combine the on and off buttons on all the lamps and pull in the current status of the lights when the page is first loaded (the rest is handled by the above mentioned script). It was fairly simple to set up the database and with a few tweaks to the PHP.ini file, I was up and running.

We are going to be starting a similar project with the same interface but a Basic Stamp and Parallax PINK server as the base so stay tuned for that. Until then, if you would like you can download the iPhone Home Controller v1.2 PHP, JavaScript and HTML files using the link in the sidebar to the right. Don’t forget that you will also need the iUI.js file found here. Peace!

iPhone Home Controller - Project 1 v1.1

Tuesday, November 13th, 2007

iPhone Home Controller Project 1 v1.1Here is version 1.1 of the Home Controller project. In addition and revision to what I posted in “Control Your Home With Your iPhone“, I have incorporated the JavaScript and some of the CSS from the iPhone User Interface, aka iUI, project. The iUI gives some of the look and functionality, mainly the sliding panel navigation, of the iPhone’s internal apps to a webpage or webapp for the iTouch and iPhone.
Other than that I have decided to go with Safari’s native submit button style and simply changed the background colors to suit. The light interface now also includes a dim and brighten option for all light modules that support it.

  • HTML - some of the markup changed from the first project because of how the iUI works but everything is still forms and input buttons. The one other difference is that I am using the “bright” function now so lights can be turned up as well as down:

    You can view the HTML file here.

  • CSS - the new CSS file incorporates some of my original coding and some plucked from the iUI.

    View the complete CSS file here.

  • PHP - the markup has not changed since version 1. I am still wishing that I could get the ActiveHome SDK software’s “queryplc” function to poll devices and return on/off and dim status.
  • JavaScript - as I stated above I have used the iUI iUI, the iPhone user interfaceto achieve a interface that is more like the rest of the iPhone’s native applications. I didn’t change anything in the iUI script save for changing the slide rate from 20 to 90. With 20 as the slide rate my interface was quite clunky.

That’s it for now. The next update will be soon, once I get my doors to unlock with the system. And then on to the TV! I promise there will be a video demo soon. You can download the files for this version in the sidebar to the right. Peace!