Remote controls have been in operation since 1950. If you have a Kodi media center and an Amazon Echo, you can play all your favorite movies and shows with a handy voice command… if you want to customize a bit.

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

RELATED: How to install and set up your Amazon Echo

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

https://www.youtube.com/watch?v=4xrrEkimPV4%3Ffeature%3Doembed&xid=17259,1500000,15700002,15700021,15700186,15700191,15700256,15700259,15700262,15700265,15700271&usg=ALkJrhgnKpMJw0KefZWRowFMglGqWQ_h7Q

It takes a bit of tweaking and looks very intimidating at first. You will need to create a web server, commit some code from GitHub, and do a little work from the command line, but you don’t need to be a programmer to get started. Ipson has done almost all the hard work and you just need to copy its code, edit a few parts and upload it to your desired location. If you follow this guide prior to writing, you should be up and running in no time.

NOTE. We use Amazon Web Services for this guide because it is the most reliable. If you’re a new AWS user, Ipson says you’ll be able to run the skill for free for about a year, after which you’ll be charged less than 20 cents per month. If you want something really free, you can set it up with Heroku instead, replacing steps two, three, and four of this guide with Heroku’s instructions in the Ipson documentation. It is, however, slightly less reliable and some requests may time out when you use it. We recommend AWS if you want the best experience — it costs no more than 20 cents per month.

Step One: Prepare Your Kodi Web Server

For this to work, Kodi needs to have a server accessible from the internet. Luckily, this is built into Kodi, although you may need to forward some ports on your router and do some other tasks before it runs smoothly.

Open Kodi in your media center and go to System > Services > Web Server. Enable the web server if it is not already enabled and give it a username and password. Be sure to use a password that you do not use for any other services.

screenshot.2

You will also need a public IP address for your home. However, as this may change, we strongly recommend that you subscribe to a dynamic domain name using a service such as Dynu. Follow our guide before proceeding if you don’t already have one.

DynamicDNS

Lastly, you 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 your Kodi box’s local IP address (192.168.1.12 in my case) and local port (8080 by default).

NOTE: Although Kodi’s local port is 8080 by default, you can change it to whatever you want or forward it to a different external port to make sure there are no complications (because other applications may be requesting port 8080). I’m using 8080 in this tutorial, but if you’re using something else just replace all instances of port 8080 with external the port you have selected here.

screenshot.3

If everything goes well, you should be able to access the Kodi web interface by opening your web browser and typing:

  my.dynamic-domain.com:8080 

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

RELATED: How to Easily Access Your Home Network from Anywhere in the World Using Dynamic DNS

Step Two: Set Up an Amazon Web Services Account

Next, you need to set up an account with Amazon Web Services (AWS). Go to this page and click «Create an AWS Account». Sign in with your Amazon credentials when prompted. If you don’t already have an AWS account, you will be prompted to enter your contact information to create one. Don’t forget to check «My Account» at the top.

aws1

Go through the rest of the wizard steps. You’ll also need to enter your credit card details, but don’t worry — as we said, you don’t have to pay too much, if at all (especially for the first 12 months).

After verifying your identity with your phone number and choosing a support plan (we recommend Basic, which is free), click the «Complete Registration» button in the right corner of the screen. Amazon will then log in.

aWS2

Now go to the Identity & Access Management page (log in to AWS if necessary) and click on the Users tab on the left side. Click the Add User button.

Create a new user with any username. Check the «Programmatic access» box and click «Next: Permissions».

Next, you will be prompted to set permissions. Click «Attach Existing Policies Directly», then search for «AdministratorAccess». Check the AdministratorAccess option and click Next: Browse.

Make sure your user looks like the image below, then click «Create User».

Don’t close the next page! You need to get the access key id and secret access key here (you need to click «Show» to show your secret key). Copy them to a text file for safe keeping, because you won’t be able to get the private key again after you leave this page.

After you have recorded them, you can safely close this window.

Step Three: Install Python 2.7 and Set Up Your Variables

To port Ipson code to AWS, you will need Python 2.7 installed on your machine. We’ll be using Windows in this guide, but you should be able to do it on both MacOS and Linux.

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

pythondownload

Then click here to download the Ipson code. Unzip the kodi-alexa-master folder inside the ZIP file on your hard drive.

Once installed, it’s time to dig into the command line. Press Windows + X on your keyboard and select Command Prompt. (Mac and Linux users will want to open their respective terminal applications). From there, run the following two commands, one after the other:

  C: \ Python27 \ Scripts \ pip.exe установить awscli 
  C: \ Python27 \ Scripts \ aws configure 

This will install the AWS Command Line Tools and launch the configuration tool.

When prompted, paste your passkey ID and secret passkey. When asked for a default region name, type us-east-1 (if you are in the US) or eu-west-1 (if you are in Europe). You can leave your Default Output Format blank (just press Enter).

Next, run the following command:

  C: \ Python27 \ Scripts \ pip.exe установить virtualenv 

You will need this for later.

Now 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 one where you saved the kodi-alexa-master folder.

Keep the window open for now, we need to get back to it in a minute.

First, in order for the Ipson code to work with your Kodi and AWS settings, you need to define a few variables in the config file. Download this template, rename it to kodi.config and save in your kodi-alexa-master folder. Open it in a code-friendly text editor like Notepad++ and edit the following four variables:

  адрес = 
 порт = 
 имя пользователя = 
 пароль = 

Variable address will be the dynamic address you set to my.dynamic-domain.com step (eg. my.dynamic-domain.com ), port will be the port you used on my.dynamic-domain.com step (probably 8080 if you didn’t change it) and username and password will be powers from the first step.

