top of page

IFTTT, Google Home, WebServer, ESP8266 and Remote Light Switches


My parents got me the Google Home Assistant for Christmas this year. It is one of the first in most likely a wave of personal home assistants. Current Amazon Alexa and Google Home dominate the field. Google being google however, does a good job of allowing their stuff to be tinkered with by developers.

I recently purchased a Belkin WeMo outlet that I can control with my phone and when I am away. The WeMo is one of only a few that can be tied into the IFTTT (If This Than That) architecture.

IFTTT is a service that ties together lots of other services and allows people to tie actions to events. It is tough to explain, you will have to look at the site to get a good understanding of what all is possible.

So while the WeMo didn't have a direct tie in to Google Home, IFTTT can act as a seamless bridge between the two.

You can create a recipe for a Google Home voice action and tie that to a WeMo device action. So I can say "Ok Google, Turn on Living Room Light" And it triggers an IFTTT Event which then turns on the WeMo. The sequence is fast and you wouldn't be able to tell there is that IFTTT hand off in between.

So what is cool is that there is also a Maker IFTTT action that can be used. Using Maker, you can tie a Google Assistant command to a Web Request to a web server.

So if you set up your own webserver to listen for that request, you can then send off a command on your local network.

As you may know from reading this blog, I have been playing with the ESP8266. This is a low power Wifi Chip that can talk to a microprocessor.


I was also given a set of Remote outlets that can be turned on or off by using a controller. This was cool, but I immediately wanted to dismantle the controller and wire it up to the internet.

And so I did.

Getting from "Ok Google, Dining Room Light On" To turning on the Dining room light using the ESP8266 and the wireless switch remote, took several steps, but I was confident in my abilities and was persistent and now I'm going to give you the basic run down.

The first thing I did was setup a webserver. I have a Windows 10 Laptop setup that I decided that I'm going to use as a server for various things. I downloaded Apache 2.4 and also PHP (I didn't know I needed to download PHP until partway through, so this will save you sometime)

Follow the install instructions for Apache on Windows and setup the Httpd as a service.

One thing I found about Windows 10 is that there is some IISS application in windows that interferes with port 80. (The default HTTP Port)

I could disable this temporarily by opening an admin Command Prompt and running "net stop was"

There are a couple things you need to setup in the http.conf file of your Apache installation to point at the PHP installation.

Then restart the apache demon.

Once you have a web page up, I then created a PHP page that gets the POST information of a HTTP header.

<?php echo 'Post Accomplished! '; $myval = htmlspecialchars($_POST["value"]); echo 'Value was ' . $myval; exec('C:\IoT\IoTInterface.exe ' . $myval); ?>

I created a test page that can post to the PHP page purely for testing, but once you get to the IFTTT part, the php is all you need. Hosting a webpage is a whole different topic of which I'm only sort of knowledgable. (I've done this setup a webpage to execute commands remotely thing before, so I had a basic idea going into this)

One thing I did was setup a free no-ip domain for my IP address, and am running the no-ip service on the laptop to keep the IP up to date.

So once the webpage is receiving the POST data, I then pass that to a server side executable. This is just a small executable written in C# that starts up and broadcasts the data via UDP over the local network.

On IFTTT Connect the Google Assistant to the Maker action. Once the IFTTT Connection is made, you create a recipe that will post a command to your webserver to be broadcast on your local network.

In a nutshell this is what is happening:

OK Google LED ON -> Post LED=ON to WebServer -> Webserver starts Application with UDP=LEDON -> Webserver talks to ESP8266 -> Esp8266 talks to Pic24 over UART -> Pic24 turns on a GPIO connected to Wireless Transmitter -> Wireless Transmitter transmits a 9.8Mhz signal to Outlet Receiver -> Outlet Receiver trips Relay -> Relay lets AC power appliance.


Next was the hardware I just soldered in wires in place of the buttons.

The PIC to ESP8266 Configuration was covered in a previous post, go back and look at that for more depth.

Then was a matter of programming the PIC To trigger the ports based on the commands coming in from the ESP8266.

Et Voila! From push button control to Google Home Control in one afternoon!


Comments


bottom of page