Amazon Alexa
Amazon Alexa is compatible with Home Assistant, allowing it to be used as a voice interface for controlling and automating your home.
Integrating Alexa with HA provides the ability to easily control devices and scenes via voice commands without the need for manual interaction, increasing the comfort and efficiency of managing a smart home.
Alexa does not yet support the Czech language, so you need to communicate with it in English, German, French, or Spanish.
I tested the entire integration process with the Amazon Echo Dot product.
Amazon Echo Dot (5th Gen)
- Sound: 1.7" speaker
- Wireless connectivity: WiFi 2.4 GHz and 5 GHz, Bluetooth Low Energy Mesh, and Matter
- Voice assistant: Amazon Alexa
- Dimensions: 100×100×89 mm
- Weight: 304 g
Amazon Alexa App
Not only for integration into HA but also for usage, you will need to install the Amazon Alexa app on your mobile phone.
Integrating Amazon Alexa into HA
- Home Assistant Cloud - The easiest way to integrate, but it requires a monthly subscription fee.
- Manual configuration - A more technically demanding method without monthly fees, which can provide greater flexibility and control.
Home Assistant Cloud
To successfully activate Alexa, you first need to have Home Assistant Cloud activated in Home Assistant.
-
Open the Settings menu and select Voice Assistants.
-
Activate the Alexa option.
-
Go to the Expose tab and select all the entities you want to link with Alexa.
-
Download the Alexa app on your mobile phone and activate the Home Assistant Smart Home skill. The procedure can be found in the following images:
Manual Configuration
The process for manually configuring Alexa integration is quite complex. If you are not confident, I recommend always choosing the method above, which requires a paid Home Assistant Cloud.
Requirements
-
Remote access to Home Assistant: Set up access on port 443 with a valid certificate. Details can be found in the Remote Access section.
-
Amazon Developer Account: To create one, visit the Amazon Developer Portal.
-
AWS Cloud Account: To use AWS Lambda functions, create an account here.
infoAWS Cloud should be free for regular use, as AWS Lambda offers up to 1 million requests and 1 GB of outbound data transfer per month for free.
Creating an Amazon Alexa Smart Home Skill
-
Login: Open the Alexa Developer Console and log in with your developer account.
-
Create a Skill: In the Skills tab, click on Create Skill.
-
Basic Skill Information:
- Provide a Skill name, for example,
Home Assistant
. - Select
English (US)
as the default language (Czech is not yet available).
- Provide a Skill name, for example,
-
Skill Configuration:
- For Experience, select
Smart home
. - Choose
Smart Home
as the Model. - Set Hosting service to
Provision your own
. - Ensure Payload version is set to
v3
. - Note down the
Skill Id
for future use.
- For Experience, select
Creating an AWS Lambda Function
-
Creating an IAM Role for the Lambda Function
-
Navigating in AWS:
- Open the IAM service (Manage access to AWS resources).
- In the left panel, select Roles and click on Create role.
- Select
Lambda
as the AWS service.
-
Adding Permissions: Add Permissions policies named
AWSLambdaBasicExecutionRole
. -
Role Settings:
- Name the new role, for example,
AWSLambdaBasicExecutionRole-SmartHome
. - Complete the role creation.
- Name the new role, for example,
-
-
Creating the Lambda Function
Very ImportantSelect the correct region for the Lambda function according to the language set for the Amazon Alexa Smart Home Skill:
- US East (N.Virginia) for English (US) or English (CA)
- EU (Ireland) for English (UK), English (IN), German (DE), Spanish (ES), or French (FR)
- US West (Oregon) for Japanese and English (AU)
-
Setting the Region: Switch AWS Cloud to the correct region, in this example US East (N.Virginia).
-
Creating the Lambda Function:
- Open the Lambda service in AWS (Run code without thinking about servers).
- You should be in the Functions tab.
- Click on Create function and select
Author from scratch
. - Name the function, for example,
SmartHome-US
. - Choose
Python 3.10
as the runtime and leave the architecture asx86_64
. - Click on Change default execution role, select
Use an existing role
, and choose the role created in the previous steps. - Click on Create function.
-
Lambda Function Settings - Adding a Trigger
- Click on the created Lambda function and in the Function overview section, click on Add trigger.
- Select Alexa as the source and change the product to Alexa Smart Home.
- Enter the Skill ID obtained in the Amazon Alexa Smart Home Skill section.
- Click on Add.
-
Lambda Function Settings - Adding Code
- In the Code section, click on the lambda_function tab and paste the code from GitHub.
- Click on the Deploy button to save the pasted code.
-
Lambda Function Settings - Setting Environment Variables
- The next step is to set the environment variables, which can be found in the Configuration tab and Environment variables.
- Set the following variables:
- BASE_URL =
https://[YOUR HA URL]
. - NOT_VERIFY_SSL =
False
- depending on the valid certificate. - DEBUG =
True
- for testing, later change toFalse
. - LONG_LIVED_ACCESS_TOKEN - generated in HA.
- BASE_URL =
- Save.
Testing the Lambda Function
To enable testing, we will jump ahead a bit. Insert the following minimal configuration into the Home Assistant configuration file:
alexa:
smart_home:
After inserting the configuration, restart Home Assistant.
After the restart, return to the AWS Lambda console and prepare for testing:
-
Go to the Test tab.
-
Click on Create new event.
-
Name your new event, for example,
Discovery
. -
In the Event JSON field, enter the following data:
{
"directive": {
"header": {
"namespace": "Alexa.Discovery",
"name": "Discover",
"payloadVersion": "3",
"messageId": "1bd5d003-31b9-476f-ad03-71d471922820"
},
"payload": {
"scope": {
"type": "BearerToken"
}
}
}
} -
Click the Create button in the upper right corner.
-
Then press Test.
The result should be a list of your devices in the response from Home Assistant.
Configuring the Smart Home Service Endpoint
Removing the long-lived access token - I recommend removing the long-lived access token that we will no longer need and changing the DEBUG setting to False
.
-
Copying the Lambda Function ARN: Copy the Amazon Resource Name (ARN) of your Lambda function.
-
Returning to the Alexa Developer Console:
- Return to the Alexa Developer Console.
- If you are not already on the Skills page, navigate to it.
- Find the skill you created and click the Edit link in the Actions column.
-
Setting the Smart Home Service Endpoint:
- In the left navigation panel of the Build page, click on SMART HOME.
- In the 2. Smart Home service endpoint section, fill in the Default endpoint with the ARN you copied from your Lambda function configuration.
-
Click Save.
Linking the Account
-
We should still be on the Alexa Developer Console page and see the 3. Account Linking section with a Setup Account Linking button. Click on it.
-
Account Linking Form Settings:
- Check the option
Do you allow users to create an account or link to an existing account with you?
- In the Your Web Authorization URI field, enter
https://[YOUR HA URL]/auth/authorize
. - In the Access Token URI field, enter
https://[YOUR HA URL]/auth/token
. - Fill in the Your Client ID field as follows:
https://pitangui.amazon.com/
if you used the US East (N.Virginia) region.https://layla.amazon.com/
if you used the EU (Ireland) region.https://alexa.amazon.jp/
if you used the US West (Oregon) region.
- The Your Secret field can remain arbitrary, Home Assistant does not use this value.
- For the Your Authentication Scheme field, select
Credentials in request body
. - Add one scope named
smart_home
to the Scope field.
- Check the option
Configuring the Alexa Smart Home Integration in HA
We will need to add a new section to the Home Assistant configuration file:
alexa:
smart_home:
However, I recommend at least adding filtering for the entities we want to send to Alexa or, conversely, those we do not want to send. We can also rename entities for Alexa or set them to behave as a different type.
alexa:
smart_home:
filter:
include_entities:
- light.kitchen
- light.kitchen_left
include_entity_globs:
- binary_sensor.*_motion
include_domains:
- switch
exclude_entities:
- switch.outside
entity_config:
light.kitchen:
name: "Custom Name for Alexa"
description: "The light in the kitchen"
switch.stairs:
display_categories: LIGHT
Comments