Core: Alexa - Unable to link HA with Alexa Skill

Created on 30 Jun 2019  ·  33Comments  ·  Source: home-assistant/core

Home Assistant release with the issue: 0.95.4

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.): Docker

Component/platform: https://www.home-assistant.io/components/alexa.smart_home/

Description of problem:
I don't know which version or date this stopped working because I was using emulated hue component. However, others and I were trying to setup Alexa Smart Home Skill Component and the linking is not working.

According to this topic https://community.home-assistant.io/t/alexa-proactive-mode-unable-to-link-alexa/123530 people say that is an issue with proactive mode, however, I tried to disable it on my alexa dev console and removing it from the configuration file and I'm still unable to link my account with Alexa.

I also tested the lambda method using the AWS console and it is working fine, returning values when have the correct token.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

smart_home:
  endpoint: https://api.amazonalexa.com/v3/events
  client_id: !secret alexa_client_id
  client_secret: !secret alexa_client_secret
  filter:
    include_entities:
      - switch.alexandre_pc
      - switch.sonoff_basic_1
      - switch.sonoff_basic_2
      - switch.sonoff_basic_3
      - switch.sonoff_basic_4
      - switch.lightswitch_1_button_1
      - switch.lightswitch_1_button_2
      - switch.lightswitch_1_button_3
      - switch.lightswitch_2_button_1
      - switch.lightswitch_2_button_3
      - media_player.alexandre_tv
      - media_player.playstation_4
      - media_player.speaker_sala
      - climate.miairgateway1
  entity_config:
    switch.alexandre_pc:
      display_categories: LIGHT
      name: Computer
    switch.sonoff_basic_1:
      display_categories: LIGHT
      name: Computer Light
    switch.sonoff_basic_2:
      display_categories: LIGHT
      name: Bed Light
    switch.sonoff_basic_3:
      display_categories: LIGHT
      name: Livingroom Light
    switch.sonoff_basic_4:
      display_categories: LIGHT
      name: Bathroom Light
    switch.lightswitch_1_button_1:
      display_categories: LIGHT
      name: External Garage Light
    switch.lightswitch_1_button_2:
      display_categories: LIGHT
      name: Garage Light
    switch.lightswitch_1_button_3:
      display_categories: LIGHT
      name: Kitchen Light
    switch.lightswitch_2_button_2:
      display_categories: LIGHT
      name: External Entrance Light
    switch.lightswitch_2_button_3:
      display_categories: LIGHT
      name: Entrance Light
    media_player.alexandre_tv:
      display_categories: TV
      name: TV
    media_player.playstation_4:
      display_categories: SPEAKER
      name: Playstation 4
    media_player.speaker_sala:
      display_categories: SPEAKER
      name: Livingroom Speaker
    climate.miairgateway1:
      display_categories: THERMOSTAT
      name: Air Conditioning

Traceback (if applicable):

2019-06-29 10:35:36 ERROR (MainThread) [homeassistant.components.alexa.state_report] Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.

Additional information:

smart_home

Most helpful comment

By changing my HA external port to 443 (standard HTTPS) account linking just started working. Looks like Amazon Alexa doesn't like using non-standard ports for account linking.

All 33 comments

When I disabled "Send Alexa events", I managed to link it, however, it would be nice to have a proactive mode working as it was advertised for the cloud in 0.95

When I disabled "Send Alexa events", I managed to link it, however, it would be nice to have a proactive mode working as it was advertised for the cloud in 0.95

@Molodax
Can you confirm which lambda are you using?

@xalexslx I'm using the lambda that you posted on forum.

Still have this in my log:

Log Details (ERROR)
Mon Jul 01 2019 00:19:50 GMT+0200 (Central European Summer Time)
Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.

Yeah, I tried to fix the linking according to the docs but it didn't work.

@balloob
Can you help us here when you get time, please?

The same for me. Also if I use @xalexslx lambda, as soon as I activate “Send Alexa Events” in the Skill I am unable to link.
Tried also with Amazon as oauth provider and a fixed token for the lambda.

For proactive mode to be enabled, you need to have client ID and secret configured. Once that is set up, you need to relink the Alexa skill.

