How-To Geek

How to Control Your Kodi Media Center with an Amazon Echo

alexa-kodi

Remote controls are so 1950. If you have a Kodi media center and an Amazon Echo, you can play all your favorite movies and shows with a well-placed voice command…if you’re willing to do a little setup.

The Amazon Echo is, in our opinion, one of the coolest parts of a smart home. Controlling your lights, blinds, and TV with your phone is cool, but controlling them with your voice is truly the future. I was skeptical, but quickly became impressed—and hungry for more.

Being able to turn my TV on is cool, but what I really wanted was to be able to control my media center. I wanted to be able to say “Play the next episode of Friends” and have it search my library, see what I watched last, and start playing the subsequent episode. And after a bit of searching, I found that one enterprising programmer named Joe Ipson had already done just that.

This takes a little bit of setup, and it looks very intimidating at first. You’ll need to create a web server, push some code from GitHub, and do a little work from the command line, but you don’t need to be a programmer to get this up and running. Ipson has done almost all the heavy lifting, and you just need to copy his code, edit a few parts, and upload it to the right place. If you follow this guide to the letter, you should be up and running in no time.

NOTE: A previous version of this guide used Heroku for the web server portion of the tutorial, which—while it worked—had a few quirks, notably telling you the command failed even when it didn’t. We’ve updated this tutorial to use Amazon Web Services instead, which should be much smoother. If you want to use Heroku (say, if you’re using a paid plan that won’t have those quirks), you can see instructions in Ipson’s documentation.

Step One: Prepare Your Kodi Web Server

In order for this to work, Kodi will need to have a server accessible from the web. Thankfully, this is built into Kodi, though you may need to forward some ports on your router and perform some other tasks before it works smoothly.

Open Kodi on your media center and head to System > Services > Web Server. Enable the web server if it isn’t enabled already, and give it a username and password. Be sure to use a password you don’t use for any other service.

screenshot.2

You will also need the public IP address for your home. However, since this can change, we highly recommend signing up for a dynamic domain name using a service like Dynu. Follow our guide here before continuing if you don’t already have one.

dynamicdns

Lastly, you’ll need to set up port forwarding for your Kodi box. This will differ from router to router, but you can check out our guide here for more information. Just forward any external port to the local IP address of your Kodi box (in my case, 192.168.1.12) and local port (8080 by default).

NOTE: while Kodi’s local port is 8080 by default, you can change it to whatever you want—or you can forward it to a different external port to make sure there are no complications (since other apps may ask for port 8080). I’m using 8080 in this tutorial, but if you use something different, just replace all instances of port 8080 with the external port you choose here.

screenshot.3

If all goes well, you should be able to access Kodi’s web interface by opening a web browser and typing in:

my.dynamic-domain.com:8080

where my.dynamic-domain.com is the URL of your dynamic domain, and 8080 is the port you set in Kodi. If that doesn’t work, make sure that Kodi, your dynamic domain, and your port forwarding were all set up properly.

Step Two: Set Up Your Amazon Web Services Account

Next, you’ll need to set up an account with Amazon Web Services (AWS). Head to this page and click “Create an AWS Account”. Log in with your Amazon credentials when prompted. If you don’t have an AWS account already, you’ll be asked to enter your contact info to create one. Be sure to check “Personal Account” along the top.

aws1

Go through the rest of the steps in the wizard. You will also have to enter your credit card info, but don’t worry—you won’t be charged unless you go over 1,000,000 requests in a month—which, unless you watch way too much TV, will not happen. So even though Amazon needs your credit card info, you shouldn’t be charged for AWS.

After verifying your identity with your phone number, and selecting your support plan (we recommend Basic, which is free), click the “Complete Sign Up” button in the right corner of the screen. Amazon will then log you in.

aws2

Step Three: Install Python 2.7 and Set Up Your Variables

In order to push Ipson’s code to AWS, you’ll need Python 2.7 installed on your computer. We’ll be using Windows in this tutorial, but you should be able to do this on macOS and Linux as well.

To install Python on Windows, head to Python’s download page and download Python 2.7. Run the installer like you would any other Windows program. Use the default selections, as we’ll need some of the tools that come with Python’s installer.

pythondownload

Then, click here to download Ipson’s code. Unzip the kodi-alexa-master folder within the ZIP file somewhere on your hard drive.

In order for Ipson’s code to work with your Kodi and AWS setup, you’ll need to define a few variables in the code. Head to your kodi-alexa-master folder and edit the .env file with an app like Notepad++. You’ll need to edit seven variables in this file. Let’s start with the first four:

KODI_ADDRESS = 
KODI_PORT = 
KODI_USERNAME = 
KODI_PASSWORD =

