Alexa, IFTTT, DropBox, and x10 Automation

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!

Dropbox

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.

IFTTT

  1. Login to IFTTT and choose New Applet.
  2. Click +this and choose Amazon Alexa and then choose Say a Specific Phrase.
  3. 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.
  4. Click +that, choose Dropbox and then choose Create a Text File.
  5. 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/
  6. 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.

Scripting

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:

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.

Next, my IFTTT script (x10ifttt.sh) which is what the above launchd item triggers:

Putting it all together…

Our chain of events are as follows:

  1. I say “Alexa, trigger printer on”.
  2. Alexa hears this and sends IFTTT the command to create a txt file in my Dropbox at the path /x10/printeron.txt
  3. 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.
  4. 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.

Closing thoughts:

  • 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.

 

This entry was posted in macOS, macOS Server, Tech Trinkets. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *