I run a basic home automation setup using retrofitted x10 modules to control lights and appliances. The lights in most rooms are triggered by motion sensors which, while not 100% reliable, work pretty well for the most part. Occasionally I want to override the motion sensors with manual control. I have a controller next to my bed, and my housemate has a dedicated x10 remote next to his, but often I’m on the couch and want to turn something on or off and I want to do it using my iPad (or iPhone) since that device is always nearby.

iPad x10 Home Automation Controller Interface

There are several apps available which already do this. One of them I have been using for sometime. While this works reasonably well, there isn’t an iPad version and it looks rather ugly when scaled up. It’s also not the most efficient system having to scroll through looking for the device I want to toggle. I wanted to create something that looked nice and functioned well, so I decided to have a crack at creating my own solution.

What I’ve made is rather basic, but it does work quiet well for the most part. I thought I’d post it here so that anybody looking to do something similar has a place to start. I’m certain people out there with much more skill than I could come up with suggestions on how to improve this. If you have some feedback, please post it.

Essentially the setup is this:

  • A web-page I’ve created sitting on a web-server. I used WAMP running on a virtual machine that I have setup. The setup I have running requires windows.
  • This virtual machine connects to the x10 USB controller (Part HA125)
  • The x10 SDK is installed onto the machine. This can be downloaded here
  • The virtual machine is networked into the home network, including wireless
  • The iPad navigates to the virtual machines IP address and loads the web page

I chose to do this on a VM for various reasons, but it should work on any windows computer with WAMP, the x10 SDK installed and the x10 USB device attached.

I won’t go through installing WAMP, you can learn more about that here. It’s as easy as installing nearly any other program on windows.

The website was designed to fit the screen of an iPad, but could be designed for anything you want. The page communicates with a little program called “ahcmd.exe” which actually triggers the x10 events. The page needs to be a .php page so it’s able to do this. The “ahcmd.exe” program is part of the x10 SDK. You’ll find it in the examples folder after you’ve installed it.

The page is essentially just a group of forms that submit to this ahcmd.exe program. The forms are styled in a way so they look like graphical buttons, however you could just go with the boring standard form buttons if you wanted. Each “button” for controlling the lights is essentially this code:

<form action=”index.php” method=”post”>
<input name=”hc” type=”hidden” value=”A”>
<input name=”uc” type=”hidden” value=”1″>
<input name=”cmd” type=”hidden” value=”ON”>
<input type=”image” src=”images/power_on.png” value=”On”/>
</form>

The second line specifies the devices house code (“A” in this case). The third line specifies the device number (“1” in this case). The fourth line specifies if the button will turn things on or off. The fifth line links to a graphic of your choice (I whipped up some simple “power” buttons). These codes would have been set when installing your x10 equipment.

At the bottom of the page, I put in the PHP code to make the forms actually submit to the ahcmd.exe program:

<?php
$cmdstring = $_POST[‘hc’].$_POST[‘uc’].” “.$_POST[‘cmd’];
exec(“ahcmd.exe sendplc $cmdstring”);
?>.

That’s essentially all there is to it. A bunch of forms communicating with the ahcmd.exe program, which in turn communicates to the USB x10 device, which sends the commands down the power line to turn a light on or off.

I tried to pretty up the interface by using some photos of the rooms the lights where in along with a built in spry asset of Dreamweaver to create “tabs” across the top of my page. I thought this would be a quicker solution than having each room on its own page and having to load that page each time you wanted to switch rooms. This would only be a second or two, but the tabs mean that you can switch rooms instantly. I loaded in a background image and styled the buttons to my liking using CSS.

Once the page is complete, copy the php file (which should be called index.php), and associated graphics to the root directory of the WAMP install (normally this would be the WWW folder). Make sure the WAMP server is up and running (click on its icon in the system try and choose “Put online” and “start all services”) and then you should be able to open up Safari on the iPad and navigate to http://<machine ip address>. In my case this is http://192.168.1.101

Put Online WAMP

It’s a good idea to ensure that the machine with WAMP installed on it has a static IP.

The last thing I did to make it a bit more “app like” was to create a favourite icon for it and add a bookmark to my iPad’s home screen. Now whenever I want to toggle something I just grab the iPad, tap the icon, choose the room and switch things on or off.

Homescreen icon

This is a quick overview, but hopefully if anyone else is looking to do something similar it gives them a starting point. The best thing to do is to setup WAMP, the x10 SDK and grab the files I made here. This way you can have a play and then modify to suit your needs (replace photos, change device codes, etc). Let me know if you have any questions via the comments system. Below are a couple more screenshots of the page.

Office Screen TV Screen