- Requirements
- Create an Amazon Alexa Skill
- Create an AWS Lambda Function
- Add Code to the Lambda Function
- Getting the home_assistant_agent_id
- Test the Lambda Function
- Configure the Skill Service Endpoint
- Account Linking
- Enabling skill on Alexa App
- Alexa Locale
- This Alexa Skil requires your Home Assistant instance to be accessible from the Internet via HTTPS on port 443 using an SSL/TLS certificate. A self-signed certificate will not work, but a public trusted certificate or a certificate signed by an Amazon-approved certificate authority should work.
- An Amazon Developer Account. Sign up here.
- An Amazon Web Services (AWS) account is required to host the Lambda function for your Alexa Smart Home Skill. AWS Lambda is free to use for up to 1 million requests and 1GB outbound data transfer per month.
-
Sign into the Alexa Developer Console. You can create your free account on the sign-in page. Note: This must be created with the same
Amazon account
you use on your Alexa devices and app. -
Go to the
Alexa Skills
page if you are not already there, then click theCreate Skill
button to start the process. -
In the
Name, Locale
step: Input theSkill name
as you like, then select your skill’s Defaultlanguage
and clickNext
. Important: The language of your skill must be the same as the language of your Amazon/Alexa account. More information about supported languages here -
In the
Experience, Model, Hosting service
step: SelectOther
>Custom
>Provision your own
, then clickNext
. -
In the
Template
step: SelectStart from Scratch
and clickNext
. -
Review and click
Create Skill
. -
This may take a few seconds, please wait…
-
In the next screen, you will see some options, and in the right panel
Building your skill
, follow these steps:- Click
Invocation Name >
change the default invocation as you like, then clickSave
. - In the left-side navigation manu, go to
CUSTOM
>Interaction Model
>JSON Editor
, and drag and dropinteractionModels.json
file, then clickSave
.
- Still in the left-side navigation manu, go to
CUSTOM
>Interfaces
, scroll down toAlexa Presentation Language
, enable it, and uncheckHub Round
(This skill is not compatible).
- Now, go to
CUSTOM
>Endpoint
and take note ofYour Skill ID
.
- Click
-
You have created a skeleton of the skill. In the next step, we will do some developer work, but keep the
Alexa Developer Console
opened, as we will need to change the skill configuration later.
We will write a small piece of code hosted as an AWS Lambda function
that will redirect requests from the Alexa skill to your Home Assistant instance. Make sure that you have the API enabled in Home Assistant because it will process the request and send back the response. The Lambda function will then deliver the response back to the Alexa skill.
First, you need to sign in to your AWS console. If you don’t have an AWS account yet, you can create a new user with the 12-month free tier benefit. You don’t need to worry about the cost if your account has already passed the first 12 months, as AWS provides up to 1 million Lambda requests, 1GB of outbound data, and all inbound data for free every month for all users. See Lambda pricing for more details.
Next, you need to create a Lambda function.
-
Click
Services
in the top navigation bar, expand the menu to display all AWS services, then under theCompute
section, clickLambda
to navigate to the Lambda console or use the search field (Tip: AddLambda
as favorite). -
IMPORTANT - Alexa Skills are only supported in certain AWS regions. Your current server location will be displayed in the top-right corner (for example, Ohio). Select an available server below that is closest to your location and in your region, based on your Amazon account’s country. Alexa Lambda functions created on other servers will not work properly and may prevent account linking!
- US East (N. Virginia) region for americas:
English (US)
,English (CA)
,Portuguese (BR)
skills. - EU (Ireland) region for
English (UK)
,Intalian
,German (DE)
,Spanish (ES)
,French (FR)
skills. - US West (Oregon) region for
Japanese
andEnglish (AU)
skills (not tested yet).
- US East (N. Virginia) region for americas:
-
Click
Functions
in the left navigation bar to display the list of your Lambda functions. -
Click
Create function
:- Select
Author from scratch
, then input a Function name likeHomeAssistantAssist
. - Select Python 3.12 as the Runtime and x86_64 architecture.
- Don’t change the
default execution role
, leave it as defaultCreate a new role with basic Lambda permissions
.
- Select
-
Click
Create function
, then configure the details of the Lambda function. -
Expand the
Function overview
(if it isn’t already expanded), then click+ Add trigger
on the left part of the panel, then selectAlexa
from the drop-down list to add an Alexa trigger to your Lambda function. -
Select
Alexa Skills Kit
and input theSkill ID
from the skill you created in the previous step. (Tip: You may need to switch back to Alexa Developer Console to copy the Skill ID.), then click theAdd
button. -
Now scroll down to the
Code
tab >Code source
, then click theUpload from
button on the right and selectzip file
.- Upload the
lambda_function.zip
downloaded from the latest releases. - All the code will be replaced by the uploaded file, and you can’t edit it (If you want to edit any files, do it in your station before this step).
- Upload the
-
Click on
Deploy
button to publish the updated code. -
Navigate to the
Configuration
tab, selectEnvironment variables
on the left navigation menu. You need to addat least one environment variable
from the list below. The remaining variables areoptional
, but they configure specific features in the skill's operation. To add a variable, click onEdit
button, then add the following key and values:- (required) Key = home_assistant_url, Value = your Home Assistant instance’s Internet accessible URL (on 443 port). Do not include the trailing
/
at the end. - (optional) Key = home_assistant_agent_id, Value = Your Assist Agent ID. Instructions here
- (optional) Key = home_assistant_language, Value = Your Assist Language. (The default is the Assist configured language)
- (optional) Key = home_assistant_dashboard, Value = Your dashboard path name. Example:
mushroom
. (The default islovelace
) - (optional) Key = home_assistant_kioskmode, Value =
True
. Set this variable to enable KIOSKMODE. (Make sure you have this component installed, up, and running in your Home Assistant instance). - (optional) Key = debug, Value =
True
. Set this variable to log the debug messages and allow thehome_assistant_token
environment variable. - (optional, not recommended) Key = home_assistant_token, Value = Your Home Assistant Long-Lived Access Token. You will connect your Alexa Skill with your Home Assistant user account in the later steps, meaning you don’t need to add it here. However, you can add it here for debugging purposes. (You should remove and delete this environment variable after debugging is finished).
- (required) Key = home_assistant_url, Value = your Home Assistant instance’s Internet accessible URL (on 443 port). Do not include the trailing
-
Click the Save button in the bottom right-hand corner.
-
Important: If you are using a IA model, or your Home Assistant API response is
more than 3 seconds
(default configuration), you need to increase the function timeout, follow the steps below to change:
- With your Home Assistant open, navigate to Developer Tools, go to the
Actions
tab and follow the steps below:
- Search for
conversation.process
in the actions field and select:
- Activate the
Agent
field and select the desired conversational agent from the list:
- Switch to
YAML MODE
and copy the ID that is in theagent_id
field:
Now, you have created the Lambda function, and you are going to do a basic test.
- Navigate to the
Test
tab, then selectCreate new event
. - Name your event as you like, for example:
AssistTest
. - Enter the following data into the code box named
Event JSON
:
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "SessionId.sample-session-id"
},
"context": {
"System": {
"application": {
"applicationId": "amzn1.ask.skill.sample-application-id"
},
"user": {
"userId": "amzn1.ask.account.sample-user-id",
"accessToken": "sample-access-token"
},
"device": {
"deviceId": "amzn1.ask.device.sample-device-id",
"supportedInterfaces": {
"Alexa.Presentation.APL": {}
}
}
}
},
"request": {
"type": "LaunchRequest",
"requestId": "sample-request-id",
"timestamp": "2024-10-18T00:00:00Z",
"locale": "en-US"
}
}
-
Click
Save
in the top right-hand corner of the panel. -
Log in to your Home Assistant and generate a
long-lived access token
. After entering your long-lived access token into the environment variablehome_assistant_token
and setting thedebug
environment variable toTrue
, you can execute the test. -
To test, click
Test
in the top right-hand corner of the panel. -
If the test goes well and everything is OK with your function, the result will appear highlighted in green as
Executing function: succeeded
, This means the skill was started correctly.
Now, remove the long-lived access token
(if you want, recommended) from the environment variables and delete it from your Home Assistant.
-
Still in the
AWS Console
, copy theFunction ARN
of your Lambda function. -
Return to the
Alexa Developer Console
, and go to theAlexa Skills
page (if you are not there already). -
Find the skill you just created, and click the
Edit
link in theActions
dropdown list. -
Go to
CUSTOM
>Endpoint
in the left navigation bar of theBuild
page. -
Paste the
Function ARN
copied from your Lambda function in theDefault region
field and click theSave
button in the upper right corner.
Alexa needs to link your Amazon account to your Home Assistant account. Therefore, Home Assistant can ensure only authenticated Alexa requests can access your API. In order to link the account, you have to make sure your Home Assistant can be accessed from the Internet on port 443.
-
Return to the
Alexa Developer Console
, and go to the Alexa Skills page (if you are not there already). -
Find the skill you just created, and click the
Edit
link in theActions
dropdown list. -
Click
ACCOUNT LINKING
in the left navigation bar of theBuild
page. -
Check
the Do you allow users to create an account or link to an existing account with you? switch. -
In
Settings
,uncheck
the Allow users to enable skill without account linking switch. -
Scroll down and make sure that
Auth Code Grant
is selected. -
Input all information required. Assuming your Home Assistant can be accessed by
https://[YOUR HOME ASSISTANT URL]
. For Alexa account linking, by default, the standard port 443 is used (use your firewall to forward this, if needed):-
Your Web Authorization URI: https://[YOUR HOME ASSISTANT URL]/auth/authorize
-
Access Token URI: https://[YOUR HOME ASSISTANT URL]/auth/token Note: Although it is possible to assign a different port, Alexa requires you to use port 443, so make sure your firewall/proxy is forwarding via port 443. (Read more from the Alexa developer documentation about requirements for account linking). Despite the Alexa documentation’s disclaimer, however,
Let’s Encrypt
certificates are still accepted. Important: You must use avalid/trusted SSL certificate
for account linking to work. Self-signed certificates will not work, but you can use a freeLet’s Encrypt
certificate. -
Your Client ID:
- https://pitangui.amazon.com/ if you are in Americas.
- https://layla.amazon.com/ if you are in Europe.
- https://alexa.amazon.co.jp/ if you are in Japan, Australia (not verified yet).
Important: The trailing slash is important here (don’t change the URL above).
-
Your Secret: Input anything you like; Home Assistant does not check this field.
-
Your Authentication Scheme: Make sure you selected
Credentials in request body
. (Home Assistant does not support HTTP Basic). -
You can leave
Scope
,Domain List
, andDefault Access Token Expiration Time
as empty.
-
-
Click the
Save
button in the top right corner. -
Click
CUSTOM
in the left navigation bar of theBuild
page andBuild Skill
in the top right corner.
- You need to use the
Alexa Mobile App
to link your account.- In the
Alexa app
, navigate toMore
>Skills & Games
>Your Skills
->Dev
. - Click on the skill you just created.
- Click
Enable to use
. - A new window will open to direct you to your Home Assistant’s login screen.
- After you successfully log in, you will be redirected back to the Alexa app.
- Now, you can ask Alexa from your Echo device or the Alexa App to open the skill like Alexa, [your Invocation Name].
- In the
The locale should match the location and language used for your Amazon Echo devices. The current supported skill locales are described in main page page.