alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.54k stars 291 forks source link

Voice (TTS) Notifications stop working after first scan interval: `Login error detected; not contacting API` #2442

Closed Javisen closed 3 months ago

Javisen commented 3 months ago

Voice notifications only work when you reload the integration, but after a while they stop working.

System details

Logs no

danielbrunt57 commented 3 months ago

Hi, I also tried to enable only polling for updates, but after 10 minutes it asked me to re-authenticate. I restarted AMP without the polling updates and it seems to work without errors. So it didn't work for me.

Thanks for the feedback! Was/is http2push connected and working?

ushroff commented 3 months ago

I have the same issue. I was able to reload AMP after a number of reload tries after upgrading to 4.12.7 under HA 24.8.0. alexapy>= v1.28.2. Worked correctly until this morning. Notify. Alexa.Media no longer works. No log entries.

jesse-kaufman commented 3 months ago

Now that it's working, could you test enabling just polling for updates as that is how I now have mine set and it's working fine for me.

Just re-enabled polling for updates here .. crosses fingers

Over 24 hours later and everything is still working as expected here!

danielbrunt57 commented 3 months ago

Over 24 hours later and everything is still working as expected here!

That's good news! I had noticed a lot of very large log entries whenever it scanned for new devices, which I do not see as being all that useful a feature. I mean, how frequently is anyone adding new devices to Alexa and can't be bothered to just reload the integration??

I have the same issue. I was able to reload AMP after a number of reload tries after upgrading to 4.12.7 under HA 24.8.0. alexapy>= v1.28.2. Worked correctly until this morning. Notify. Alexa.Media no longer works. No log entries.

There has to be a log entry or entries related to the failure. Are you looking at the full log or just the synopsis in the top window of Logs? Also, It might not be an alexa_media &/or alexapy log entry. Did the notify.alexa_media service disappear or just not work?

Hi, I also tried to enable only polling for updates, but after 10 minutes it asked me to re-authenticate. I restarted AMP without the polling updates and it seems to work without errors. So it didn't work for me.

I think there might be a fundamental error in your initial authentication verification. Once the session token expires, it has to reauthenticate with the stored email, password and OTP secret (which generates an OTP code). If they fail then you get the reauth message. Remove the integration entry AND THE PICKLE FILE, redownload the custom_component in HACS, restart HA and re-add it.

antoweb commented 3 months ago

So what Is the solution?

jesse-kaufman commented 3 months ago

So what Is the solution?

Delete the pickle file, delete the integration, reboot, re-add the integration. It’s been said numerous times now

nicolacavallo84 commented 3 months ago

So what Is the solution?

Delete the pickle file, delete the integration, reboot, re-add the integration. It’s been said numerous times now

@danielbrunt57, @jesse-kaufman. No, I agree. It has never worked for me, I have tried countless times without ever having success. I have precisely followed every single advice in this conversation. The problem for me from what I have been able to understand among the thousand tests carried out is the excessive exchange of data with Amazon servers that causes the temporary disconnection of the integration. Like me here in Italy many people have the same problem as me without having yet found an effective solution. In my small way I want to help others to solve this problem. It does not seem right to me that without waiting for further feedback the problem was declared closed. For me it is still an open problem. To date the only solution to make notifications work continuously is to keep pooling disabled. While thanking you for the commitment and passion you put into all of this, I would ask you to change the status of this problem from closed to open also for the good of other enthusiasts who are still in my same condition. Thank you!

nicolacavallo84 commented 3 months ago

This is the mistake I had, that I have right now and that I have always had.

Registratore: alexapy.helpers Fonte: custom_components/alexa_media/init.py:785 Integrazione: Alexa Media Player (documentazione, problemi) Prima occorrenza: 15:53:03 (2 occorrenze) Ultima registrazione: 15:53:03

