home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.67k stars 30.42k forks source link

Alexa integration: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid #35917

Closed msp1974 closed 1 year ago

msp1974 commented 4 years ago

The problem

I get frequent log entries with the following message:

Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.

The integration seems to continue to work but this gets logged about every 1-2 hours. Presume when this happens it is requesting a new access token, so should this be in the error log? Is it part of normal operation?

Environment

Problem-relevant configuration.yaml

This is setup with UI config

Traceback/Error logs

The first occurred is about 2 hours after last rebooting.

Log Details (ERROR)
Logger: homeassistant.components.alexa.state_report
Source: components/alexa/state_report.py:49
Integration: Amazon Alexa (documentation, issues)
First occurred: 0:12:50 (7 occurrences)
Last logged: 11:35:52

Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.

Additional information

probot-home-assistant[bot] commented 4 years ago

alexa documentation alexa source (message by IssueLinks)

ochlocracy commented 4 years ago

This will usually resolve itself once the old tokens expire. But it you want to force it, disable the Home Assistant skill in the Alexa app and then re-enabled it. Restart HA as needed.

ochlocracy commented 4 years ago

@msp1974 Are you still experiencing this?

msp1974 commented 4 years ago

Yes. It now shows 32 occurences since 21st May. Havent disabled/re-enabled the skill yet but will do tonight and report back.

msp1974 commented 4 years ago

So i disabled the Alexa integration in HA Cloud, disabled the skill in Alexa, rebooted and added it all back/relinked etc and the same messages started appearing a few hours after, so sorry, this did not seem to fix it.

`Log Details (ERROR) Logger: homeassistant.components.alexa.state_report Source: components/alexa/state_report.py:49 Integration: Amazon Alexa (documentation, issues) First occurred: 1:07:45 (3 occurrences) Last logged: 9:19:46

Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.`

tommyjlong commented 4 years ago

As an FYI, I had the same issue. I did as suggested by re-enabling the skill, and restarted HA. After about an hour, I don't see these logs anymore.

bturrie commented 4 years ago

I am having the same issue. I haven't done anything about it because it does not appear to have any significant effect on alexa cloud performance.

hugalafutro commented 4 years ago

Getting the same suddenly out of the blue from yesterday. Using HA 0.112.4 installed in python venv on RPi 3b+ Everything seems to be working fine, but the sudden error in logs bothers me. I've tried re-enabling the HA skill in Alexa app and restarting HA but the error keeps popping up every now and then.

jluc2808 commented 4 years ago

hello, getting the same issue, which appears every often minutes : Logger: homeassistant.components.alexa.state_report Source: components/alexa/state_report.py:49 Integration: Amazon Alexa (documentation, issues) First occurred: 12 juillet 2020 à 20:35:31 (2989 occurrences) Last logged: 10:16:28

release and recreate skill association, restart HA, control that lambda test is OK, control port 8123 and 443 is OK from inside and outside. control the validity of the secret and client_id, control that both secret client_id are declared inside configuration.yaml.

So i'm stock with this issue.

as mentioned above , i don't know if this issue have or havn't an effect, but i suspect that 'return status' of devices aren't correctly fetched and displayed by HA thanks to help to solve

hugalafutro commented 4 years ago

but i suspect that 'return status' of devices aren't correctly fetched and displayed by HA

I don't think it even affects this as I only use HA skill in alexa through which I control everything connected to HA including hue, tp-link and meross plugs / lights for which I needed separate alexa skills before, and the status of the devices is always correct in both HA and Alexa. Have you noticed some discrepancies in the entity states between alexa and HA?

That said I'd still like the error gone and / or explained as it must be presumably stemming from some underlying issue. This worries me especially since I subscribed to the HA cloud service only for the alexa integration and couple weeks later it starts throwing out errors.

There's been at least 3 updates to HA since it started happening to me. I didn't do any update, nor restart nor change anything in HA config the day it started and suddenly this error pops up in logs sometimes 10 times a day, sometimes 10 times an hour. Although nowhere near the 2k+ occurrences from your log.

jluc2808 commented 4 years ago

but i suspect that 'return status' of devices aren't correctly fetched and displayed by HA

I don't think it even affects this as I only use HA skill in alexa through which I control everything connected to HA including hue, tp-link and meross plugs / lights for which I needed separate alexa skills before, and the status of the devices is always correct in both HA and Alexa. Have you noticed some discrepancies in the entity states between alexa and HA?

That said I'd still like the error gone and / or explained as it must be presumably stemming from some underlying issue. This worries me especially since I subscribed to the HA cloud service only for the alexa integration and couple weeks later it starts throwing out errors.

