[Addon] HA Skill - an addon to setup Alexa Smart Home integration

Hello Folks,

I created HA Skill - a HomeAssisstant addon for allowing Alexa to talk to HA. It draws inspiration from the official setup guide. The main differences are

  1. The HomeAssistant endpoint doesn’t need to be publicly accessible.
  2. The addon sets up the Lambda function automatically
  3. You don’t need to sign in to your HomeAssistant account to link the Alexa Skill

The basic setup steps and requirements are the same.

  1. Create an AWS Account
  2. Create an IAM user for the addon to use
  3. Create an Alexa developer account
  4. Create a Skill
  5. Install/Run the addon
  6. Finish skill setup
  7. Enable the skill in your Alexa account
  8. Enjoy

Go to GitHub - adamirr/ha_addons: Collection of custom HomeAssistant addons to install the addon

This is the first addon I have created and published. Let me know if anything looks whacky or doesn’t work as expected.

1 Like

Hi,
thank you. Exactly what I am looking for. I need to enter my aws acces key and secret, where do I find them?

In your AWS account, go to the IAM console, go to IAM User and create a new user. When you create the user it will should you the access key and secret key. Use those in the addon.

See the AWS docs if you need more details Creating an IAM user in your AWS account - AWS Identity and Access Management

I set everything up and in the alexa app it said skill configured succesfully, however in home assistant I have the following error:
Login attempt or request with invalid authentication from ec2-34-248-5-89.eu-west-1.compute.amazonaws.com(54.77.190.238). See the log for details.

Logger: homeassistant.components.http.ban
Source: components/http/ban.py:82
Integration: HTTP (documentation, issues)
First occurred: 16:32:33 (92 occurrences)
Last logged: 16:43:57

I am also a little confused, because in the link it eays eu-west-1 although in aws the region is us-east-1. Do I have to paste the value of AlexaEndpoint anywhere?

Did you use the Lambda that is created by this addon? The addon is setup in a way that the Lambda doesn’t talk directly to HomeAssistant so seeing auth failures for ec2-… makes me think you are using an old Lambda or otherwise didn’t use the auth endpoints created by the addon.

Yes i didn’t use the lambda that was created. I deleted everything and wanted to start over again. I created my user with the policy, the iam role and my skill. When i start the addon i get the following error:
023-07-04 20:34:11 INFO Starting up!
2023-07-04 20:34:12 INFO Creating CloudFormation stack neuerSkill
2023-07-04 20:34:12 INFO Waiting for stack neuerSkill to be created
Traceback (most recent call last):
File “/run.py”, line 136, in
handle_cloudformation_stack(session, options[‘CloudFormation Stack Name’], stack_params=stack_params)
File “/run.py”, line 45, in handle_cloudformation_stack
create_waiter.wait(StackName=stack_name)
File “/usr/lib/python3.11/site-packages/botocore/waiter.py”, line 55, in wait
Waiter.wait(self, **kwargs)
File “/usr/lib/python3.11/site-packages/botocore/waiter.py”, line 375, in wait
raise WaiterError(
botocore.exceptions.WaiterError: Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression “Stacks[].StackStatus” we matched expected path: “ROLLBACK_COMPLETE” at least once

You’ll need to go into the AWS CloudFormation console, click on the stack name, look through the events, and see what the error message says there.

Like for the oldest event that was an error.

I deleted the stacks and now I have everything set up. The skill was added successfully but I don’t have any devices in the Alexa app. I dont get any errors. I even tried giving one of my entities a custom name:

alexa:
  smart_home:
  entity_config:
    switch.baustelle_switch:
      name: "123Baustelle"

Looks like your indentation is off. Take a look at Amazon Alexa Smart Home Skill - Home Assistant → Alexa Smart Home Integration Configuration

Looks like you need

alexa:
  smart_home:
    entity_config:
      switch.baustelle_switch:
        name: "123Baustelle"

Although by default all entities should be included so it’s weird that nothing is showing up.

You can try going to the Lambda console in your AWS account and trigger an invocation with the following input

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

It should succeed and return a list of devices that Alexa exposes.

Yeah I just tried manually configuring the entity so I can see it easily in the app.
After trying your invocation i get the following message:

These are the protocol events in case you need them:

What do the addon logs says when the Lambda response is a 502?

Looks like I might need to make debugging this thing easier as there are 2 sets of logs and by default it doesn’t log much.

These are the logs:


2023-07-06 09:19:41 WARNING SQS Payload: {'body': '{"directive": {"header": {"namespace": "Alexa.Discovery", "name": "Discover", "payloadVersion": "3", "messageId": "1bd5d003-31b9-476f-ad03-71d471922820"}, "payload": {"scope": {"type": "BearerToken"}}}}', 'response_queue': 'https://sqs.us-east-1.amazonaws.com/187902379907/ha-skill-responses-2023_07_06___LATEST_92ce897230c64c90b7689d8de707a29f.fifo', 'group_id': 'bcd96aed-dd5d-4f46-93e7-29523d747373'}
2023-07-06 09:19:41 WARNING Got HA response {'status': 502, 'data': '502: Bad Gateway', 'group_id': 'bcd96aed-dd5d-4f46-93e7-29523d747373'}
2023-07-06 09:24:34 WARNING SQS Payload: {'body': '{"directive": {"header": {"namespace": "Alexa.Discovery", "name": "Discover", "payloadVersion": "3", "messageId": "1bd5d003-31b9-476f-ad03-71d471922820"}, "payload": {"scope": {"type": "BearerToken"}}}}', 'response_queue': 'https://sqs.us-east-1.amazonaws.com/187902379907/ha-skill-responses-2023_07_06___LATEST_216dfcabb3db4814bfd1b5363fb2e21b.fifo', 'group_id': '3fa0d7d0-6c67-4de5-9b15-82636618840f'}
2023-07-06 09:24:34 WARNING Got HA response {'status': 502, 'data': '502: Bad Gateway', 'group_id': '3fa0d7d0-6c67-4de5-9b15-82636618840f'}

I am not sure why the alexa API would cause a 502 when calling it. Have you restarted Home Assistant since adding the alexa entry into your config?

Can you try hitting the Alexa API for another terminal addon (I used the VSCode addon)

curl -s -X POST -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -H "Content-Type: application/json" http://supervisor/core/api/alexa/smart_home -d '{
  "directive": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover",
      "payloadVersion": "3",
      "messageId": "1bd5d003-31b9-476f-ad03-71d471922820"
    },
    "payload": {
      "scope": {
        "type": "BearerToken"
      }
    }
  }
}'