KODI_ADDRESS will be the dynamic address you set up in step one (e.g. my.dynamic-domain.com ). KODI_PORT will be the port you used in step one (likely 8080, unless you changed it). Lastly, enter your Kodi username and password from step one here as well.

You’ll also need to edit three variables at the bottom of the document:

AWS_ACCESS_KEY_ID =
AWS_SECRET_ACCESS_KEY =
LAMBDA_ROLE =

You’ll grab these from the AWS console. Head to the Identity and Access Management page (log back into AWS if necessary) and click the “Users” tab on the left-hand side. Click the “Create New User” button.

aws3

Create a new user with whatever username you want.

aws4

Once you click “Create User”, you’ll be given a chance to access that user’s security credentials. Click “Show User Security Credentials” and copy both access keys. Paste them into the .env file under AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, respectively. Click Close on the AWS window when you’re done.

aws5

Next, click the “Users” tab on the left side and select your user. Click the “Permissions” tab and click the “Attach Policy” button.

awsuserattach

On the Attach Policy screen that appears, scroll down to “AWSLambdaFullAccess” and check it. Click the Attach Policy button. Your user now has permission to use Lambda.

awsuserlambda

Now, click on the “Roles” tab on the left side and click “Create New Role”. We’re going to create a role used for running Lambda functions. Again, you can name it whatever you want. Click Next Step.

aws6

On the Select Role Type step, click the Select button next to “AWS Lambda”.

aws7

On the Attach Policy screen that appears, scroll down to “AWSLambdaFullAccess” and check it. Click the Next Step button.

aws8

On the Review page, copy the Role ARN value, which will look something like arn:aws:iam::11111111111:role/lambda , and copy it to the .env file under LAMBDA_ROLE.

Click the Create Role button in AWS to finish.

aws9

At this point, your .env file should look pretty well filled out, like so:

KODI_ADDRESS = my.dynamic-address.com
KODI_PORT = 8080
KODI_USERNAME = kodi
KODI_PASSWORD = mysupersecretpassword
LAMBDA_ENV_VARS = KODI_PASSWORD,KODI_USERNAME,KODI_PORT,KODI_ADDRESS
AWS_DEFAULT_REGION = us-east-1
LAMBDA_TIMEOUT = 60
LAMBDA_MEMORY_SIZE = 128
LAMBDA_HANDLER = wsgi.lambda_handler
AWS_ACCESS_KEY_ID =ABCDEFGHIJKLMNOPQRST
AWS_SECRET_ACCESS_KEY = ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN
LAMBDA_ROLE = arn:aws:iam::11111111111:role/lambda

If everything looks good, save your changes to the .env file continue to the next step.

Step Four: Push Your Code to AWS

Now it’s time to get your code up and running. Press Windows+X on your keyboard and choose “Command Prompt”. (Mac and Linux users will want to open their respective Terminal apps). CD into your kodi-alexa-master folder with the following command:

CD C:\Users\Whitson\Documents\Code\kodi-alexa-master

Obviously, replace the file path with the path to wherever you saved your kodi-alexa-master folder.

cdkodialexa

Then, run the following command:

C:\Python27\Scripts\pip.exe install lambda-deploy

This will install the lambda scrip that deploys your code to AWS. If you installed Python in a different folder from the default, you may need to alter the file path to pip.exe.

aws10

Then, run:

C:\Python27\Scripts\lambda-deploy.exe deploy

This will deploy your code. If all went well, you should see a success message here.

aws11

Lastly, head to the Lambda page on the AWS console and click the “Get Started Now” button (if you’ve never used Lambda on AWS before). You should see your function in the list. Click on it.

aws12

Head to the “Triggers” tab and click “Add Trigger”.

aws13

Click on the empty box and choose “Alexa Skills Kit”. Click Submit.

aws14