There's been at least 3 updates to HA since it started happening to me. I didn't do any update, nor restart nor change anything in HA config the day it started and suddenly this error pops up in logs sometimes 10 times a day, sometimes 10 times an hour. Although nowhere near the 2k+ occurrences from your log.

i'm quite with the same situation, i don't noticed discrepancies in the state as i didn't checked the return status of each object after using alexa (generaly i use alexa order when i'm not with my smartphone or tablet or PC to send the order, so it's not easy to control with this usage). if i'm looking in the log the error occured 3177 time in 3 days (life time of HA till my last restart). So it could be a good reason to fetch why the error append.

mkanet commented 4 years ago

Are there any suggestions on how to prevent this from happening? I've been subscribed to the HA cloud for several months now. However, this just started happening to me for about 1-2 weeks ago.

I've already disabled/re-enabled the HA Alexa skill and re-authenticated with an Amazon Captcha code in HA. However, I'm still seeing these errors in my log regularly.

hugalafutro commented 4 years ago

Anybody still getting these in HA 0.113.2 ? Haven't seen it since updating to this version, but no idea if it's fixed or if I'll get it later as I only get it sparsely compared to other commenters.

jluc2808 commented 4 years ago

i'm now under HA 113.2 and still get the error, every 10 minutes

mkanet commented 4 years ago

Anybody still getting these in HA 0.113.2 ? Haven't seen it since updating to this version, but no idea if it's fixed or if I'll get it later as I only get it sparsely compared to other commenters.

Im using HA 113.2 and still get the error regularly.

hugalafutro commented 4 years ago

Spoke too soon, the error popped up again an hour ago.

mkanet commented 4 years ago

Spoke too soon, the error popped up again an hour ago.

I noticed that I don't get these errors until after Home Assistant has been up and running running for a while. It seems like something triggers these errors. Once I get this error, I'll get the errors regularly.

ochlocracy commented 4 years ago

If you're using a custom built skill verify the skill still has the permission configured to "Send Alexa Events" in the Alexa developer console.

Verify your Alexa configuration is using the correct endpoint for your locale, and your client_id and client_secret still match with what's provided in developer console for your skill.

  locale: en-US
  endpoint: https://api.amazonalexa.com/v3/events
  client_id: !secret alexa_client_id
  client_secret: !secret alexa_client_secret

If you're using HA Cloud/Nubu Casa, or roll your own custom skill try the following:

This is a long shot.... but, try disabling/re-enabling the Alexa HA skill from the Alexa Web based app. e.g. https://alexa.amazon.com

I once had an unrelated issue during development causing issues with the Alexa API; I eventually reached out to Alexa Developer support, and this was the solution that eventually fixed the issue I was having at the time. Previously, I'd had been using only the mobile app to disable/re-enable the skill.

If you've been using this web app, try from the mobile app instead. Also verify all the devices in the Alexa app are connected via Home Assistant and available. If not, delete the device from the Alexa app, and re-discover.

There is also a "nuclear" command to Remove All devices in the web app... If you want to try removing everything, disabling the skill, and trying a fresh start.

mkanet commented 4 years ago

I have a custom skill enabled in my Alexa app. However, my Home Assistant setup doesn't utilize that skill, at least not to my knowledge. ...Does Nabu Casa try to access ALL my skills in my Alexa app; including my custom Developer skill?

ochlocracy commented 4 years ago

There are several ways to integrate Alexa into Home Assistant, I'll clarify for the purpose of this issue. But the INVALID_ACCESS_TOKEN_EXCEPTION message is related to the Smart Home Integration:

For Alexa Smart Home integration you should choose to use one of the following:

  1. Use Home Assistant Cloud/Nabu Casa Subscription, with the Official Home Assistant Skill from Nabu Casa
  2. Build your own Private Alexa Smart Home Skill, with your own AWS Lambda Function such as HASSKA,this would be your own private developer skill and doesn't need to be published.

If you're using both smart home integrations... then that's likely the cause of the problem.

If you're using Nabu Casa, then all the configuration should be done through the UI or in the cloud: configuration.

Note: You could also have your own custom Alexa skill that uses Home Assistant intents functionality, but that is completely separate from the Smart Home integration.

mkanet commented 4 years ago

My private Alexa skill doesn't have anything to do with smart home. It's used to control Event Ghost software with voice commands (unrelated to HA). I only have Nabu Casa enabled in the HA GUI. I don't have any Nabu Casa configuration settings in configuration.yaml. I only use Nabu Casa to sync my HA scripts to Alexa so the scripts are accessible to Alexa Scenes. However I'm still getting these errors on occasion.

hugalafutro commented 4 years ago