I also published a new version of the HA Skill addon (v1.0.4) that includes a debug option in the addon configuration. You can try enabling that to see if the addon logs show anything useful.

Somehow it now works. When i enter the code it returns my devices. However I still dont have them in my alexa app. Is it possible that it may take a while? I tried deactivating and reconfiguring my skill.

Now I see that the response is empty:

2023-07-07 10:21:07 DEBUG  Recieved response []

If I invoke the Test in VSCode or as a lambda test in aws I get devices in the return:

2023-07-07 10:22:42 DEBUG  Recieved response [sqs.Message(queue_url='https://sqs.us-east-1.amazonaws.com/187902379907/ha-skill-requests.fifo', receipt_handle...

The empty response is expected. The addon is constantly polling for any requests. If there are no requests after 20 seconds, it’ll return an empty list.

Did you setup the Alexa skill in the same Amazon account that you use for your Alexa devices? That’s the only reason I can think of for the Lambda finding devices but them not showing up in Alexa.

Yes I am using the same account for everything.

I deleted everything and set up the addon and skill and everything in lambda. Same issue. The tests return the devices but alexa doesnt find any. Can I provide you with any more information for trouble shooting?

Unfortunately I’m not sure where else to look to debug this. If the Lambda is finding devices the addon logic is working. Best I can tell is there is something wrong with how you registered / setup the Alexa skill - either picking the wrong account, wrong region, or wrong Lambda function. Double check that the Lambda being used by the skill is the one the addon setup (arn is in the addon logs). And make sure you selected the correct region for the addon (if you are in the US then us-east-1).

When you ask Alexa to discover devices, does the Lambda get invoked (do you see logs)?

Sorry to burst your bubble and all of your hard work. Anything dealing with AWS is hard work.

The easiest way to use Alexa on Home Assistant is with the Home Assistant Cloud. All of the AWS stuff is taken care of for you.

If a cloud subscription is an issue (what do you think AWS is?), then just install the Node-RED add-on, and in Node-RED install “node-red-contrib-alexa-cakebaked” to the pallette. Done. I use a free (contributions appreciated) service provided by Ben Hardill to create most of my Alexa devices.

After installing a device in ESPHome, I can have Alexa controlling it in five minutes.