After looking at all the automation options, I decided on using the X10 standard. It's affordable, extremely flexible and most importantly I don't need to make any physical modifications to my rental house to implement it. X10 using existing power lines to communicate by using adapters that sit between the power socket and the device to remotely turn devices on and off. Also available among a huge list of optional adapters are light socket adapters that similarly interface between the light socket and the light, providing remote control lighting.
I purchased and quickly implemented a number of X10 power and lighting adapters and a remote to control them. They worked great, but I wanted more. I wanted to control more devices and I wanted to do it remotely, these are all things that X10 does not offer.
X10 is cool, but I need more
Enter Asterisk, the open source, Unix based, PABX solution. I had worked with Asterisk before for several businesses I supported, but only with simple dial plans and voice mail. While Asterisk is designed as a PABX, it has all the required framework to be a great automation conduit. The key features I want to leverage are the support for complex menus, ability to trigger Unix scripts and most importantly the ability accept remote commands via a VOIP dial-in number.
My plan was to setup Asterisk to handle all the triggering of the automation, then if I was at home I could use my portable VOIP phone or off-site I could dial in with my mobile.
The first steps to home automation
The first step is to setup your Linux based PC with the X10 computer interface module, install and setup Asterisk and register your VOIP phone number with the Asterisk box. I have been using VOIP at home for a number of years, so it was easy for me to connect my handset to Asterisk and then let Asterisk connect to my VOIP provider.
What I love most about Linux is the way things so easily connect together with scripting tools such as grep and awk. I set about making a number of scripts that when requested from the Asterisk dial plan, would go about performing my tasks. I was able to automate the following tasks via Asterisk.
- Getting a temperature reading from inside my house remotely by using a USB based temperature probe
- Turning on/off lightning and my coffee machine
- Inputting scheduled recordings into my Media Center by the use of a small C++ MCE tool I coded (available here)
- Starting and controlling my air conditioner via the use of a USB infrared transmitter
- Activating a web cam in my house and triggering an iptables port forward of the webcam. I could then view the RTSP feed via my mobile phone.
- Accepting all commands via voice input using the Sphinx speech recognition framework
- Voice based SSH port knocking
- Getting the Asterisk box to tell me my IP address for remote access
- Controlling the current state of my house via external scripting. For example, after 10:30PM, my house would set it self to a sleep state, redirect all incoming VOIP calls to voice mail.
- The ability to schedule wake up calls
- All incoming numbers would be announced over a speaker before the phone rings
What you need to build a similar setup
- A Unix based system - I went with Debian Linux and a MSI Titan 700 Via C7 based system
- Asterisk PABX installed with swift installed if you want text 2 voice
- X10 power/light modules
- X10 to rs232 adapter for PC based control of X10 devices
- A TEMPer USB temperature logger for temperature awareness
- External speakers for announcements
- The Sphinx speech recognition toolkit and sphinx.agi for Asterisk if you want speech recognition
- The Linux heyu X10 control software installed
The beauty of Asterisk is that via the "asterisk -rx" command, you can issue commands directly to Asterisk via the Linux command line. For example you could have a X10 movement sensor setup with the heyu daemon listening to trigger a specific script when any movement is detected. That script could then initiate a dial-plan that calls you and reports there has been movement detected. You could then, via Asterisk and your VOIP number, remotely dial in and trigger your webcam stream to be started which you could view on your mobile phone.
To tie everything together I wrote two sets of scripts that worked in separate ways.
One set of scripts are triggered by Asterisk events. Any time I call Asterisk and speak or dial a command, these scripts are triggered to perform tasks such as turning on a light or reading back the current temperature via text to voice.
The second set of scripts are triggered by events such as time of day, a motion sensor being triggered or an iptables logging event. This second set of scripts then initiate Asterisk commands via "asterisk -rx" or performed other tasks such as turning light on or off.
I took things a step further by creating an Asterisk variable called "house mode". I included lists of settings for modes such as phone, night, day, sleep and do no disturb. Based on the current house mode, speaker volume can be automatically adjusted, asterisk can choose whether to ring the phone or send the call directly to voice mail and lights can be dimmed or toggled.
You can potentially store any variables you want in Asterisk via the database put function, but for reliability it is best to store them somewhere more "permanent". For example I keep the current house mode in a flat file and use that file to populate the database as per the example below.
asterisk -rx "database put x10 housemode `cat /etc/heyu/state/housemode.curr`"
Some code examples
This is by no means a small project, it requires extensive bash scripting to link everything together. I have included some code examples below that will hopefully give you some ideas and help get you started.
- Asterisk Extensions.conf examples - this is where all the magic takes place
- A bash script that Asterisk uses to check current house temperature and announce it
- A bash script that Asterisk uses to make an announcement over the speakers
- A bash script that Asterisk uses to open a port no the firewall, VOIP based port knocking
- A bash script to schedule Asterisk to make a phone call
- A bash script that gets the current IP and converts it to a WAV file, ready for Asterisk to play back
Hopefully you can use some of these ideas to get started but please don't hesitate to contact me for more information.
just curious to see if you're developing x10 anymore with asterisk.
ReplyDeleteGreat job on what you have accomplished!
Dear James
ReplyDeleteKindly contact me on my email address: ahmed@mltsc.com
ASAP
Thanks
best publicize! this is a every percentage of easy to apply weblog that i can definitively come steerage to greater epoch this yr! thanks for informative proclaim. control4
ReplyDeleteThis is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. roller blinds bunnings
ReplyDeleteI read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. Visitor Management
ReplyDeleteMore prominent understanding and organization control-Automation helps make IT tasks more receptive to change through investigation. factory material handling self-driving vehicle
ReplyDelete