Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid Access Token" - How to provide new credentials? #39

Open
jmwhite5 opened this issue Nov 30, 2022 · 25 comments
Open

"Invalid Access Token" - How to provide new credentials? #39

jmwhite5 opened this issue Nov 30, 2022 · 25 comments

Comments

@jmwhite5
Copy link

I've been using this integration for months without any issues.

Suddenly, I started getting this error:

2022-11-30 11:49:43.654 ERROR (MainThread) [custom_components.sonos_cloud] Household request failed (401): {"fault":{"faultstring":"Invalid Access Token","detail":{"errorcode":"keymanagement.service.invalid_access_token"}}}

What's the process for providing updated credentials?

@sparment
Copy link

sparment commented Dec 1, 2022

Yup - see issue #38 that I opened a couple weeks ago. Same issue.

@jmwhite5
Copy link
Author

jmwhite5 commented Dec 1, 2022

The issue went away this morning. I haven't changed or upgraded anything. Strange.

@sparment
Copy link

sparment commented Dec 1, 2022

For me the error has been showing up in the log at roughly 24 hour intervals.

@Tazmanian79
Copy link

Same for me happened from today. Reloading or restarting HA is no solution.

`Logger: custom_components.sonos_cloud
Source: custom_components/sonos_cloud/init.py:78
Integration: Sonos Cloud (documentation, issues)
First occurred: 09:18:44 (96 occurrences)
Last logged: 11:21:38

Household request failed (401): {"fault":{"faultstring":"Invalid Access Token","detail":{"errorcode":"keymanagement.service.invalid_access_token"}}}`

@jcallaghan
Copy link

Started seeing this in 2022.12.0 too. I upgraded to 2022.12.3 and the integration had further issues where it didn't load.

I dropped the integration be removing it and when prompted had Home Assistant remove the application credential. Once removed I added the integration again using the same Sonos Developer client ID and secret and it was working again.

I did have to rename my entities in line with what they were previously but that is no stress to have this up and running again.

@mycanaletto
Copy link

+1

@Steveelliott111
Copy link

Any ideas when this will be fixed, or is there an alternative to use rather than this add in. I reply on Sonos TTS for various alerts around the house, water leak sensors, doorbell notifications, smart door locks etc, and such like, and it's really frustrating that this doesnt work more than it does.

@jcallaghan
Copy link

Any ideas when this will be fixed, or is there an alternative to use rather than this add in. I reply on Sonos TTS for various alerts around the house, water leak sensors, doorbell notifications, smart door locks etc, and such like, and it's really frustrating that this doesnt work more than it does.

@Steveelliott111 did you try the fix above?

@sparment
Copy link

sparment commented Mar 5, 2023

@jjlawren I'm still seeing this issue in my logs. I have uninstalled SONOS Cloud and the credentials a few times and reloaded... the error comes back within a few days.

"Play request failed (401): {"fault":{"faultstring":"Invalid Access Token","detail":{"errorcode":"keymanagement.service.invalid_access_token"}}}"

Any suggestions?

@andonevris
Copy link

andonevris commented Mar 9, 2023

I'm getting this also, the access token expires and the only way to renew it is to delete and re-add the integration which fixes it temporarily

It makes audio announcements something you can't rely on because it can break at any time.

@jcallaghan
Copy link

I "think" I have seen this once since my comment in December 2022. This was in the last week or two. I got it back by reloading the integration. Didn't think anything of it. I'll see if I still have the logs and can find anything more specific. I'm always running the latest build or the beta depending on the monthly release cycle timing.

@aejay
Copy link

aejay commented Apr 16, 2023

I have been wrestling with this issue off and on the past few weeks, where the integration would stop working until either the next morning or until I restart HA; reloading the integration would do nothing, and it would show as failed to load on the integration screen ("Retrying setup: None").

Each time it happened, it seems like it would happen in the evening, which makes me wonder if we have an issue with timezones; I'm in CDT (GMT-5). Thinking in timezones breaks my brain a little, but is it possible that the expires_at for the access token is being misinterpreted as being good for longer than it should? The integration typically fixed itself by morning. Even this doesn't seem too likely, though, because I wouldn't have this issue every evening, just every few evenings.

Well, this was the behavior until last night; this time it broke, but it did not fix itself, and no amount of restarting HA helped. I had to remove and reconfigure the integration (opting to remove the application credentials when prompted). If I still see the behavior described above, I'll try to keep a better journal of exactly how often and at what time of day the issue occurs.

