Have you ever wondered why you should buy new devices just because the old ones don’t support IoT? Any device controlled by an infrared remote can be transferred into an IoT device with a Adafruit ESP8266, an infrared receiver and LED, and your remote control. With the help of an IR code library, I was able to make a program that does just that.
Triggered with the phrase “Hey Google”, the Google Assistant is able to feed the words following the trigger phrase into its database of applets, one of which is IFTTT. Once one of the applets recognizes the phrase, it responds with a statement showing that it has acknowledged the command. In this case the answer phrase is set by the user. The Google Assistant will respond by saying the term set in IFTTT. I set it to “IR Code Sent.” The conversation will be something like the one shown in the conversation above.
Problem analysis
Our goal is to teach the Google Assistant to control a device with an IR signal. In this case we use a Panasonic SC-HC20 CD player.
We need a device, controlled by Google Assistant that can mimic an infrared remote control. In this project we will try to build that device and hook it up to Google Assistant using IFTTT (If This Then That). We build this so people do not have to buy new devices just so they can be controlled by “smart” devices.
Design considerations
We will give an overview of what we found and explain some of the trade-offs that we made.
Teaching Google Assistant skills
Adding Skills to the Google Assistant can be challenging, but IFTTT simplifies the process by setting up the api.ai (Google’s Voice Recognition Platform) part of the equation. This was normally the tricky part of teaching the Google Assistant, and IFTTT makes this much simpler. Now all we need to do is configure IFTTT and code the transmitting device.
- If This Then That (IFTTT) adds custom voice commands to Google Assistant and can sent information to a device using HTTP
- Actions on Google adds a dialog to Google Assistant and supports sending and reading information to/from devices.
Infrared Interface platform
We need to make a device that can accept commands over WiFi and relay them as infrared commands to the CD player.
- Requirements: small, low power, WiFi, GPIO (general purpose i/o pins)
- Contestants: Arduino, ESP8266, Arduino 101, ESP32
- Winner: Adafruit Feather Huzzah ESP8266. 1 MByte flash enough for over the air updates. Micro USB for code upload / debugging.Y
Infrared Interface infrared codes
Our device needs to be able to mimic the remote as to control the CD player.
- Requirements: must support the platform; it ideally should recognize the device codes so we don’t have to use raw IR timings.
- Contestants: A fork from Chris Young’s IRlib;
- Winner:A fork from Chris Young’s IRlib;
Traversing the WiFi router
The access router in our home is a jack-of-all-trades. Among its many duties it protects the home network from outside intruders. This comes with a catch: Google Assistant needs access to our home network to control the CD player. This means we need to provide a mechanism in which Google Assistant can contact the CD device.
Like with anything else on the internet, there are many choices to consider. The two trains of thought are:
- Make an exception in the firewall to accept and forward incoming commands to the IR interface. We can also use this router to handle the more resource intense encryption and scrutinize the commands to prevent code injection. Problem is that anything on the internet can access our webserver, so we need an authentication mechanism. There are two protocols that come to mind: HTTP and MQTT. HTTP is the protocol that brings the web pages that you visit to you. We can use it to push messages from Google Assistant to our IR interface. The other protocol, MQTT, is designed to provide low latency, assured messaging over fragile networks and efficient distribution to one or many receivers. It is less known but powers Facebook, and is supported by AWS IoT.
- Maintain a connection to a web service, so that it can send messages to the IR interface over that existing connection. When using the HTTP protocol, we need a kludges like long polling or websocket. A more elegant solution is Firebase Cloud messaging, but that requires a substantial amount of memory to handle HTTPS and identifiers. It appears to run on ESP8266. The memory is used for HTTPS, UID and authToken. Problem is that it causes a lot of idle traffic and requires an intermediate server (because IFTTT doesn’t support it directly).
IoT devices are characterized by a small processor, little memory and low power usage. In this respect MQTT would be ideal. However, this requires a bridge such as Ponte or web service to translate between HTTP and MQTT. Instead, we decided to go with the more common HTTPS protocol.
Design, development and unit testing
The design consists of various blocks as illustrated below. We will describe the design, development and the unit testing for these blocks. We will start the Infrared Interface and work our way up to integrating it with the Google Assistant ecosystem.
All code is available through the repository:
Infrared Interface
We go straight to the exciting part: the infrared interface.
Design
The hardware for this project is straightforward. The microcontroller is an ESP8266-based Feather HUZZAH that already has an USB interface for programming and debugging.
The software uses a framework that provides: online WiFi SSID/passwd configuration, saves fatal exception details to non-volatile memory and supports over-the-air (OTA) software updates.
Development
The ESP8266 is connected to an Infrared Receiver to decoding signals from the original remote control of the CD player. To send infrared codes to the CD player it uses a transistor to drive an IR LED.
Hardware
Build the circuit as shown in the schematic above.
-
Gather the parts shown in the table below. Be careful to use the PN2222A or 2N222A transistor (not the P2N2222A).Label Part# Description Information We paid IR1 Vishay TSOP38238 Infrared Receiver 38kHz datasheet $ 1.08 D1 Everlight EL-SIR333-A Infrared Diode 875nm 1.5Vdrop datasheet $ 0.39 T1 PN2222Atfr NPN Transistor datasheet $ 0.49 PCB1 Feather HUZZAH ESP8266 Microcontroller board detail $ 16.95 R1 1kΩ ¼W Resistor $ 0.02 R2 68Ω ¼W Resistor $ 0.02 Feather Proto board detail $ 4.95 -
Assemble the circuit using a breadboard or prototyping board. The illustration below shows the pinouts.Semiconductor pinouts -
Test . DisconnectT1
andD1
R1
from the ESP8266 module, and connect it to the 3.3V rail to verify that the voltage drop overR1
is approximately 3.4 V, indicating that the current through the infrared diode is 3.4V/68Ω=50mA. Reconnect the resistor to the ESP8266. Alternatively you can use camcorder to view the infrared light. -
Note that we used the 5 Volt rails (labeled
USB
to supply the Infrared LED with sufficient current.
Software
When IFTTT makes the web request via Webhooks, the host of the website, in this case an Adafruit Huzzah Feather ESP8266 receives the command, and checks the command against its list of valid commands. If the command checks out, then it is matched to the corresponding IR command. It then sends the value out to the CD player, which completes the action.
-
Prepare your Arduino IDE or Microsoft Visual Studio environment. Install the board support and libraries listed in the table below.IDE, board support and external libraries Type Component Author Version tested IDE Arduino arduino.cc and community 1.8.5 Board support ESP8266 esp8266 community 2.4.0 Library WiFiManager tzapu 0.12.0 Library ESP8266 Framework Coert Vonk 1.0.0 Library ESP8266 Fatal Coert Vonk, forked from Krzysztof 1.0.0 Library IRremoteESP8266 Sebastien Warin et al. 2.3.1 -
Training is required so that the device issues the correct infrared codes to the CD player. to capture the infrared codes from the existing remote control, we used the exampleIRrecvDumpV2
from theIRremoteESP8266
library.- Compile and upload it to the device over USB Serial, then open the Serial Monitor.
- Press the relevant buttons and note the button pressed and codes generated. E.g. for my CD player it shows the the manufacture’s address as
0x4004
(Panasonic) and the code for “play” as0x05505005
.
-
Program the device using the code from GitHub.- Copy or clone
ir-interface.c
. - Update the code with your own codes.
- Compile and upload it to the device over USB Serial. Subsequent uploads may be performed using over-the-air (OTA) updates.
- The first time the board starts up it will be in Access Point mode. Use a computer or phone to connect to WiFi network. If it doesn’t automatically connect you to the device, use a browser with any address. Use the browser to configure your networks SSID and password. These values will be saved in EEPROM so next time the device can connect directly.
- Open a serial monitor and note the IP address assigned to the device.
- Copy or clone
Unit testing
-
Test the
webserver pointing a webbrowser athttp://ir-interface.local/ir/ir
. You should see the infrared menu. -
Test a
keyword by pointing a webbrowser at e.g.http://ir-interface.local/ir?req=play
. The CD player should start playing. The image below shows the pulse train on an oscilloscopeInfrared pulse train - Test the remaining keywords
Access router
The design relies on the router as an integral part of the solution. It functions as a remote proxy and translates between HTTPS used on the internet and HTTP on the local area network.
Design
Development
Install a reverse-proxy and TLS-certificates on your WiFi router. Detailed instructions for routers with DD-WRT firmware can be found at DD-WRT Reverse Proxy and HTTPS. Alternatively, you can configure port forwarding on your WiFi router. In that case you need to use http
instead of https
.
Unit testing
Drumroll please …
- Use a webbrowser to access
https://ir.home.domain.com/ir
. It should respond with a list of valid commands. - Use a webbrowser to issue
https://ir.home.domain.com/ir?req=play
. It should respond with “Sending play”. - Continue with testing the other keywords.
If This Then That
If This Then That, commonly referred to as IFTTT, is a web service that preforms actions through multiple services when a applet is triggered, you can customize both the trigger and the action using their interface. In this project we use the Google Assistant as the trigger and Webhooks to preform the web request.
Design
Development
The tricky part is setting up IFTTT. To do this go to the IFTTT site; click on Continue with Google and create a new applet (Profile Dropdown » New Applet)
-
Start by specifying a
trigger by clicking the +this and selecting “Google Assistant” from the list of services.- Click Connect to authorize IFTTT to manage voice commands
-
Click Say a phrase with a text ingredient, and fill in the trigger fields:
- What do you want to say? =
CD $
- What’s another way to say it? =
remote $
- What do you want the Assistant to say in response? =
Sending IR Code
- Press Create Trigger
- What do you want to say? =
-
Specify the
Action by clicking the +that.- Choose action service = Select “Webhooks” and press Connect
- Choose action = Make a web request
-
Fill in the action fields
- URL =
https://ir.home.domain.com/ir?req={{TextField}}
- Method =
GET
- Content Type =
text/plain
- Press Create Action
- URL =
- Press Finish
Testing
Now for the fun part:
-
Prepare - While still on the IFTTT site at the My Applets > Google Assistant, click Check now.
- Connect to the serial port of the ESP8266 using the Serial Monitor on the Arduino IDE
-
Give it a shot - Use a Google Home (or on another Assistant enabled device), and say “Hey Google CD Play”.
- The Google Home should reply with “Sending IR Code”.
- On the Serial Monitor, you should see “Sending Play”.
- The CD player should start.
- Give yourself a pat on the back and continue with testing the other keywords.