- Linux box, preferably a Raspberry Pi
- HEYU installed
- Apache installed
- PHP installed
Step 1 – Raspberry Pi goodness?
The first step is to get your Raspberry Pi up and running. There are plenty of guides how to download and install either NOOBS, or RASPBIAN on a memory card for your RPi, so I won’t go into those details unnecessarily. Suffice it to say, you’ll need to have your RPi booted into Raspbian and configured to your location and language, including SSH enabled.
Once you have the RPi working you can SSH (remote) into it and log in as the user Pi. For PC you can use PUTTY, or MAC use the Terminal Window to SSH into the Pi. At this point I would also recommend you update and upgrade your RPi, by entering the following:
$ sudo apt-get update
$ sudo apt-get upgrade
I also recommend changing the default password.
Once updated and upgraded, power down your RPi, and make all the following connections:
- Install batteries into the CM11A
- Plug the control cable into the CM11A jack
- Connect the Serial Adapter to the X10 CM11A’s serial cable
- Plug the CM11A into a wall socket
- Plug the USB to Serial Adapter into the RPi
Power your RPi back on, and SSH back into it.
Step 2 – Heyu turn on my lights!
Let’s install heyu, which is a text-based console program for remotely controlling lights and appliances in the home or office. I put heyu in a directory I created named ‘src’.
Here are the steps I completed:
$ ls -l /dev/ttyUSB0
- You should get something like the following:
crw-rw---T 1 root dialout 188, 0 Aug 10 20:44 /dev/ttyUSB0
Make note* of the last part, you’ll need it later.
$ mkdir src
$ cd src/
$ wget http://www.heyu.org/download/heyu-2.11-rc1.tar.gz
(Or current version)
$ tar xfvz heyu-2.11-rc1.tar.gz
$ cd heyu-2.11-rc1/
$ sh ./Configure.sh
The installer will run, make a cup of coffee.
More installation, drink the coffee you made.
$ sudo make install
You should then see the following:
I did not find a Heyu configuration file.
Where would you like the sample Heyu configuration file installed?
1. In directory /home/pi/.heyu/
2. In subdirectory .heyu/ under a different user home directory
3. In directory /etc/heyu (for system-wide access)
4. No thanks, I'll take care of it myself
Choice [1, 2, 3, 4] ?
1 and you’ll see:
Creating directory /home/pi/.heyu
The sample configuration file will be installed as /home/pi/.heyu/x10config
The next question the program will ask is the following:
I will add the TTY port for your CM11 to the config file
Specify /dev/ttyS0, /dev/ttyS1, etc., or the word dummy
To which port is the CM11 attached?
/dev/ttyUSB0 (or whatever you noted* earlier).
Now you can test the install, enter
$ heyu info, and you should get an output with details about the heyu install that look similar to the following:
Heyu version 2.11-rc1
Configuration at /home/pi/.heyu/x10config
Powerline interface on /dev/ttyUSB0
Firmware revision Level = 1
Interface battery usage = 0:00 (hh:mm)
Raw interface clock: Sat, Day 212, 14:07:35
(--> Civil Time: Sat 01 Aug 2015 15:07:35 EDT)
Uploaded schedule will expire in 154 days.
Housecode = M
0 = off, 1 = on, unit 16.......8...4..1
Last addressed device = 0x0002 (0000000000010000)
Status of monitored devices = 0x0042 (0000000000010001)
Status of dimmed devices = 0x1112 (1110000000010000)
Now let’s test to see that you can turn a light on and off. My housecode is M, but use your chosen housecode. Try the following:
$ heyu on M2 and the module set to M2 should turn on, alternatively
$ heyu off M2 and the module set to M2 should turn off.
Step 3 – Are you being served?
Next we will install an Apache server and PHP5 on the RPi , here is what I did to accomplish that:
$ sudo apt-get install apache2 -y
After this install completes, you should be able to navigate to your RPi’s Apache server. Type the IP address of your RPi into any browser, for me it’s 192.168.1.19, and you should see an “It works!” page.
Let’s install PHP:
$ sudo apt-get install php5 libapache2-mod-php5 -y
The user that runs PHP exec commands on Apache installations is www-data. We’ll have to allow the www-data user permission to use the ttyUSB0 device (or what you noted* earlier in Step 2 as your USB to Serial Adapter device name). One way to do this is to modify the ttyUSB0 permissions on boot. NOTE: Due to security concerns, this should only be done on a Raspberry Pi that is not accessible from the internet!
$ sudo nano /etc/rc.local
chmod 666 /dev/ttyUSB0 &to the file on the line above the ‘exit 0’
- Save and exit the file
We should also modify the ttyUSB0’s current permissions so we can move forward with our install by doing the following:
$ sudo chmod 666 /dev/ttyUSB0
We will also have to allow www-data permission to run heyu commands. NOTE: Due to security concerns, this should only be done on a Raspberry Pi that is not accessible from the internet!
$ sudo visudo
- Add the following to the last line of this file and save:
www-data ALL=(pi) NOPASSWD: /src/heyu-2.11-rc1/heyu
Step 4 – Get Control!
The code goes in the your Raspberry Pi’s Apache server /var/www/html/ folder, so it’s the default served page. NOTE: The directory was /var/www in Raspbian Wheezy but is now /var/www/html in Raspbian Jessie. Clone the latest release from my Git repository by doing the following:
$ cd /var/www/html
$ sudo git clone https://github.com/audiofreak9/PHP-X10-Control .
YES, the period at the end is needed so only the files are cloned, not the containing directory.
The code gets your configured heyu devices and displays their state and gives control of each. Configure your X10 devices in your HEYU config file. To locate your config file enter the command
$ heyu info and note where your config file is located. You’ll see something like, “Configuration at /home/pi/.heyu/x10config”.
$ sudo nano /home/pi/.heyu/x10config (or whatever your config file address is).
Find the “Aliases:” section of the config file, and enter your devices with name and module address like this:
- ALIAS kitchen M3 StdLM
- ALIAS front M4 StdLM
- ALIAS hallway M5 StdLM
- ALIAS railing M6 StdLM
- ALIAS lockers M7 StdLM
The word ALIAS lets HEYU know this is a device, give them unique names “kitchen” for example, then list the module address “M3” for example, then StdLM for dimmable modules OR StdAM for non-dimmable modules. Once you have entered all your modules, click ‘CTRL + X’ and save the file when prompted. You can also refer to my example x10config file I posted on GitHub here: https://github.com/audiofreak9/HEYU-config-file-example/blob/master/x10config.
It also gets your configured scenes and displays them as well.