Tutorial Control Home Assistant by voice thanks to Alexa

Home Assistant offers many possibilities to control your connected home. One of the most practical advantages is its compatibility with voice assistants like Amazon Alexa, Google Assistant, Siri and Snips.

This local server is more than complete, so pair it with the charming voice ofAlexa allows us to go further. Indeed, our server freshly installed home assistant will allow us to make our routines more complex and we will also be able to control devices natively incompatible with the voice. Alexa.

Prerequisites for using Home Assistant with Alexa

This installation is totally free but takes a little longer than usual integration.

There is also Nabu House which allows you to control your instance from the outside as well as connect your server to the various voice assistants. Obviously all of this is very secure, however this service is offered at 5 € / month.

Do you want to choose the free solution? Perfect ! Let's see this in more detail.

Requirements for your setup

Create a skill Amazon Alexa Smart Home

Once your account developer Amazon created, connect to the consul Alexa developer then go to the tab " skills " if you are not, click on the button « Create Skill ".

alexa console create skill

Give it a name, for example "Lesalexiens"then select « Smart Home » et "Provision your own".

alexa smart home skill

alexa smart home hassio skill

You can now create your skill by clicking on the button "Create Skill" at the top right of the screen.

alexa developer console smart home assistant

Make sure "v3 (preferred)" is selected.

You can leave this page open in a corner of your browser, we have to come back to it later.

Create an AWS Lambda Function

Your skill Alexa Smart Home will trigger a function AWS Lambda who will process the request. We're going to copy / paste (yeah..we are not developers!) A little piece of code hosted as a Lambda function that will redirect the request to our Home Assistant server, then the integration ofAlexa in Home Assistant will process the request and provide a response. It is therefore our Lambda function that will provide the response to Alexa.

Didn't you understand anything? It does not matter, we will copy paste a few lines of code and Alexa will work 🙂

Download and prepare our skill Alexa Adapter

Start by download the latest version of the project, it will be our AWS Lambda function.

The file is at the bottom of the page, choose the file in ".zip" format:

haska alexa hasio

Once the file is downloaded, go to file editor, we will add some lines to the file configuration.yaml :

api alexa smart home



Save the file then restart your server

Creating a Home Assistant long-term token

You will now need to obtain a long-lasting token, you can create one from your Home Assistant interface very easily:

  1. Log in to your Home Assistant interface
  2. Click on your profile (the blue circle at the bottom left of the page)
  3. Scroll to block Long-term access tokens
  4. Click on create a token
  5. A window will open, give it a name (For example: lesalexiens)
  6. Once a name is added, a token will appear. Paste it in the help file, we'll use this token later.

Connection configuration with Amazon

Connect to your consul Amazon developer then click on the link Login with Amazon :

connection with amazon link to page

Click on create a security profile :

create a security profile amazon

Then you just have to create the profile as below:

  1. Enter your profile name desired security, for example "lesalexiens"
  2. Write a brief description, for example "Profile for the use of my home assistant server"
  3. Add the URL you want for the privacy notice, for example "https://lesalexiens-tutoriel.duckdns.org"

Click on Save then on your new profile, click on the small gear and choose Web settings.

Note theCustomer ID and client secret code in the help file made available to you.

profile ID and client secret code

Keep this window open, we'll get to that later.

Kit configuration Alexa cv

From a new window, open the developer console.

Alexa skill kit

From Alexa Skills Kit, select your skill and get your Skill ID (Paste it in your help file)

alexa skill ID

Currently you should have 4 values ​​in your help table

Preparing for AWS Lambda Access

Connect to your AWS console by selecting the profile IAM User

AWS console connection

After logging into your AWS console, the tab Services appears at the top left of the page. Click on it then search I AM

AWS IAM service

Once the page I AM open, click Rôles then then on Create a role

aws IAM role

You should see this page appear:

  1. Select AWS Services
  2. Click on Lambda
  3. Validate by clicking on the button Next: Permissions

You should see this new page appear:

Look up the word basic you should see a single line appear with the name AWSLambdaBasicExecutionRole. Check this line then click on the button Next: Tags

On this page do not enter any tags and click directly on the button Next: Verification

Here we are on the last step of creating our role. You just need to give it the name lambda_basic_execution then validate by clicking on the button create a role as below:

Your role is created, return to the main page by clicking on the AWS logo at the top left of your page

Region configuration

This step is very important to continue the tutorial

At the top right of the screen there is your username (certainly your email address) and next to it you will find a menu listing different regions, select the region Europe (Ireland) eu-west-1 and only this region.

If you live in the United States or Canada select the region US East (N. Virginia) us-east-1

Configuring the AWS Lambda Service

Search calculation from the search bar in the AWS Services block. The list will show different services, select the Lambda service.

lambda service calculation

Once the Lambda page appears click on the orange button Create a function. create a lambda function

Make sure the sticker Author from scratch is selected then set the following options :