For proactive mode to be enabled, you need to have client ID and secret configured. Once that is set up, you need to relink the Alexa skill.

It was done (ID and secret configured, relink) @balloob but it doesn't work.

Are you using the right endpoint? It depends on where your lambda is hosted and where the account is linked which endpoint to use.

Are you using the right endpoint? It depends on where your lambda is hosted and where the account is linked which endpoint to use.

@balloob I am sure that I'm using the right endpoint because as soon as I disable "Send Alexa Events" in permissions, I am able to link Alexa and everything works in Alexa apart proactive status update since it is disabled. I've also checked the Client ID and Client secret. Others reproduced the same issue and discussed it on the forum (link above in the description)

What region is your lambda hosted and what endpoint do you use?

What region is your lambda hosted and what endpoint do you use?

endpoint: https://api.eu.amazonalexa.com/v3/events
lambda: Ireland

Thanks, @balloob

Region: us-east-1
Lambda: https://gist.github.com/awarecan/630510a9742f5f8901b5ab284c25e912
Default Endpoint: arn:aws:lambda:us-east-1:XXXXXXXXXXXX:function:HALambda
Send Alexa Events: Disabled
Testing Lambda via AWS Console with LLT: OK, Return my entities.
Config:

smart_home:
#  endpoint: https://api.amazonalexa.com/v3/events
#  client_id: !secret alexa_client_id
#  client_secret: !secret alexa_client_secret
  filter:
    include_entities:
      - switch.alexandre_pc
      - switch.sonoff_basic_1
      - switch.sonoff_basic_2
      - switch.sonoff_basic_3
      - switch.sonoff_basic_4
      - switch.lightswitch_1_button_1
      - switch.lightswitch_1_button_2
      - switch.lightswitch_1_button_3
      - switch.lightswitch_2_button_1
      - switch.lightswitch_2_button_3
      - media_player.alexandre_tv
      - media_player.playstation_4
      - media_player.speaker_sala
      - climate.miairgateway1
  entity_config:
    switch.alexandre_pc:
      display_categories: LIGHT
      name: Computer
    switch.sonoff_basic_1:
      display_categories: LIGHT
      name: Computer Light
    switch.sonoff_basic_2:
      display_categories: LIGHT
      name: Bed Light
    switch.sonoff_basic_3:
      display_categories: LIGHT
      name: Livingroom Light
    switch.sonoff_basic_4:
      display_categories: LIGHT
      name: Bathroom Light
    switch.lightswitch_1_button_1:
      display_categories: LIGHT
      name: External Garage Light
    switch.lightswitch_1_button_2:
      display_categories: LIGHT
      name: Garage Light
    switch.lightswitch_1_button_3:
      display_categories: LIGHT
      name: Kitchen Light
    switch.lightswitch_2_button_2:
      display_categories: LIGHT
      name: External Entrance Light
    switch.lightswitch_2_button_3:
      display_categories: LIGHT
      name: Entrance Light
    media_player.alexandre_tv:
      display_categories: TV
      name: TV
    media_player.playstation_4:
      display_categories: SPEAKER
      name: Playstation 4
    media_player.speaker_sala:
      display_categories: SPEAKER
      name: Livingroom Speaker
    climate.miairgateway1:
      display_categories: THERMOSTAT
      name: Air Conditioning

This file is being included by configuration.yaml

alexa: !include configs/alexa.yaml

Screenshots:
chrome_2019-07-01_19-12-38
chrome_2019-07-01_19-12-48
chrome_2019-07-01_19-12-56
chrome_2019-07-01_19-11-53

Okay, well then I don't know.

I have been wrestling with the same issue xalexslx (and others) have outlined above. I can't see any obvious things I'm doing wrong, but getting the same 'unable to link' message each time.

Hi!
For all having problems linking: For me, this lambda seems to be working ok (from here). Environment variables HOST and BEARER_TOKEN (long lived acces token) must be set. Handler is called lambda_function.event_handler
Can anyone confirm? Than maybe we can improve it to use the HA authentication instead of the long lived token.