If you have multiple Kodi boxes in your home, you can also use this config file to manage them individually with Alexa. We won’t be going through this in this guide, but you can find instructions in the Ipson documentation here.

When you’re done, save the file and return to the command prompt window.

Step Four: Insert Your Code into AWS

With these variables, your code is ready to be deployed. Back at the command line, run these two commands:

  C: \ Python27 \ Scripts \ virtualenv venv 
  venv \ Scripts \ activate.bat 

This will create a new «virtual environment» and activate it.

At the venv prompt that appears, run the following commands:

  pip install -r needs.txt 
  упаковка 
  pip install zappa 

This will install a tool called Zappa that will help you deploy your code.

Next, you need to set up Zappa. Run:

  Заппа init 

This will guide you through the wizard. Just accept the defaults for everything.

Finally, run:

  Заппа развернуть Dev 

This will deploy your code to Lambda. This will take a few minutes, so let it work. At the end it will give you the URL — copy it as you will need it in the next step.

Finally, I also recommend running the following command as you will need the resulting files in the next step:

  python generate_custom_slots.py 

Make sure your Kodi box is up and running when you run this script as it will collect the titles of movies, shows and other media from your library.

You’re almost there! Now we just need to set up the Alexa skill for this code.

Step Five: Build Your Alexa Skill

In order to link the Ipson code to our Echo, we need to create an Alexa Skill that uses this code. This application will not be distributed to anyone, it will be permanently in «test mode» and connected to your Amazon account for use with your Echo.

To get started, create a free Amazon Developer account. Go to this page, sign in with your Amazon account, and sign up for a developer account. Fill in the required fields, agree to the terms and say «No» when asked if you are going to monetize your apps.

screenshot.26

Once on the site, navigate to «Alexa» on the top toolbar. Click the «Get Started» button in the «Alexa Skillset» section.

alexa-skills-1

Next, click the «Add New Skill» button.

alexa-skills-2

Give your skill a name — I named mine «Cody» — and give it a callable name. This is what you will say when you want to call the command. For example, my call name is also «living room», which means I would have to say «Ask for living room…» to give Alexa commands to my media center.

In my experience, long calls work better than short ones. I used «Kodi» («Ask for Kodi…») for a while, but Alexa sometimes had trouble finding movies. I can’t tell why, but longer names like «living room» work almost flawlessly for me. So try to choose something with a few syllables.

Click Next when you’re done.

screenshot.29

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

screenshot.1

Create a new slot called SHOWS . Go back to the kodi-alexa-master folder, open the SHOWS file with Notepad++ and copy the show into the box on the Amazon page. This will help Alexa recognize the shows you’ve dictated to him.

Alternatively, you can simply list some of your TV shows in the box, one per line. You don’t have to add every show to your Kodi library, but it’s good to have a decent amount of examples (I’ve found 20 or 30 to be pretty good).

Click OK when done.

screenshot.2

Repeat this process with these slot types: MOVIES, MOVIEGENRES, MUSICARTISTS, MUSICALBUMS, MUSICSONGS, MUSICPLAYLISTS, VIDEOPLAYLISTS, and ADDONS (if you don’t have information for any of these, create a slot type anyway — the Ipson code requires it — and just write the word «Blank» in the field.It won’t cause any problems.)

Again, you don’t need every single show, movie, or artist in these slots, so you don’t have to update them every time you add a new movie to your library. It just helps to have a decent number of examples in each.

When you have created all nine types of slots, go back to the kodi-alexa-master folder. Open folder IntentSchema.json and SampleUtterances.txt files IntentSchema.json and SampleUtterances.txt using an application such as Notepad++.

Select all text in a file IntentSchema.json and paste it into the Intent Scheme field on the Amazon Developer website. Repeat this process with the file SampleUtterances.txt by placing text in the Speech Samples field.

When you’re done, click the Next button. Building an interaction model can take several minutes.

screenshot.31

On the next page, select «HTTPS» as the endpoint type and paste the URL obtained at the end of the fourth step. Select your geographic region (North America or Europe) and select «None» to link your account. Press «Next.

On the next page, select «My development endpoint is a subdomain of a domain that has a wildcard certificate from a CA.» Press «Next.

screenshot.24

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

On the Submit Information page, complete the required fields, but don’t worry about what you entered as you won’t be submitting this app for certification. You are the only one who will use this application. ( Here you can use 108×108 icon and 512×512 icon. ) When finished, click next button.

screenshot.33

On the last page, select «No» for both privacy questions and check Complicance. Click the «Save» button when you’re done. DO NOT click the Submit for Certification button.

alexa-ultimate

Step Six: Test New Commands

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

«Alexa, ask the living room to play the first season, the first episode of Friends»

(…Obviously replacing it with an episode and showing what you have on your machine.) This might take Alexa a while, but hopefully she should respond and start running this show. If you get an error and the episode won’t play, go back and make sure you did everything right.

You can ask Alexa if you have any new episodes, ask her to play the next episode of the show, or even use her to control Cody, no matter how ineffective («Alexa, ask the living room to pause», «Alexa» ask walk down the living room, «etc.). Check file SampleUtterances.txt to see everything Alexa can do with this integration. If you’d like to add a new phrase that matches one of these features, simply sign in to your Amazon Developer account and add it to the list we inserted in step four.


It’s not the fastest or easiest thing to set up, but once it’s up and running, it’s one of the coolest things you can do with Amazon Echo in my opinion. Now I can start watching TV while cooking in the kitchen or when the batteries in my remote are dead. This is the power the Amazon Echo has designed, and while it takes a little work, it’s well worth it.

Any problems? Check out this thread on the Kodi forums, as well as the original GitHub page, or leave a line in our comments below.

Image title from Doomu/Bigstock and Amazon.

Похожие записи