Hack70.Control the Lights Using Your IP Phone


Hack 70. Control the Lights Using Your IP Phone

Using an X10 phone controller, you can turn your lights on and off from the comfort of your IP phone.

X10 home-control interface equipment has been a favorite pastime of geeks for decades. Since the early days of 8-bit hobby computers, you've been able to automate your home using your keyboard (and later, your mouse). X10 interface controllers connect to lights and other appliances in your house, and your computer can send serial commands to the controllers to turn them on and off and adjust voltage like a dimmer. Some X10 interfaces even offer telephone-based user interfaces, letting you control them by calling them with your phone.

There are a few ways to integrate X10 controls with an Asterisk phone system. The integration method depends on the type of X10 controller purchased. For this hack, I chose the X10 TR16A phone controller that operates by DTMF digits. Ordinarily, you would hook a phone line to it and then call that phone line with a standard phone to operate the TR16A. But, with Asterisk, you can connect directly to the TR16A as if you yourself are the phone company. Then, controlling the TR16A is as simple as a dial-plan hack in Asterisk.

The Asterisk system I used to connect to the TR16A contains a single Wild-card TDM400P using two foreign exchange station (FXS) modules and one FXO module. The system has one analog phone and one SIP-enabled Polycom IP500 phone. The SIP phone is the one I used as my "remote control"the phone from which I sent my commands to the X10 controller.

I performed the following steps to integrate the TR16A with the Asterisk system.

For the TR16A controller:

  1. I connected it to a suitable 120VAC outlet.

  2. I set the Answer delay switch to Minimum.

  3. I set the controller to the appropriate house code.

  4. I set the four-digit PIN to verify access when accessing the unit. (The device includes instructions on how to do this.)

  5. I used a modular cord to connect from the RJ11 port to the Asterisk FXS port.

For the Asterisk system:

  1. I assigned the FXS port an extension number using an Asterisk Dial command.

  2. I set the SIP peer for the IP phone to pass digits in-band (dtmfmode=inband).

  3. I set the SIP peer for the IP phone to use the G.711 uLaw codec.

Here's the bit from /etc/asterisk/extensions.conf that you would use, assuming the FXS port is Zap/1:

 exten => 100,1,Dial(Zap/1) 

Here's the bit from /etc/asterisk/sip.conf:

 [200] username=200 secret=200 type=friend dtmfmode=inband disallow=all allow=ulaw 

Verifying if the setup is correct requires a few test calls. Use the Polycom IP phone to call the controller. Go off-hook on the IP phone and dial the extension number assigned to the controller (100 in this example). The line will ring for about 15 seconds before the controller will answer. When the controller answers, you will hear three beeps. Enter your PIN code, and then a second set of three beeps will confirm that you entered the proper PIN code. After the second set of three beeps, enter the module number you want to control, followed by * or # to turn the module on or off, respectively.

I mentioned that there are a few ways to integrate X10 controls with Asterisk. Using the TR16A, I demonstrated how you could connect to an Asterisk phone system using an FXS port and an IP phone to operate the X10 controller. X10 has another controller known as the CM15A. The CM15A connects to your local PC using a USB cable, and it boasts a free SDK that you can use to write custom scripts. Using the Asterisk system's IVR function, you can program Asterisk to run a script. In turn, that script can control the X10 modules, allowing for a pure software-based solutionthat is, no FXS interfacing necessary.

5.13.1. Hacking the Hack

To have Asterisk dial the PIN code for you automatically, add it to the extension definition that dials the controller (assuming your PIN is 1212), so that it dials your pin automatically after connecting:

 exten => 100,1,Dial(Zap/1,30,D(1212)) 

Joel Sisko




VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net