Skip to content

Alexa Talking to Home Assistant (The Skill)

malorezzanzo64 edited this page Oct 3, 2023 · 13 revisions

Goals

  • import the skill
  • configure the skill
  • check the connection

You will use an automatic import directly from GitHub. Screenshots show it step by step.

Prerequisites

You did follow along the previous steps.

  • Your Amazon developer Account is set up.
  • The HACS Alexa Media Player integration is up and running.
  • Your Home Assistant system is accessible from outside and you know the URL.
  • You decided for a language aka the local code of Alexa.
  • You created and loaded the helper entities.

Token

Now get acquainted with token creation. You find it within your administrators profile.

Screenshot of the token management

If you want to use account linking instead, you don't need a token.

Language availability check

Actively check if there is already an interaction model for your language. The below screenshot may be outdated.

Screenshot 2023-10-03 at 13-58-07

Very important notice:


If there is an interaction model available, you will be able to import it directly. If it is not, choose en-US, aka English (US), during the creation of your skill and NOT your language. Later on, you can do the translation into your speech within the Alexa developer console.


Creating the Skill

Navigate to https://developer.amazon.com/alexa/console/ask and login with the same credentials you use for your Alexa devices.

Click the button "Create Skill" in the upper right hand corner.

Screenshot with create button

Name, Locale

Enter a skill name.

Screenshot of name input


Screenshot of German selection

The tutorial will proceed with German as an example for a language not Englisch, not US.


Click the button "Next" in the upper right hand corner.


Experience, Model, Hosting service

In the following selections choose "Other" > "Custom" > "Alexa-hosted (Node.JS)".

skill.model.selection.mp4

Finally select your "Hosting region".

Screenshot of region selection

Click the button "Next" in the upper right hand corner.


Templates

In the "Templates" tab click the button "Import Skill" on the right hand side.

Screenshot of button Import Skill

Insert the URL of the Github repository https://github.com/malorezzanzo64/HomeAssistantAlexaSkill.git and click the "Import" button.

Import skill template

Troubleshooting

Don't get confused by a bunch of messages. There are just a lot of asynchronous tasks going on. Provisioning of the resources may take a little longer than one minute. If it doesn't seem to finish within two minutes, though, head back to https://developer.amazon.com/alexa/console/ask/ and find your new skill already listed.

Amazon Alexa Console - Skills list

Configurations

In the moment of writing the import does not work as flawlessly and some finishing is still required. Open your new skill if it is not open already.

Configuring the Interaction Model

Invocation Name

Screenshot of skill invocation name in the checklist

Follow the menu to the "Skill Invocation Name". It has unfortunately been set to "change me" during the import. Set it to an invocation name of your choice.

before: change me

Click the "Save Model" button at the top.


The JSON Editor

Head over to Build > CUSTOM > Interaction Model > JSON Editor. Check that your invocation name has been set. This is the file that holds all the code of your interaction model and you can edit it in this central place. All parts of the graphical user interface of the interaction model are writing to it.

Screenshot of the JSON Editor

Click the "Build Model" button at the top.


Checking Success

After a little while building of the model has been finished. We now can test, that it is addressable. Open Test > Devlopment. Within the Alexa Simulator use your language to open the skill with it's invocation name. In English you would type "open Home Assistant Alexa Skill" if the given name is "Home Assistant Alexa Skill".

Screenshot of skill invocation within the Alexa Simulator

It should complain about the answer of the skill. That proves that the skill is addressable. It still does not work, because the code has not been configured yet. If it doesn't relate to the skill at all, it is not addressable and you have to check your setup.

Configuring the Node JS Code

It's time to connect the skill to Home Assistant. Open "Code > Skill Code > lambda > constants.js".

Screenshot 2023-10-04 at 00-14-20 Developer Console

Insert the outside URL to your Home Assistant installation into the variable HOME_ASSISTANT_URL. Replace the example URL.

In case you don't possess a valid certificate, you may want to set VERIFY_SSL to False. If you use the "Duckdns addon" with "Let's Encrypt", your certificate should be valid, though.

Create a long lived token within Home Assistant and insert it into the TOKEN variable.

Let the token variable empty, if you want to use account linking. Find account the account linking setup under Build > TOOLS > Account linking.


Click the button "Deploy" in the upper right hand corner.


Checking Success

After a little while deployment of the model has been finished. We now test, that it can speak to our Home Assistant system. Open Test > Devlopment. Within the Alexa Simulator use your language to open the skill with it's invocation name. In English you would type "open Home Assistant Alexa Skill" if the given name is "Home Assistant Alexa Skill".

Screenshot of a successful connection to HA

We now should get a welcome messageresponse speaking the content of input_text.alexa_text, that we did setup. The Skill did successfully connect to the Home Assistant system. If it didn't you have to check your setup.


Head to the next step: Home Assistant Talking to Alexa (The Script)