alexaapi.get_customer_history_records((<alexapy.alexalogin.AlexaLogin object at 0x7f119f5b86e0>,), {'max_record_size': 10}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Unauthorized',) alexaapi.get_last_device_serial((<alexapy.alexalogin.AlexaLogin object at 0x7f119f5b86e0>,), {}): An error occurred accessing AlexaAPI: An exception of type AlexapyLoginError occurred. Arguments: ('Unauthorized',)

Javisen commented 3 months ago

There is no single solution. I have not deleted the .pickle file, removed the integration, or done any automation to reload the integration. I just changed the Amazon password and deleted the alexa_mediayouremail@yourdomain.comget files that are in the HA configuration folder. And since I pointed it out here it hasn't failed again. I don't have Include devices via echo enabled.

nicolacavallo84 commented 3 months ago

Non esiste una soluzione unica. Non ho eliminato il file .pickle, rimosso l'integrazione o eseguito alcuna automazione per ricaricare l'integrazione. Ho solo cambiato la password di Amazon e cancellato i file alexa_mediayouremail@yourdomain.comget che si trovano nella cartella di configurazione HA. E da quando l'ho segnalato qui non ha più fallito. Non ho abilitato Includi dispositivi tramite echo.

Unfortunately I also tried this without any positive results. Everything suggested in this conversation has never worked for me.

antoweb commented 3 months ago

Non esiste una soluzione unica. Non ho eliminato il file .pickle, rimosso l'integrazione o eseguito alcuna automazione per ricaricare l'integrazione. Ho solo cambiato la password di Amazon e cancellato il file alexa_mediayouremail@yourdomain.comget che si trovano nella cartella di configurazione HA. E da quando l'ho segnalato qui non ha più fallito. Non ho abilitato Inclusi dispositivi tramite echo.

Purtroppo ho provato anche questo senza alcun risultato positivo. Tutto ciò che è stato suggerito in questa conversazione non ha mai funzionato per me.

Same here

danielbrunt57 commented 3 months ago

Today I started wondering if most of the various authentication issues aren't somehow related to the original error before all hell broke loose and that is the damn partitioned cookie error? I've just issued merge request !380 for alexapy v1.28.2 to revert my 1st fix which skips the "partitioned' key when retrieving the cookie as it only worked for a while for me but then stopped when alexapy v1.28.2 released it. The only fix I've found is to replace Python 3.12's cookies.py file with the one that should be coming in Python 3.13 (eta October, HA sometime after that).

If there's someone willing to try this on their system to see if it fixes their issue, I'll re-document everything here.

In alexapy merge request !380, I've also added a function to delete the cookiefile and I just issued PR #2462 to call that function when removing the config entry. I'm using amitfin's custom component Patch to automate re-replacing the cookies.py file when an HA update restores the python3.12 cookies.py as well as patching alexalogin.py file and AMP's __init__.py file to delete the pickle file when config entry is deleted.

Furthermore, I'm testing an edit I just completed (also in __init__.py) in the http2push processing where I've added code to update last_called when the PUSH_VOLUME_CHANGE command is received as I noticed that in addition to when you change the volume level on an echo, the command is also pushed whenever you speak to an echo and right now I'm seeing last_called update instantly. Check my video of it in action. Remains to be seen though whether it will work reliably in more active environments...

danielbrunt57 commented 3 months ago

@Javisen

I just changed the Amazon password and deleted the alexa_mediayouremail@yourdomain.comget files that are in the HA configuration folder.

Could you please clarify for me what this is? deleted the [alexa_mediayouremail@yourdomain.comget](mailto:alexa_mediayouremail@yourdomain.comget) files

danielbrunt57 commented 3 months ago

@nicolacavallo84

Unfortunately I also tried this without any positive results. Everything suggested in this conversation has never worked for me.

Can I get you to try this all with my patches?

Frucoboti commented 3 months ago

any way to return to 4.12.1 release? 2 weeks ago it was the solution with 2024.7.x

danielbrunt57 commented 3 months ago

any way to return to 4.12.1 release?

Not from HACS. You'd have to download the v4.12.1 zip file and manually replace alexa_media in custom_components.

Javisen commented 3 months ago

@Javisen

Acabo de cambiar la contraseña de Amazon y eliminé los archivos alexa_mediayouremail@yourdomain.comget que están en la carpeta de configuración de HA.

¿Podrías aclararme qué es esto? deleted the [alexa_mediayouremail@yourdomain.comget](mailto:alexa_mediayouremail@yourdomain.comget) files

html files that the integration creates in the HA configuration folder when you log in. One of them leads to resolving a chapta. Many Alexa media player users have had the integration work without problems since that/those files were removed. Html files that the integration creates in the HA configuration folder when you log in. One of them leads to resolving a chapta. For me it caused a 403 and I had to reconfigure the integration. Many Alexa media player users have had the integration work without problems since those files were removed.

nicolacavallo84 commented 3 months ago

@nicolacavallo84

Unfortunately I also tried this without any positive results. Everything suggested in this conversation has never worked for me.

Can I get you to try this all with my patches?

Yes, no problem, but first I have to go home, I will be away for about a week for work.

hubrikt commented 3 months ago

After upgrading to latest release (4.12.8), an error with cookie deletion appears:

Source: custom_components/alexa_media/__init__.py:1339

Failed to delete cookiefile: 'AlexaLogin' object has no attribute 'delete_cookiefile'
nicolacavallo84 commented 3 months ago

@danielbrunt57 after changing the time in seconds between scans from value 60 to value 600, my notifications work without problems at least for now. Right now I have AMP restart automation disabled and both pooling and new entity switches enabled. Hope it can help you understand the problem. Thanks again.

antoweb commented 3 months ago

@danielbrunt57 after changing the time in seconds between scans from value 60 to value 600, my notifications work without problems at least for now. Right now I have AMP restart automation disabled and both pooling and new entity switches enabled. Hope it can help you understand the problem. Thanks again.

Yes i can confirm Also here Is working since about 2 hours

danielbrunt57 commented 3 months ago

After upgrading to latest release (4.12.8), an error with cookie deletion appears:

Source: custom_components/alexa_media/__init__.py:1339

Failed to delete cookiefile: 'AlexaLogin' object has no attribute 'delete_cookiefile'

Yes, there was a failure on my part in not knowing all the ins and outs of PR's and Alan promptly merged my PR for the AMP side of the equation and bumped the version but alexapy merge request !380 is needed to add the required async def delete_cookiefile(self) function. For now, you can either:

danielbrunt57 commented 3 months ago

@danielbrunt57 after changing the time in seconds between scans from value 60 to value 600, my notifications work without problems at least for now. Right now I have AMP restart automation disabled and both pooling and new entity switches enabled. Hope it can help you understand the problem. Thanks again.

With 600 seconds, if http2push is working that effectively becomes 6000 seconds (100 minutes)

antoweb commented 3 months ago

With 600 seconds problem is not solved. There Is a definitive solution?

danielbrunt57 commented 3 months ago

With 600 seconds problem is not solved. Is there a definitive solution?

No.

javiges commented 3 months ago

I did everything, delete the file that is in .storage, the 2 Alexa files in the root of config/ I set the automation to reload the component and after a while it no longer notifies and asks me to authenticate, I use ha container

danielbrunt57 commented 3 months ago

Closing this as it's the same error message as #2453. Please use that issue for ongoing discussion.