I do not have neither I've ever had private alexa skill. I only ever used the Nabu Casa configuration in UI and official Home Assistant skill in Alexa app on phone. Never configured anything Alexa / cloud related in .yaml manually. This was running fine for months, and still is, but since about month ago this error started popping up. Everything still works, devices and the state they're in show correctly in both HA and Alexa, but the error has to be coming from somewhere.

mkanet commented 4 years ago

Mine also happened recently. I haven't had any changes to my configuration. I have only updated Home Assistant versions. I can check my private Alexa skill for that setting, however, I've been using it that way for a relatively long time before this issue started.

jluc2808 commented 4 years ago

Mine began as soon as connect Alexa with ha. I have checked every recommandations, restart, reconnect alexa, tested aws, still the same

probot-home-assistant[bot] commented 4 years ago

cloud documentation cloud source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @home-assistant/cloud, mind taking a look at this issue as its been labeled with an integration (cloud) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

mkanet commented 4 years ago

I need assistance to enable: "Send Alexa Events" permission for my private skill. Could someone please kindly tell me how/where to navigate to this setting in my skill under the Developer Console? The closest I can get is the screenshot below; which isn't correct: Send-Alexa-Events

Thanks!

ochlocracy commented 4 years ago

@mkanet Home Assistant only send events to Alexa for "Smart Home" Skills. Your private skill is a "Custom" Skill. For Custom skills you want to use the intent scripting. The INVALID_ACCESS_TOKEN_EXCEPTION error has nothing to do with your "Custom" skill.

mkanet commented 4 years ago

@oischinger thanks for letting me know. There isn't anything more I can do to prevent these errors. I only have Nabu Casa enabled with no configuration settings in my configuration.yaml file. I have already tried disabling/enabling my Alexa skill in the Alexa app with no luck.

The only other thing I have that's related to Alexa is the HACS addon called, Alexa Media Player. Would that have anything to do with this error? There's nothing else I can think of that would cause this error; other than the Nabu Casa cloud integration itself.

rjenx commented 4 years ago

Just for the record, I have Nabu Casa installed and configured for Alexa integration, I have been seeing the invalid access token issue for some days and yesterday I bit the bullet and removed all integration related to Alexa and reinstalled. This morning I woke up to the same error again. It doesn't seem to a major impact to operation of the integration, I have yet to identify any functionality affected. I am on the latest HA version 0.114-3 running in a docker container on Synology NAS.

KennethLavrsen commented 3 years ago

I am constantly seeing this error message also and have for many months. I am Nabu Casa subscriber. I cannot see anything not working. Just a flood of error messages

merloose commented 3 years ago

I had the same. it appeared for instance every time I had an action perform on a switch I got it solved as follow (using custom lambda skill, Login with amazon, and know very very little about coding so excuse me in advance). It seems I had the wrong client_ID and client_secret configuration in HASS 1 - On LWA security profile added your HASS url:port as allowed origin 2 - On alexa skill / permission tab: enable "send Alexa event" and copy Alexa Client Id and Alexa Client Secret which appears underneath 3 - on configuration.yaml in Hass: set client_id as the "alexa client id" previously copied and set client_secret as the "alexa client secret" previously copied. (I was using there previously the client ID and secret provided in the security profile and not the on apearing under skill permission) 4-relink/restart as necessary

And no more error... hope this help

xhemp commented 3 years ago

@merloose This one worked for me, thanks for sharing!

jkknighton commented 3 years ago

I'm getting the same error about the invalid access token but my Amazon account is also getting locked out. I've had to change the password several times now.

nhorvath commented 3 years ago

I was also having this error more than once per minute. I followed @merloose 's instructions (from step 2 on as my login with amazon was set up correctly) and that solved my issue. Make sure you restart home assistant then unlink/relink the alexa skill when you're done.

Just to provide some helpful info on how to find the permissions: Alexa Console: https://developer.amazon.com/alexa/console/ask Then click your skill, then click Permissions in the sidebar.

Drealine commented 3 years ago

I had the same. it appeared for instance every time I had an action perform on a switch I got it solved as follow (using custom lambda skill, Login with amazon, and know very very little about coding so excuse me in advance). It seems I had the wrong client_ID and client_secret configuration in HASS 1 - On LWA security profile added your HASS url:port as allowed origin 2 - On alexa skill / permission tab: enable "send Alexa event" and copy Alexa Client Id and Alexa Client Secret which appears underneath 3 - on configuration.yaml in Hass: set client_id as the "alexa client id" previously copied and set client_secret as the "alexa client secret" previously copied. (I was using there previously the client ID and secret provided in the security profile and not the on apearing under skill permission) 4-relink/restart as necessary

And no more error... hope this help

Not working for me. Not others idea ?

sjp770 commented 3 years ago