lambda function parameters

  • Function name : lesalexiens
  • Runtime environment : Python 3.6
  • Execution role : Use an existing role
  • Existing role : lambda_basic_execution

The function is ready you can create it by clicking on the button Create a function.

Trigger configuration Alexa Smart Home

Once your function has been created, you should see a block appear with the name Designers. There you will find a button Add a trigger,  click on it then select Alexa Smart Home.

alexa smart home skill id

Once Alexa Smart Home selected, paste your Skill ID (You will find it very easily thanks to your help file)

Be sure that Activate trigger is checked then click on the button Add.

alexa smart home lambda

Once Alexa Smart Home added, click on the name of your function (Our function is named the alexians). Further down the page you will find the section Function code :

aws lambda function code

Select Upload a .zip file in Code entry typeFrom the download button select the .zip file on your computer that we downloaded earlier.

Once the file has downloaded, replace what is in the box Manager by haaska.event_handler


Click on Save at the top right of the window and wait a few seconds that the file is loaded.

Configuring your function

In the section Function codeyou will find a list of files. Double click on the file config.json:

aws token hassio

And add the following two attributes:

  • url : The URL of your Home Assistant server (for example here, https://lesalexiens-tutoriel.duckdns.org:8123/api)
  • bearer_token : The long-term access token (which you will easily find in your help file)

Don't forget to put / api at the end of your url.

You can now record from the button at the top right.

Link AWS with the kit Alexa

Once the file is saved, return to the top of the page. You will find a RNA, paste it into your help file.

Lambda aws RNA

From the developer console Alexa,  select your skill and insert your RNA in the zone default endpoint :

default endpoint aws hassio

Example of RNA to paste in Default endpoint :

arn: aws: lambda: eu-west-1: 1234567891011: function: lesalexiens

You can select the region Europe, India and also paste your RNA :


Save by clicking on the button SAVE 

Login Alexa Smart Home à Amazon

Down the developer console Alexa you will find a button Setup account linking

Click on the button then enter the following information:

  • Authorization URI : https: // www.amazon.com / ap / oa
  • Access Token URI : https: // api.amazon.com / auth / o2 / token
  • Your Customer ID : Your Client ID (You will find it in the help file)
  • Your Secret : Your Client Secret (You will find it in the help file)
  • Your Authentication Scheme : HTTP Basic (Recommended)
  • Scope : Create a scope by clicking on Add Scope and add profile

A list of redirect URIs will be available in the section Alexa Redirect URLs, paste them in your help file.

Save your changes by clicking on the save button at the top right of the page.

To finalize the configuration, go to console Amazon then click Login with Amazon

Your skill will appear, you will then have to hover your mouse over the gear and click on web settings.

Click on Edit at the bottom right of your page:

Paste the three URIs in the section Allowed return urls as below:

All you have to do is save your changes.

At this stage our configuration is complete, we will test our function and then finish our installation in Home Assistant as well as in the application Alexa.

Test our Lambda function

At the top of your Lambda function configuration page, there is the button Tests, click on it.

Create a new test event

You can Configure a new test event using the following data:

aws lambda function test

Give your event a name (for example, my event).

{"directive": {"header": {"namespace": "Alexa.Discovery "," name ":" Discover "," payloadVersion ":" 3 "," messageId ":" 1bd5d003-31b9-476f-ad03-71d471922820 "}," payload ": {" scope ": {" type " : "BearerToken", "token": "YOUR_LONG_DURITY_ACCES_CASE"}}}}

You just need to create your test by clicking on Create at the end of the page. Once your test is created, select it from the drop-down menu to the left of the test button.

Click on the button Tests, and if the test is successful, a green message will appear.

Congratulation! Your function can communicate with your Home Assistant installation. : )

Final configuration in Home Assistant

From file editor, go to your file configuration.yaml in order to finalize our integration ofAlexa.

Previously we had the following three lines for Alexa :



You must modify them in order to have the following configuration:


  smart_home: locale: fr-FR endpoint: https://api.eu.amazonalexa.com / v3 / events client_id: YOUR_CLIENT_ID client_secret: YOUR_SECRET_CLIENT

your client_id et client_secret are available in your help file. Save and restart your Home Assistant server.

Add our skill in the application Alexa

Last step! See you in your application Amazon Alexa

You just have to go to Skill and games then select the tab Your Skills

Your Skill will appear (for example, the alexiens), you just have to click on it and identify yourself with your account Amazon. : )

Alexa is operational with your Home Assistant server. You can communicate with all your devices, no more need to worry about compatibility.

In the next tutorial we will see how to add our Echo devices to Home Assistant in order to control the media player and use the voice system to alert or inform us. 🙂

Several feathers of enthusiastsAlexa to concoct articles with 4 or more hands ... Collaborative writing to address the most specialized or transversal subjects, the best home automation and connected home plans on the web, and much more ...