Monday, 28 August 2017

X10 Home Security DIY - Adding voice control and linking up with online services

X10 Home Security DIY - adding Voice Control with Google Home

The last phase of the implementation involves linking up the Home Automation server with the online world, to take advantage of Google Home and services like IFTTT

IFTTT makes it possible to (for example) schedule a light to turn on at dawn/dusk, to link a Google Home custom voice command with X10, or to have our lights turn red when Manchester United score!

Note that this is the opposite of using IFTTT for notifications - now, we want an external event to trigger an internal action.  This must be accomplished securely - we do not wish to forward a port through our router unless it is highly secure.  Most IoT devices that link to outside web services do it through a secure tunnel: for example, using ngrok.

Using ngrok, we will create a secure tunnel to our internal server: specifically, to the x10cmd.pl CGI script that drives the X10 CM15A.

So the steps are as follows:
1. Create an IFTTT account if you do not have one from the notification section.
2. Add the Webhooks service to your IFTTT account.
3. Create an App (recipe) to trigger on the weather channel, with the "Then" action being the Webhook - fill in the destination IP with your ngrok address (see below). 
4. Install and run ngrok on your server to point to the server port and the CGI script that contains your x10cmd.pl file.

The URL field in the IFTTT app is as follows (use either http or https):
http://serverid.ngrok.io/x10cmd.pl
Where:
  serverid - the URL reported by ngrok when you start it on your server.

The Method field is GET or POST.  With GET you paste the parameters into the URL field (e.g. append ?device=mydev&cmd=mycmd to the url).  With POST you specify the Content Type as application-x-www-form-urlencoded, paste the parameters into the body (e.g. device=A3&cmd=ON) (Note there is no ? needed in the body unlike in the URL).
Where:
  mydev - your internal X10 device id (e.g. A3)
  mycmd - you internal X10 command (e.g. ON or OFF)

For a voice command to do the same using Google Home, create an IFTTT app that triggers on Google Assistant instead.  Here, you can use a custom phrase (like "OK Google, turn the A3 light ON").  You can even use parameters in the trigger phrase, so that it only takes one app to trigger all of your devices; to do this, select the "Say a phrase with a text ingredient" type of Google Assistant trigger, and place $ in they phrase, and "text ingredient" in the action to send the paramter on to ngrok.



No comments:

Post a Comment