I completed the HASS.io how to last night and the step where I generate a long term token is where I first saw this. I generated the token and ran the test but got this reply. I moved on with the account linking and voice commands work find along with discovery. Should I remove the Long term code from the alexa skill?

paoloantinori commented 3 years ago

This error just happened to me, with haaska. I've fixed it by disabling the skill from the web console and re-enabling (and linking it). I'm not sure what created the issue in first instance BUT I had changed my Amazon account password a couple of times in the past days (and I had even to perform so kind of validation, due too many modifications. I suspect this might effect the tokens and generated the issue in first instance).

marcandre83 commented 3 years ago

I do have the same problem. I tried disabling and re-enabling the nabu casa skill, but it didn't help. The error occurs every hour once around the same time and I can not find anything accordingly in the logbook that could cause it

sjp770 commented 3 years ago

I disabled and re enabled the skill after updating a new long term key. Got a different error: SKILL_DISABLED_EXCEPTION

Found this for that problem: Problem was that I assumed that us-west-2 (Oregon) is North America, whereas it represents "Far East". As a result, the 403 with a description of "The user does not have a valid enablement for your skill." actually means that asynchronous notifications are being sent to the wrong endpoint.

Solved the problem by sending async events to the "Far East" endpoint for users hitting the lambda function in us-west-2 with an AcceptGrant request

So if the user submits an accept grant in this region then the endpoint is as follows:

us-east-1 -> North America: https://api.amazonalexa.com/v3/events eu-west-1 -> Europe: https://api.eu.amazonalexa.com/v3/events us-west-2 -> Far East: https://api.fe.amazonalexa.com/v3/events

schester44 commented 3 years ago

relink/restart as necessary

what steps are needed to "relink/restart" ? I'm a bit confused on what you all mean by relink here.

nhorvath commented 3 years ago

relink/restart as necessary

what steps are needed to "relink/restart" ? I'm a bit confused on what you all mean by relink here.

After you finish fixing the config restart home assistant. Then remove the integration. Then add it again.

sjp770 commented 3 years ago

relink/restart as necessary

what steps are needed to "relink/restart" ? I'm a bit confused on what you all mean by relink here.

Restart is done last - that's Home Assistant. First change the skill in Alexa development console if needed (such as updating a new long term access key) then unlink the skill in Alexa, restart HA then relink the Alexa skill to auth to your home instance.

Next step, wait overnight if it's still throwing errors. I think I was too keen and generated another code when it didn't have time to sync.

sjp770 commented 3 years ago

Note this is still broken - after fixing zones it works then drops off as if the token expired or something.

KennethLavrsen commented 3 years ago

I can confirm that is error is there logging this many times per day

I use Nabu Casa too and no custom skills.

Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid. 5:33:30 – Amazon Alexa (ERROR) - message first occurred at 22 March 2021, 15:18:29 and shows up 75 times

Things seem to generally work except I often get a “sorry something went wrong” response from Alexa though the command was executed and I suspect this could be related.

I just raised a ticket on Nabu Casa site. It was raised May 2020 so I think it may have been forgotten

FrancYescO commented 3 years ago

~~as relink/restart have not helped, looks i've solved the issue changing in the configuration yaml the endpoint from the generic one to the .eu endpoint: https://api.eu.amazonalexa.com/v3/events~~ nvm, error log spamming started again.

broyuken commented 3 years ago

I am seeing the same thing, I'm getting hundreds of these events per hour in my logs. Everything seems to work for the most part, but this is filling up my logs. I am not using Nabu Casa, my HA is open to the internet. I also tried rebuilding my skill from scratch but it didn't help. Also tried deleting all tokens from HA but that didn't help either.

Edit: One thing that changed in my environment which may have been around the time that this started happening was that I moved from just regular 443 to my HA instance to Nginx reverse proxy. My HA instance runs on port 8123 and the reverse proxy forwards it from https port 443 from the internet to http on port 8123. Certificate is handled by nginx/lets encrypt.

When I access my url from the internet I get no certificate warnings and it all works fine, but alexa appears to have some issues.

Edit 2: When I link alexa to my HA skill I get the following in my logs: 2021-04-27 11:10:49 ERROR (MainThread) [homeassistant.components.alexa.auth] Error calling LWA to get auth token

dorbitbrown commented 3 years ago

Disabling, then re-enabling the Home Assistant skill in the Alexa browser interface fixed this for me. Now I can use Alexa to set state variables!!

broyuken commented 3 years ago

Unfortunately that didn’t work for me

markPHL commented 3 years ago

Are any of you sharing camera entities with Alexa? I have the HACS Unifi Protect integration set up - when I exposed all my camera entities to Alexa through Nabu Casa I got a ton of these errors in my log. I removed them all yesterday and I've only seen the error once since.