This past Christmas we received an Amazon Echo as a gift. The Echo is the smaller version of the full Alexa, just without the large speaker
If you’ve seen some of my posts here, I’ve been using x10 modules for a long time. Being on the thrifty-side, and not wanting to re-invest in a completely different home automation system, I set about getting the two to work together. In fact, you should probably read the above post first to see how I have x10 working with my server if you’re looking to do the below with macOS.
So, how do you bridge a modern voice control system like Alexa with home automation gear that was invented in 1975, but still sold today? Scripting, DropBox and a service called If This Then That (IFTTT).
I could write an entire blog post about IFTTT alone, but the short version is IFTTT can take input from one type of service or product and then do something with that input to a different service. For us, we’re going to take a voice command to Alexa, drop a text file into Dropbox that will trigger an event on our Server that hosts the x10 CM17A “Firecracker” interface to tell our modules what to do. It sounds complicated, but it really isn’t and works like a charm!
Most everyone knows what Dropbox is, it’s an online cloud service that lets you synchronize files with your computer. We’re going to make a directory in our Dropbox to be used exclusively by this process. I simply called mine x10.
- Login to IFTTT and choose New Applet.
- Click +this and choose Amazon Alexa and then choose Say a Specific Phrase.
- I’m going to create one to power on our printer, which is downstairs and we often print to it from upstairs. This will save us a trip. So, I enter: printer on and click Create Trigger.
- Click +that, choose Dropbox and then choose Create a Text File.
- Erase the pre-filled File Name and just call it printeron, Content can be anything but must have something, so I just use x10, and for the Dropbox Folder Path just use your custom folder from above, in my case x10/
- Finally, click Create Action and then Finish. When you’re done, it should look like the image on the right.
If you wanted a companion Applet to turn the printer off, just repeat the above process with the trigger phrase printer off.
All of the following referenced scripts are over at my GitHub repository. I’ll put them below for reference, but you might want to use the ones from GitHub as I’ll be updating those on a regular basis after this post goes live.
The first script is an x10 pre-handler I wrote because x10 modules can sometimes be stubborn and is what is called by my main script. It also does some custom notifications for the other x10 timed events I use:
#This script works with http://www.heyu.org/ to control X10 units. X10s have an issue
#where they sometimes don't register commands, either due to a large home, many electrical
#sub-panels, or line interference from other devices. This script will resend a command
#over several seconds to be sure that the modules receive the signals. It will also use
#https://github.com/julienXX/terminal-notifier to display completion of the command.
#Examples shown if you want to name modules.
if [ "$MODULE" = "A7" ]; then
DISPLAY="A7 Steve's Notebook is"
if [ "$MODULE" = "A8" ]; then
DISPLAY="A8 Holiday Lights are"
if [ "$MODULE" = "A9" ]; then
DISPLAY="A9 Morning Modules are"
if [ "$MODULE" = "A10" ]; then
DISPLAY="A10 Afternoon Modules are"
while [ $COUNTER -lt 5 ]; do
"$HEYU" "f""$ONOFF" "$MODULE"
NOTIFY="$DISPLAY"" now ""$ONOFF"
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title 'X10 Module' -message "$NOTIFY" -appIcon ~/Scripts/GitHub/x10/x10.png
You could just skip it and replace the calls to it in the below script with direct heyu commands too.
Now we need a launchd entry on my macOS Server to watch for changes and trigger the x10ifttt.sh script to turn modules on or off. You could easily mimic this with cron on Linux if that is your OS flavor.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Next, my IFTTT script (x10ifttt.sh) which is what the above launchd item triggers:
#This script monitors a Dropbox location for specific files dropped by the IFTTT service.
#When a matching file is found, it triggers an X10 module event and the file is cleaned-
#up. See the accompanying launchd script that must be added to your system to trigger this
#Location of the directory to monitor.
#Bedroom Lights On
if [ -e "bedroomon.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh on a2
#Bedroom Lights Off
if [ -e "bedroomoff.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh off a2
#Laptop Adapters On
if [ -e "laptopon.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh on a7
#Laptop Adapters Off
if [ -e "laptopoff.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh off a7
if [ -e "printeron.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh on a3
if [ -e "printeroff.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh off a3
#Holiday Lights On
if [ -e "holidayon.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh on a8
#Holiday Lights Off
if [ -e "holidayoff.txt" ]
/Users/majorsl/Scripts/GitHub/x10/x10.sh off a8
Putting it all together…
Our chain of events are as follows:
- I say “Alexa, trigger printer on”.
- Alexa hears this and sends IFTTT the command to create a txt file in my Dropbox at the path /x10/printeron.txt
- Using the lanuchd service, my server is monitoring that Dropbox directory on my server for changes. It sees a change and runs my x10ifttt.sh script.
- The script looks for files named a particular way and executes the x10 command if a matching one is found. In this case, it finds printeron.txt which tells it to send the command to turn module a3 on. It then removes the text file so it isn’t present the next time I send a command.
- You would think there might be a delay with all of this happening. To my delight, there isn’t much. The time of a spoken command to x10 module event is on average +/- 3 seconds. Heavy network traffic into your LAN might add a few seconds, but so far my command success rate has been 100% after two months.
- At some point I plan to re-work this so that only one command will be needed eg: “trigger printer”. This will require some logic so that the script remembers the last state of the device (on or off). Unlike the newer automation boxes, there is no two-way communication with x10, and thus no way to retrieve the current state of the module.
- You’re not limited to Dropbox. This could be easily changed with your choice of services: Google Drive, OneDrive, or something else so long as IFTTT supports the service.
- This is just a working framework for macOS/Linux, you could also do this on Windows using a x10 program and Task Scheduler as a substitute to launchd’s “watch folder” process.