joeyhage / homebridge-alexa-smarthome

Connect Alexa devices to HomeKit
MIT License
62 stars 20 forks source link

too many request. try again in some time #129

Closed jonahgcarpenter closed 2 weeks ago

jonahgcarpenter commented 1 month ago

Describe Your Problem:

Getting this error in logs, even after leaving homebridge off all night and reinstalling the alexa addon [6/2/2024, 2:48:20 PM] [HomebridgeAlexaSmartHome] Alexa-Remote: rate exceeded response ... Retrying once in 58696ms [6/2/2024, 2:48:20 PM] [HomebridgeAlexaSmartHome] Alexa-Remote: rate exceeded response ... Retrying once in 37645ms [6/2/2024, 2:49:18 PM] [HomebridgeAlexaSmartHome] BEGIN capabilities for all devices: { "message": "Too many requests. Try again in some time." } END capabilities for all devices [6/2/2024, 2:49:18 PM] [HomebridgeAlexaSmartHome] After initialization - RequestUnsuccessful(Error getting smart home device state(s). Response: { "message": "Too many requests. Try again in some time."

Plugin Config:

{ "bridge": { "name": "Homebridge 1262", "username": "", "port": 51582, "pin": "202-30-841", "advertiser": "bonjour-hap" }, "accessories": [], "platforms": [ { "name": "Config", "port": 8581, "platform": "config" }, { "devices": [ "Thermostat", "Speakers" ], "excludeDevices": [], "auth": { "refreshInterval": 4, "proxy": { "clientHost": "homebridge.local", "port": 9000 } }, "amazonDomain": "amazon.com", "language": "en-US", "performance": { "cacheTTL": 30, "backgroundRefresh": false }, "debug": true, "platform": "HomebridgeAlexaSmartHome" } ], "disabledPlugins": []

Environment:

biomir commented 1 month ago

Same issue just observed.

tralce commented 1 month ago

+1 issue

julioviegas commented 1 month ago

same for me

zpole commented 1 month ago

Me too. Return to 2.1.2 helps

aovr1234 commented 1 month ago

Me too. Return to 2.1.2 helps

Having the same issue. I downgraded problem solved.

jonahgcarpenter commented 1 month ago

Me too. Return to 2.1.2 helps

Downgrading also solved my issue!!

mbpetrillo commented 1 month ago

I also had this issue. As soon as I reverted back to 2.1.2 everything worked again.

wunaidage commented 1 month ago

had the same issue. following suggested rolling back to 2.1.2, seems fixed

justin-robinson commented 4 weeks ago

Downgrade to 2.1.2 with

hb-service add homebridge-alexa-smarthome@2.1.2
tychoid commented 3 weeks ago

Same exact issue here. Downgrade to 2.1.2 fixed issue.

TZeys commented 3 weeks ago

same issue. downgrading to 2.1.2 OR 2.1.1 did NOT work

SheldorSheldonDZ commented 3 weeks ago

+1 same issue. Downgrading did NOT work, also newest version. Its kind of strange, bc it worked till yesterday with 2.1.4 and suddenly stopped with this error. Someone any ideas or help?

SheldorSheldonDZ commented 3 weeks ago

@joeyhage +1

grzech1991 commented 3 weeks ago

i have this same problem... @joeyhage

Predator602 commented 3 weeks ago

i have the exact same issue... @joeyhage

cesans commented 3 weeks ago

I have tried to figure out the issue, and both authentication and finding the devices are fine, but it fails when retrieving the state. I believe the error comes from all calls to /api/phoenix/state. I was working on a new installation and I have been able to drop the calls that get the state and the devices are added successfully... but without any useful communication with HB.

TZeys commented 3 weeks ago

yeah, I believe Amazon did some backend changes to the API, effectively bricking the retrieval of device states.

cesans commented 3 weeks ago

The requests are made with a copy of the alexa-remote2 npm package: https://www.npmjs.com/package/alexa-remote2 If the author of the plugin is no longer active, the authors of alexa-remote2 might be able to help here.

shenghan97 commented 3 weeks ago

Downgrading to version 2.1.2 worked for a few days, but it stopped working today. I was trying to figure out what changes broke the plugin.

I suspected changes in the API, but I'm not certain. Here's what I found so far:

My guess is that Amazon recently changed the authorization API, rolling it out in the US a few days before Germany. This would explain why version 2.1.2 with the hardcoded Germany endpoint worked for a few days before failing. However, if my assumptions are correct, I'm unsure why we were able to use the Germany authorization API while all the other APIs were for the US.

mbpetrillo commented 3 weeks ago

2.1.2 also stopped working for me today as well.

On Wed, Jun 12, 2024 at 10:45 PM shenghan97 @.***> wrote:

Downgrading to version 2.1.2 worked for a few days, but it stopped working today. I was trying to figure out what changes broke the plugin.

I suspected changes in the API, but I'm not certain. Here's what I found so far:

  • In version 2.1.3, the alexa-remote2 dependency was upgraded from v6.1.2 to v7.0.3, according to the changelog.
  • In version 2.1.4, alexa-remote.js was added to the repository. It's an edited copy of alexa-remote2 with unnecessary APIs removed.
  • I compared the alexa-remote.js in this repo to the one from alexa-remote2 v6.2.0, which should be the version 2.1.2 dependency at this moment, and didn't find many meaningful changes.
  • I discovered an upstream bug in alexa-remote2 v6.2.0, where the getAuthApiBearerToken function incorrectly referenced a fixed Germany API endpoint https://api.amazon.de/auth/token, regardless of the user's settings. This bug was fixed in v7.0.4, as well as in the version manually copied into the repo.

My guess is that Amazon recently changed the authorization API, rolling it out in the US a few days before Germany. This would explain why version 2.1.2 with the hardcoded Germany endpoint worked for a few days before failing. However, if my assumptions are correct, I'm unsure why we were able to use the Germany authorization API while all the other APIs were for the US.

— Reply to this email directly, view it on GitHub https://github.com/joeyhage/homebridge-alexa-smarthome/issues/129#issuecomment-2164250545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIKPASUBLFSVNMIXICGICOTZHEBTLAVCNFSM6AAAAABIVKK2E6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRUGI2TANJUGU . You are receiving this because you commented.Message ID: @.***>

grzech1991 commented 3 weeks ago

I'm using an air conditioner, I'm from Poland and given a .com domain in the app (as if it were American, not German).

I did a downgrade to 2.1.2 - it started working.

It stopped.

I did upgrade to 2.1.4 - the air conditioner is visible in homekit, but does not respond to temperature change.

Error:

[6/13/2024, 11:40:53 AM] [homebridge-alexa-smarthome] Alexa login cookie updated. Storing cookie in file: /volume1/homebridge/persist/.homebridge-alexa-smarthome [6/13/2024, 11:41:43 AM] [homebridge-alexa-smarthome] After initialization - RequestUnsuccessful(Error getting smart home device state(s). Response: { "message": "Too many requests. Try again in some time." })

sebrenner commented 3 weeks ago

Same problem.

HomeBridge: v1.8.2 Node.js: v20.12.2 Homebridge Alexa Smart Home: v2.1.2

END devices connected to Alexa account
[6/13/2024, 8:03:10 PM] [HomebridgeAlexaSmartHome] Found all 2 devices in plugin settings.
[6/13/2024, 8:03:10 PM] [HomebridgeAlexaSmartHome] Updating device states
[6/13/2024, 8:03:10 PM] [HomebridgeAlexaSmartHome] Alexa-Remote: rate exceeded response ... Retrying once in 41915ms
[6/13/2024, 8:03:10 PM] [HomebridgeAlexaSmartHome] Alexa-Remote: rate exceeded response ... Retrying once in 55804ms
[6/13/2024, 8:03:52 PM] [HomebridgeAlexaSmartHome] BEGIN capabilities for all devices: {
  "message": "Too many requests. Try again in some time."
} END capabilities for all devices
[6/13/2024, 8:04:06 PM] [HomebridgeAlexaSmartHome] After initialization - RequestUnsuccessful(Error getting smart home device state(s). Response: {
  "message": "Too many requests. Try again in some time."
})
ErikAbele commented 2 weeks ago

My guess is that Amazon recently changed the authorization API, rolling it out in the US a few days before Germany. This would explain why version 2.1.2 with the hardcoded Germany endpoint worked for a few days before failing. However, if my assumptions are correct, I'm unsure why we were able to use the Germany authorization API while all the other APIs were for the US.

When looking at my logs (debug enabled), I can see authorization working fine here (I'm in DE and using amazon.de) but right after that when alexa-remote is trying to get the device capabilities it gets a response of 429 (too many requests). Don't have the time to dig deeper but obviously Amazon changed some limits here and either amazon-alexa is really doing to many requests or Amazon did this intentionally to block it...

I stopped here due to time but this is the path to a solution: querySmarthomeDevices and, if anybody wants to dig deeper, here happens the 429 response of Amazon using the API endpoint /api/phoenix/state: https://github.com/joeyhage/homebridge-alexa-smarthome/blob/32176a6ca03186afed1d5200593ca73c0146854f/src/alexa-remote.js#L4201

cesans commented 2 weeks ago

I can get device capabilities just fine. It fails later when retrieving device states. I actually could add new devices after modifying the code a bit, but they are just useless without the ability of getting or setting the state.

El El vie, 14 jun 2024 a las 16:56, Erik Abele @.***> escribió:

My guess is that Amazon recently changed the authorization API, rolling it out in the US a few days before Germany. This would explain why version 2.1.2 with the hardcoded Germany endpoint worked for a few days before failing. However, if my assumptions are correct, I'm unsure why we were able to use the Germany authorization API while all the other APIs were for the US.

When looking at my logs (debug enabled), I can see authorization working fine here (I'm in DE and using amazon.de) but right after that when alexa-remote is trying to get the device capabilities it gets a response of 429 (too many requests). Don't have the time to dig deeper but obviously Amazon changed some limits here and either amazon-alexa is really doing to many requests or Amazon did this intentionally to block it...

— Reply to this email directly, view it on GitHub https://github.com/joeyhage/homebridge-alexa-smarthome/issues/129#issuecomment-2168217547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO4I6MWMSL4PAXIWLD3Y33ZHMAAXAVCNFSM6AAAAABIVKK2E6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRYGIYTONJUG4 . You are receiving this because you commented.Message ID: @.***>

ErikAbele commented 2 weeks ago

I can get device capabilities just fine. It fails later when retrieving device states.

Interesting, I just updated my comment above – did you arrive at the same querySmartHomeDevices or does that work for you?

cesans commented 2 weeks ago

Yes, that's where the issue happened. I can't find any documentation about this/api/phoenix/state API, was this maybe never intended to be used publicly?

shenghan97 commented 2 weeks ago

I did some more digging and finally found the cause—it looks like the Alexa API now rejects requests and returns a 429 error whenever the user agent string includes "AlexaRemote."

The quickest fix is to set the user agent suffix to an empty string, like this:

this._options.apiUserAgentPostfix = ''

You can find this in the alexa-remote.js file at line 118: https://github.com/joeyhage/homebridge-alexa-smarthome/blob/32176a6ca03186afed1d5200593ca73c0146854f/src/alexa-remote.js#L118

I've fixed this on my end by manually editing the file in the node_modules folder at homebridge/node_modules/homebridge-alexa-smarthome/dist/alexa-remote.js.

I can make a pull request this weekend, but I'm not sure when it will be merged.

ErikAbele commented 2 weeks ago

Yes, that's where the issue happened. I can't find any documentation about this/api/phoenix/state API, was this maybe never intended to be used publicly?

Yes, this seems to be a private API, there's zero docs and other devs are reverse engineering it, e.g. here.

ErikAbele commented 2 weeks ago

The quickest fix is to set the user agent suffix to an empty string, like this:

Haha, I was thinking about that too but didn't bother to try it; anyway, can confirm that changing the UA fixes the issue. So we can be pretty sure that this was an intentional block by Amazon.

I can make a pull request this weekend, but I'm not sure when it will be merged.

Yes, would be great. OTOH, I guess they will block empty UA strings then or find some other way to block it, oh my...

joeyhage commented 2 weeks ago

I did some more digging and finally found the cause—it looks like the Alexa API now rejects requests and returns a 429 error whenever the user agent string includes "AlexaRemote."

The quickest fix is to set the user agent suffix to an empty string, like this:

this._options.apiUserAgentPostfix = ''

You can find this in the alexa-remote.js file at line 118:

https://github.com/joeyhage/homebridge-alexa-smarthome/blob/32176a6ca03186afed1d5200593ca73c0146854f/src/alexa-remote.js#L118

I've fixed this on my end by manually editing the file in the node_modules folder at homebridge/node_modules/homebridge-alexa-smarthome/dist/alexa-remote.js.

I can make a pull request this weekend, but I'm not sure when it will be merged.

Great find. I would be happy to review the PR. Sorry all that I’ve been MIA, I got back from vacation today.

joeyhage commented 2 weeks ago

Tested and published a new version, v2.1.5. I tested the prior and new user agents side by side: the prior user agent resulted in the too many requests error, the new user agent worked seamlessly. Please let me know if this didn’t resolve your issue, otherwise I will assume this has been fixed.

ErikAbele commented 2 weeks ago

Just updated to 2.1.5 and can confirm that the 429 errors are gone. Thank you, Joey!

SheldorSheldonDZ commented 2 weeks ago

Same for me. Everything fine - thank you!

fmottaz commented 2 weeks ago

Works fine by me, thanks for the fix.Envoyé de mon iPadLe 16 juin 2024 à 21:39, Joey Hage @.***> a écrit : Tested and published a new version, v2.1.5. I tested the prior and new user agents side by side: the prior user agent resulted in the too many requests error, the new user agent worked seamlessly. Please let me know if this didn’t resolve your issue, otherwise I will assume this has been fixed.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

mbpetrillo commented 2 weeks ago

Hi Joey, thanks for the fix. I updated to 2.1.5 and the too many requests error went away. A new one popped up saying “after initialization http error.”

My devices are from the smart life through Alexa. Kind of like this issue here: https://github.com/joeyhage/homebridge-alexa-smarthome/issues/121

Is there any troubleshooting steps you suggest with this to get them working again?

joeyhage commented 2 weeks ago

Hi Joey, thanks for the fix. I updated to 2.1.5 and the too many requests error went away. A new one popped up saying “after initialization http error.” …

@mbpetrillo I would recommend using the @0x5e/homebridge-tuya-platform plugin for those devices. That’s what I use and it works great.

mbpetrillo commented 2 weeks ago

Thanks for the help!

jmantheitguy commented 1 week ago

@joeyhage I'm still getting these errors on version 2.1.5. I have double confirmed I'm on the latest version. Any ideas on how to fix it?

[6/25/2024, 3:22:06 AM] [homebridge-alexa-smarthome] Alexa-Remote: rate exceeded response ... Retrying once in 48225ms [6/25/2024, 3:22:06 AM] [homebridge-alexa-smarthome] Alexa-Remote: rate exceeded response ... Retrying once in 41445ms

[6/25/2024, 3:22:55 AM] [homebridge-alexa-smarthome] BEGIN capabilities for all devices: { "message": "Too many requests. Try again in some time." } END capabilities for all devices [6/25/2024, 3:22:55 AM] [homebridge-alexa-smarthome] After initialization - RequestUnsuccessful(Error getting smart home device state(s). Response: { "message": "Too many requests. Try again in some time." })

grzech1991 commented 1 week ago

try change time from 30s to 40s

jmantheitguy commented 1 week ago

Just tried it. Still getting the same error.

jlupini commented 1 week ago

I'm also getting the same error - seemingly regardless of the cache lifetime setting

ErikAbele commented 1 week ago

@jlupini @jmantheitguy Just checked here and it works flawlessly for me. We would need to debug again to find out if there's some edge case where the user-agent is set a second time. Maybe you can simply grep the codebase for something like 'AlexaRemote' or 'UserAgent' and see if something pops up. Hope that helps.

grzech1991 commented 1 week ago

i have this same problem, air conditionier not working

[6/27/2024, 10:18:49 AM] [homebridge-alexa-smarthome] Restarting child bridge... [6/27/2024, 10:18:49 AM] Got SIGTERM, shutting down child bridge process... [6/27/2024, 10:18:50 AM] [homebridge-alexa-smarthome] Restored existing accessory from cache: Klimatyzator [6/27/2024, 10:18:54 AM] [homebridge-alexa-smarthome] Child bridge process ended [6/27/2024, 10:18:54 AM] [homebridge-alexa-smarthome] Process Ended. Code: 143, Signal: null [6/27/2024, 10:19:01 AM] [homebridge-alexa-smarthome] Restarting Process... [6/27/2024, 10:19:01 AM] [homebridge-alexa-smarthome] Launched child bridge with PID 9236 [6/27/2024, 10:19:02 AM] Registering platform 'homebridge-alexa-smarthome.HomebridgeAlexaSmartHome' [6/27/2024, 10:19:02 AM] [homebridge-alexa-smarthome] Loaded homebridge-alexa-smarthome v2.1.5 child bridge successfully [6/27/2024, 10:19:02 AM] Loaded 1 cached accessories from cachedAccessories.0E386473685B. [6/27/2024, 10:19:02 AM] [homebridge-alexa-smarthome] Loading accessory from cache: Klimatyzator [6/27/2024, 10:19:02 AM] Homebridge v1.8.3 (HAP v0.12.2) (homebridge-alexa-smarthome) is running on port 47092. Failed to create listener for avahi-daemon server state. The system will not be notified about restarts of avahi-daemon and will therefore stay undiscoverable in those instances. Error message: Error: No such interface found WARNING couldn't map socket coming from remote address ::ffff:169.254.118.74:52418 at local address ::ffff:169.254.118.74 to a interface! [6/27/2024, 10:20:01 AM] [homebridge-alexa-smarthome] After initialization - RequestUnsuccessful(Error getting smart home device state(s). Response: { "message": "Too many requests. Try again in some time." })

jonahgcarpenter commented 2 days ago

I'm also getting the same error - seemingly regardless of the cache lifetime setting

same