May 1, 2016
Amazon echo for home automation using x10 and ifttt.com
The way this works currently is you need to be able to access a remote url inside your home.  Usually this will require the use of a dynamic dos host provider that can provide you with a hostname that points to your dynamic home address that is updated automatically by your router.  This is not exactly ideal security wise but obscure enough that you’re not likely to have some hacker turning your lights on and off just to mess with you and about the worst case scenario is they turn all your lights on while you are way turning up your electric bill.
That said here is what you need the firecracker CM17A module from x10 and modules to control. Â We start by creating a web server on a local linux box with the CM17A plugged in. Â You can create a virtual machine too and assign the local com port to the virtual machine. Â This is the setup I have on a 5018A-FTN4 running esxi and pfsenseI installed along side it ubuntu. Â I added the com port to the VM and used app-get to install bottlerocket.
Once that was setup I used the following command to test control.
br -x /dev/ttyS0 M1 ON
br -x /dev/ttyS0 M1 OFF
This toggled the module on and off again.
Next I modified permissions on /dev/ttyS0 to read write for user group and world.
chmod +666 /dev/ttyS0
Now we need a script to control the app. Â Created a quick script in /var/www/html/x10control.php
<html>
     <head>
         <title>x10 Home Control Page</title>
     </head>
     <body>
<?php
$areas=[“office”=>[“M1”, “M4”]];
$location=$_GET[‘location’];
$mode=$_GET[‘mode’];
$device=$_GET[‘device’];
$modules=[];
if($device==‘ALL’){
   foreach($areas[$location] as $module){
     array_push($modules, $module);
   }
}else{
   array_push($modules, $device);
}
$cmd=‘br -x /dev/ttyS0 ‘.implode(‘,’, $modules).‘ ‘.$_GET[‘mode’];
echo exec(escapeshellcmd($cmd));
?>
     </body>
</html>
Modify the areas array to match your layout and you can even create another key level to define the name of each device you wish to control.
Now we can test calling from the command line.
curl http://localhost/x10control.php?location=office&device=ALL&mode=OFF
curl http://localhost/x10control.php?location=office&device=ALL&mode=ON
If this works as expected M1 and M4 both turn off and on.
Now to IFTTT.com to create our trigger.
Go to My Recipes and Create a Recipe on the next place click this and then the Amazon Alexa Channel. Â You should have to link your echo at this point. Â Once linked Click Say a specific phrase.
From here we want to create a trigger of what to say to kick off our ifttt.
Next click that and we want to select our Action Channel. Â In the search box type maker and we want to sleep the Maker Action Channel.
We want it to make a web request.
Here we will enter our external address to access our PHP script.
Lastly we create our Recipe
Once created we can repeat with he phrase all office lights off and change the url mode argument from ON to OFF and you can now with voice control your x10 items with your amazon echo.