In the top right corner of the page, you’ll see an ARN (in the form of arn:aws:lambda:us-east-1:111111111111:function:kodi-alexa-master . Copy that and save it in a safe place—you’ll need it in the next step.

Now that your code is set up on AWS, you just need to point your Echo to it.

Step Five: Create Your Amazon “App”

To connect Ipson’s code with our Echo, we’ll need to create an “app”, or Skill, for Alexa. This app won’t be distributed to anyone, it’ll just be in “testing mode” forever, connected to your own Amazon account for use with your Echo.

To start, set up a free Amazon Developer account. Head to this page, log in with your Amazon account, and register for a developer account. Fill in the required fields, agree to the terms, and say “No” when you’re asked if you’re going to monetize your apps.

screenshot.26

Once logged in, head to “Alexa” in the top toolbar. Click the “Get Started” button under “Alexa Skills Kit”.

alexa-skills-1

Next, click the “Add a New Skill” button.

alexa-skills-2

Give your skill a name—I called mine “Kodi”—and give it an invocation name. This is what you’ll say when you want to invoke a command. For example, my invocation name is also “the living room”, which means I’ll have to say “Ask the living room to…” to give Alexa commands for my media center.

In my experience, long invocation names work better than shorter ones. I used “Kodi” for awhile (“Ask Kodi to…”) but Alexa occasionally had trouble finding movies. I couldn’t tell you why, but longer invocation names like “the living room” work almost flawlessly for me. So try choosing something with a few syllables.

Click Next when finished.

screenshot.29

Click “Add Slot Type” button in the middle of the next window.

screenshot.1

Create a new slot called SHOWS , and list some of your TV shows in the box, one per line—I have about 20-30 shows in mine. You don’t need to add every show in your Kodi library, but it’s good to have a decent number of examples. This will help Alexa recognize the shows you dictate to it. Click OK when finished.

screenshot.2

Repeat this process with three more Slot Types: MOVIES, MUSICARTISTS, and MUSICPLAYLISTS (If you don’t have a music library, create the slot type anyway—Ipson’s code requires it—and just stick a few random artist names in there. It won’t cause any problems.)

screenshot.30

NOTE: If you find that 20-30 random items isn’t enough for Alexa to recognize your commands, try this slot generator, also from Joe Ipson. It’ll scan your library and create a list of every movie, show, and artist on your Kodi box, to ensure Alexa gets it right every time.

When you’ve created all four Slot Types, head back to the folder you extracted from GitHub on your PC. Find the alexa.intents and alexa.utterances files. Open them both with an app like Notepad++.

screenshot.30

Select all the text in the alexa.intents file and paste it into the “Intent Schema” box on the Amazon Developer website. Repeat this process with the alexa.utterances file, placing the text in the “Sample Utterances” box.

When you’re done, click Next.

screenshot.31

On the next page, choose “AWS Lambda ARN” for the Endpoint and paste in the ARN you wrote down at the end of step four (arn:aws:lambda:us-east-1:111111111111:function:kodi-alexa-master ). Choose “No” for Account Linking and click Next.

screenshot.23-1-650x305

On the next page, select “My development endpoint is a subdomain of a domain that has a wildcard certificate from a certificate authority”. Click Next.

screenshot.24

You shouldn’t need to add any information on the Test page, though you can test certain aspects of the code if you know what you’re doing. Otherwise, click Next.

On the Publishing Information page, fill out the required fields—but don’t worry too much about what you put in, since you won’t be submitting this app for certification. You’re the only one who will be using this app. (Here is a 108×108 icon and a 512×512 icon for you to use.) Click Next when finished.

screenshot.33

On the final page, choose “No” for both privacy questions and check the Complicance box. Click the “Save” button when you’re finished. Do NOT click the “Submit for Certification” button.

alexa-final

Step Six: Test Your New Commands

If all went well, you should be able to test your new commands now. Make sure your Kodi box is turned on, and try saying something like:

“Alexa, ask the living room to play season one, episode one of Friends”

(…obviously replacing that with an episode and show that you have on your machine.) It may take Alexa a moment, but hopefully she should respond and start playing the show in question. If you get an error and the episode doesn’t play, go back and make sure you did everything properly.

You can ask Alexa if you have any new episodes, ask her to play the next episode of a show, or even use her to control Kodi, as inefficient as it may be (“Alexa, ask the living room to pause,” “Alexa, ask the living room to navigate down,” etc.). Check out the alexa.utterances file to see all the things Alexa can do with this integration. If you ever want to add a new phrase that corresponds to one of those functions, just log back onto your Amazon Developer account and add it to the list we pasted in step four.

If you have multiple Kodi boxes, you can do this for each of them—you just need to create a new app on both AWS and Amazon for each (and give each a different invocation name). For example, I have a second app controlling the Raspberry Pi in my bedroom that lets me “ask the bedroom” to play new shows.


This isn’t flawless, and it wasn’t without its growing pains when I first set it up. But once you get it working, it’s easily one of the coolest things you can do with your Amazon Echo, in my opinion. Now I can start watching TV while cooking in the kitchen, or when my remote’s batteries are dead. This is the kind of power Amazon Echo was designed to have, and even though it takes a bit of work, it’s well worth it.

Having trouble? Check out this thread on the Kodi forums, as well as the original GitHub page, or drop a line in our comments below.

Title image from doomu/Bigstock and Amazon.

Whitson Gordon is a writer, Windows geek, PC builder, metalhead, chopstick-using potato chip eater, and Midwest-to-Southern California transplant. You can follow his nerdy exploits on Twitter and Facebook.

  • Published 04/25/16

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!