February 22, 2020

I recently got a new Android phone, and with it came Google Assistant. You can tell it to do things for you and automate simple things. I didn't have much use for this feature because it could only do things on my phone, things I could do myself easily. I knew these special lights and thermostats existed that could be controlled by your Google assistant, but I didn't have any. So I thought it would be fun to build one!

I found this service online called IFTTT (If This Then That). It could detect what you say to your Google assistant and send a request to a server depending on what you say. My plan was to have IFTTT detect when I tell my assistant to turn my light on or off, then send a web request to a server I would be running locally on an old computer in my room. Then using a Arduino micro-controller, an esp8266 wifi module and a relay, I could connect to my local server and toggle the light depending on a variable.

So I went online and since I already had an Arduino and a relay, I just had to buy an esp8266. It cost me around $10. I knew it would take while to ship, so I started working on the server side of things. I had no idea how requests really worked so I had to do some research on how to receive the request IFTTT would send to my server. Finally, using php, Apache and some port forwarding on my router, I was able to set it up. So now I had a system where I could tell my Google assistant to turn my light on and it would change a variable on my server. Next, I need to connect my Arduino to this server and read that variable.

The esp8266 took a long time to ship, but it arrived around a month later. At first, I was not able to program the esp. The easiest way to program then is with a usb to ttl converter, but I didn't have one, so I had to use my arduino as a converter between my computer and the esp. After a week or so of fiddling with the thing, it finally cooperated and was successfully able to connect to my WiFi network. After some research, I was able to connect to my local server with the esp8266 and read the variable. I quickly hooked up a small LED to test it and, sure enough, when I told my assistant to turn my light on, it would turn the little LED on! Now I just had to connect the relay and my actual desk lamp. I cut an electrical extension cord in two and connected it to my relay so I could control the current through it. I connected the relay to the Arduino, and plugged the desk lamp into the extension cord, and BOOM! Voice activated desk lamp complete.

I learned so much doing this project. I learned how to handle requests on a web server and how to port forward on a router to make the server available to the internet. Now I know how to program and esp2866, connect it to a network and make a request. I also learned how to connect a high voltage wire to a relay safely and properly. I am very happy with the outcome of this project and I wonder what else I can control using my Google assistant.