Alexa Voice Control TV Remote ESP8266
by beautifulsmall in Circuits > Arduino
13513 Views, 46 Favorites, 0 Comments
Alexa Voice Control TV Remote ESP8266
Does someone in your house loose the remote control, do you walk into an empty room to find the TV blaring out. Batteries starting to fail and no control from the back of the room. Now you can control your TV, DVR, anything with IR control you can capture the IR signal for. I made this system to control my SKY DVR with a simple voice interface.
Required Hardware:
- Amazon Echo or Dot
- A wifi router which can port forward (my service provider did this for me)
- An Arduino NANO converted to 3V3
- ESP8266 -01 or similar
- IR transmitter module or circuit
- IR receiver module if you want to capture codes.
Required Software and services:
- Arduino IDE, I used 1.6.11
- Amazon Alexa skills account (free)
- Amazon AWS account(Free tier but requires credit card to open account) or alternative server.
Alexa Skills Setup
The Alexas skills kit takes the voice command and filters it using a list of 'values'
Once registered:
In Amazon Developer console, select Alexa tab> Alexa Skills Kit [Get Started]
[Add a new Skill]
Skill type:Custom Interaction Model
Language: select the correct one, when had this set to English (US) it wouldn't respond !
Name: this isn't important now as we are not publishing.
Invocation Name: , pick a short name , its the word used to open the app.
[NEXT]
Intent Schema, paste in code
Custom Slot Types {Add Slot Type], enter EFFECT_ON_TV
in Slot values , paste in code
Sample utterances , put, TVCommandIntent tv {TVAction}
[SAVE] , on the next skills page we have to add a link to the code we are going to run when the "Intent" is triggered by either the app start word "clicker" or after that by "tv {slot value}".
We will come back to Alexa after we setup the Lambda server python script.
AWS Lambda Server Python Script
Sign up for the Free Tier of AWS, I had concerns this may cost me real money but after using it a while and reading forums the usage limits are so high for personal and development use it should never reach a charge point. There is an alternative to use your own HTTPS server and maybe this is something the esp8266 could do, another instructable !
This is the code that runs when the Invocation Name is uttered (eg "Alexa open clicker") and receives the magic word from Alexa. Once the app is started you only need to say "tv play, tv jump five " and Alexa will send "play" , "jump 5" to this python script. The app times out if it has no responses after a while.
In AWS Services, first select your location, in the top right there is an option .
for US select N Virginia, for EU select Ireland.
select Lambda from Compute heading.
[Create a Lambda Function]
[Blank Function]
Configure trigger : click on the dotted box and select Alexa Skills Kit
[NEXT]
Configure Function
Name whatever you want
Description, up to you
Runtine : Python 2.7
paste in python code,
in the code the URL HTTP address will need to be changed to your own external ip address later.
link="http://185.255.255.255:777/text?data=" + favorite_color
lower on screen is a ROLE, click on the tab and select Select a custom Role
This will open a new screen and click allow., it returns to the Configure function screen with Lamda basic execution selected as Existing role.
[NEXT] the review, hit [Create Function] and it should compile and give you an ARN number. COPY this code and we will put it into the alexa skills kit .
Downloads
Set the Alexa Skills Kit Link to AWS Lambda
In Alexa skills kit, select the Configuration page , headed Global Fields and select AWS Lambda and your region and paste the ARN code into the box, [NEXT], in test, check ENABLED is selected.
WE are done here for now , now for some hardware.
Arduino NANO 3V3 Conversion
The ESP8266 runs from 3v3 so either you run it from an external regulator or convert a nano. I have used a clone nano with a CH340 usb chip. I have two different pcb layouts i know of, but hopefully this will cover most layouts.
We need to replace the 5V regulator with a pin compatible 3v3 one , 1117-3. then route the 5V in from the usb socket only to the regulator and connect everything else to its output. luckily this can be achieved by removing the input diode replacing the regulator and adding one wire from the input side of the diode to the Vin on the nano board.
check you can program the nano after the conversion.
NANO Code
This used codes for my SKY UK remote , it might be model specific and it is worth checking your codes work in a separate sketch not linked to the esp8266.
I used the IRremote library by shirriff Version 2.0.1
Use IRrecord example to capture remote commands which requires an IR receiver module or you might find your codes on the web? I'm not going into that here but this is where you can choose what you control and how.
Connect up an IR transmitter available on ebay or build one . You should use an 850nm IR led as these are the most common in receivers. The IR library used D3 as its TX pin
The alexa word gets passed to the nano, so from here its nano with voice control.
ESP8266
There are many ESP8266 modules, I used one I had to wire under a microscope, The ESP8266-01 has a 2x4 header and all the pins you need and its cheap. Loads of examples on the web, . My trip ups, GPIO_0 needs to be connected to gnd during power up (can then be floated) when programming, its a config pin , pulled high internally. Once programmed let GPIO_0 float and re-power. CHPD connect to V+ permanently.
The board manager in arduino 1.6.11 doesnt have the esp8622 link,
in Arduino IDE
file>preferences>additional Board Manager URL’s , add :
http://arduino.esp8266.com/stable/package_esp8266c...
then goto board manager and find the esp8266 package. this should now give you a big list of esp8266 boards, select Tools>Board>ESP8266 Generic Module. Using a usb to uart module you can now program the esp part with esp8266_server_text. Power with 3V3, connect TX-RX, RX-TX and Gnd.
You need to enter your network SSID and password into the script and the port you will set for port forwarding,eg 777.
You can run the code by re-powering the esp whilst connected to the usb to uart converter and the arduino serial window (9600 baud) should display the local ip address of the esp module. enter this into the code and re-program.
Downloads
Network Setup
So to allow the Lambda URL call to connect to the ESP HTTP server we need to set your router to port forwarding. I got my external ip address from http://www.whatsmyip.org/ , I am on a microwave link so my provider has the router and I had to request port forwarding from them. I had to give the IP address of the ESP8266 on my network and the port I chose , eg 777. The external IP address needs to be entered into the lambda python script and your local esp address will be shown when you run the esp8266 code through the usb to uart link.
The ESP module on the usb to uart connection should show on a terminal the incoming word from lambda.
Connect the ESP to the nano as shown 3v3, gnd and TX to nano D2 soft serial. if you have the nano on usb to a serial comms display on th epc it should show what it receives from the esp.
If the ESP isn't connected to the network or doesnt respond to the URL call from lambda , lambda will timeout and Alexa reports a failed skill response.
Alexa Open Clicker Tv Pause
I put the module next to the receiver but with higher power IR output it could be anywhere in a room. I use a known brand usb power adapter to feed power through the usb.
Sit back and say "Alexa open Clicker"
tv guide
tv go down
tv select
tv play
tv jump five
to jump forward a set number of minutes the macros will go to 30x wait for a requested time and then play.
UK adverts are about five minutes.
To exit the app say Alexa quit.
Enjoy.