Maybe this is the issue? I guess most of us are using Letsencrypt:
> If you have not implemented OAuth 2.0, you can use Login with Amazon (LWA) as your OAuth 2.0 provider or any provider that has a certificate signed by an Amazon-approved certificate authority. Note that you cannot use https://letsencrypt.org/, even though it is on the certificate list.

For the initial linking (only with Send Alexa Events enabled?) the token is send in the grantee payload.
See here:
{ "directive": { "header": { "namespace": "Alexa.Authorization", "name": "AcceptGrant", "messageId": "5f8a426e-01e4-4cc9-8b79-65f8bd0fd8a4", "payloadVersion": "3" }, "payload": { "grant": { "type": "OAuth2.AuthorizationCode", "code": "VGhpcyBpcyBhbiBhdXRob3JpemF0aW9uIGNvZGUuIDotKQ==" }, "grantee": { "type": "BearerToken", "token": "bearer-token-representing-user" } } } }

@awarecan
If I update the lambda function to include something like directive.get('payload', {}).get('grantee').get('token') then linking is possible even without a long lived access token.

@ronmichel
Are you using this lambda from Haaska but with the original alexa.smart_home component?

Edit:
Tried to use this lambda with original alexa.smart_home and it didnt work for me with or without send events.

I Got mine linking using the modified script with send events turned on
Modified Lambda function
It's a quick hack based on this forum post

below is my configuration.
AWS region: Ireland
I have the following enviroment Variables

BASE_URL - pointing to https://<myhomeassistant>
DEBUG: TRUE
LONG_LIVED_ACCESS_TOKEN: <token Value from Homeassitant>
NOT_VERIFY_SSL: <BLANK>

```yaml

secrets.yaml

alexa_event_endpoint: "https://api.eu.amazonalexa.com/v3/events"
alexa_client_id:
alexa_client_secret:

```yaml
alexa:
  smart_home:
    endpoint: !secret alexa_event_endpoint
    client_id: !secret alexa_client_id
    client_secret: !secret alexa_client_secret

Is this really working for anyone? I've been hammering on this now for two days without success. The 'test' function works without issue but linking the Skill always fails. I'm happy to provide whatever information would be helpful

I'll help but I'm not an expert I just know it took me over 2 weeks, which instructions have you used?

@aLTeReGo-SWI it doesn't work (doesn't link) if you follow the original instructions posted here > https://www.home-assistant.io/components/alexa.smart_home/ AND enable "Send Alexa Events". It looks like it is possible to have "Send Alexa Events" enabled but not with HA OAuth2.
@balloob announced support in 0.95 for proactive state reporting (enabled "Send Alexa Events") for cloud, assuming it is possible to make it work but...

I have the same issue. Following for update

It seems like finally managed to make it work using the updated lambda from @matt2005. The "secret" for me was to reboot the homeassistant after every disable and enable skill step in Alexa, otherwise, it messes up with tokens.

@Molodax could you please update the documentation?

@balloob I can update the docs, it will also require update of the lambda function.
It would be good to hear whether it was a solution for others.

I got it to link using the updated lambda code. Unlinked, restarted hass, linked.

By changing my HA external port to 443 (standard HTTPS) account linking just started working. Looks like Amazon Alexa doesn't like using non-standard ports for account linking.

Hello Guys
After a lot of hours trying too making it work, i finaly managed to make it work for me. The issue was: it doesn't work with the EU configuration for the client id and the lambda script. I had to use the US configuration for Alexa and AWS.
This message is just for the poor french guy triying the configure it with https://layla.amazon.com/

Closing issue as docs have been updated with new instructions.

Does anybody have this working on non-standard ports? Even with "Send Alexa Events" disabled I still get the same error.

Can confirm non-standard port don't work when used in Alexa skill account linking authorization/token URLs. I got it working using Login with Amazon and a long lived token in the Lambda.

Can confirm non-standard port don't work when used in Alexa skill account linking authorization/token URLs. I got it working using Login with Amazon and a long lived token in the Lambda.

You got working using login with amazon, what do You mean??

Was this page helpful?
0 / 5 - 0 ratings