This completely broken behavior makes me wonder if there are two problems at hand here, though. I tried digging through the Sonos API docs and couldn't find this info, but does anyone know whether the grant associated with the refresh_token has a limited lifetime? i.e. are we supposed to be able to refresh the token indefinitely, or do we need to re-auth at some point?

Also... side question... does anyone know how to get better logging to try to diagnose this? The only information I've been able to get out of my logs has been the message listed in the main issue's description.

@jjlawren
Copy link
Owner

Sorry for the lack of response so far. I've taken several attempts at reproducing the issues described but I have not been successful.

That being said, I've been working on an alternative approach and HA 2023.5 will include a built-in support for the announce feature on TTS announcements and media_player.play_media (new language in the docs here). This will provide functionality similar to sonos_cloud but via local websockets instead of a cloud service.

Once the 2023.5 beta is available (or in dev today if you're particularly adventurous), you'll be able to test without needing a custom integration. Assuming the features are on par, that will likely be the way forward for Sonos announcements.

@andonevris
Copy link

That's great news, I've been trying to nail down what causes this to no avail. Sometimes it will go weeks without issue then it will happen twice in a week.

Bringing this functionality into HA will be very useful, as long as the features are on par with this integration as you mention.

@tpantano
Copy link

tpantano commented May 9, 2023

@jjlawren - Thank you for the update. I have been using the normal Sonos integration with the announce feature for the past week and it has been working great so far. I got rid of the Sonos Cloud integration entirely.

@aejay
Copy link

aejay commented May 10, 2023

I've just switched my setup to do the same, and it seems promising so far! In case anyone else was using the extra volume parameter to play announcements at a different volume than your media... remember to switch it to an integer percentage.

I thought the change wasn't working, but it was because I was asking for a volume of 0.35, so I just couldn't hear it. I've corrected it to 35 and it seems to be working the way I hope!

@jmwhite5
Copy link
Author

@jjlawren That great. I just switched away from using the Sonos Cloud integration as well. Everything seems to work OK except for one thing, when I use a media_player group I get the old behavior where the music is stopped instead of the announcement overlay (with sound ducking). Should I file a bug for this?

@jjlawren
Copy link
Owner

@jjlawren That great. I just switched away from using the Sonos Cloud integration as well. Everything seems to work OK except for one thing, when I use a media_player group I get the old behavior where the music is stopped instead of the announcement overlay (with sound ducking). Should I file a bug for this?

Make sure you're on 2023.5 and that you're passing the announce: true parameter.

Some old hardware doesn't seem capable of "mixing" the audio together and will instead silence it while playing the announcement, but it should still automatically resume afterwards.

@jmwhite5
Copy link
Author

jmwhite5 commented May 10, 2023 via email

@jjlawren
Copy link
Owner

Sounds like an issue with the media player grouping behavior in HA core. I'd suggest to open an issue there.

@jmwhite5
Copy link
Author

jmwhite5 commented May 10, 2023 via email

@claytonjn
Copy link

Everything seems to work OK except for one thing, when I use a media_player group I get the old behavior where the music is stopped instead of the announcement overlay (with sound ducking).

I don't want to keep this conversation going here too much because it doesn't apply to this custom integration but this might help someone else.

I noticed this behavior too, but I did a quick test and it does have the expected behavior with an "old-style" group (group.[...] instead of media_player.[...]) - with the "new-style" media_player group music stops with the announce: true parameter, but with the "old-style" group media ducks, the announcement plays, and media continues to play at the previous volume afterwards.

@jmwhite5 if you created an issue in HA core can you link to it? I'd like to follow so I know when I can stop using this workaround. Thanks!

@jmwhite5
Copy link
Author

Actually, I haven't file a bug yet @claytonjn. But the more I think about it, I'm not convinced that it's a media player group issue, because my group was working fine with the Cloud Sonos integration. There's something about this enhanced Sonos integration that doesn't handle groups the same way. @jjlawren feel free to give me more context if you feel otherwise and I'm happy to file an issue.

@jjlawren
Copy link
Owner

I haven't looked into it all, but the cloud integration always used the overlay method. It was not controlled by the announce option. I assume that's not being passed down the line.

@jmwhite5
Copy link
Author

@jjlawren Thanks for this additional info. I filed home-assistant/core#93046 to track the media_player group issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests