-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
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
ForecastSolar can't recover when API rate limit is hit #106771
Comments
Hey there @klaasnicolaas, @frenck, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) forecast_solar documentation |
So what is the issue? 🤷🏻 |
As discussed over Discord, it would be great if this error is caught and just prints a single error/line in the log |
Have a same issue after update home assistant to version 2024.1.5. Updated on Saturday 20.1. evening. Since this time the Forecast.Solar integration has an error. |
I have also been running into this error over the past week, I've tried disabling the integration for at least a day and re-enabling it twice and it still encounters this error. I also tried signing up for a trial for the Personal tier license key and adding that to my integration but that didn't work. |
I did some research to get more clarity about where things go wrong and especially how the problem can persist for days. By default, if you make more than 12 requests to the API in an hour, you will get a rate limit error and this can be caused, for example, by many restarts of Home Assistant. But what I noticed is that with a rate limit exception, an error appears in the logs every minute, so it may try to execute a request to the API every minute. As a result, the reset time is always pushed forward (rolling reset time), which puts you in a limbo and the problem does not solve itself after waiting 1 hour and can last for days. |
I'm running into the problem as well, with an anonymous account (so no API Key); from the Code it's quite clear that it should only updaten hourly when no API-Key is set. I believe the problem for me (and maybe for others as well) is, that if the API call fails, then Home Assistant tries to re-initialize the Integration after 1 Minute (or 90 seconds, which I believe is more correct), then receives the same error & after 1 Minute tries again, and again, and again... ...pushing the next possible working call further into the future. It would be probably be best, going full circle with the issue, to not let the Integration go into an erronious state with this error, so that the Integration itself can handle the interval, without being re-initialized all over. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Just stating that "you also have the issue" does not help solve the problem and only pollutes the thread, so please don't do that. If you would like to stay informed, you will find a subscribe button on the right of the sidebar and you will receive notifications 😉 ./Klaas |
I am encountering the same issue. I tried disabling the integration for 12 hours (overnight) to ensure it did not exceed the API call limit. I re-enabled it, and the same issue occurred immediately on the first API call as the integration was starting. |
I've also had the same, I wonder if either failed accesses are counted against you as a tally (e.g. I had this happening for 24+ hours before I noticed, so I would have accumulated 3 * 24 * 40 = 2880 rejected requests, which at 12 calls per IP per hour is going to take 10 days to clear ;-( Equally it could just be a bug in the rate limiting at Forecast.Solar. |
Knut here, possibly it would be a way to check responses with HTTP code 429 for or the headers This should be stored somewhere and checked before next call. The |
https://github.com/home-assistant-libs/forecast_solar/blob/master/forecast_solar/exceptions.py shows that the Looking at https://github.com/home-assistant/core/blob/dev/homeassistant/components/forecast_solar/coordinator.py around line 67, it needs to catch Further looking at https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/update_coordinator.py I can see that there is |
Maybe something like: 4364b17 (totally untested) might work? I've tried but failed to get my local ha to load the revised code as a custom component. Looks like I may need to set up a proper ha dev env to try this (I've only ever made very minor changes to HACS installed custom components before). |
Same here, Logger: homeassistant.components.forecast_solar Unexpected error fetching forecast_solar data: Rate limit for API calls reached. (error 429) Not sure what you need from me to help you solve this. |
I hit the limiting too. Because of the internal integration reloads, it never recovered. I got it back to work:
As already mentioned above you will get details when you are allowed to try next, what are the limits and the current calls which are registered:
Anyway: The RatelimitException (HTTP Codes 429) should not be treated as an integration fault. Maybe just log an unsuccessful call and a hint for old data, but without reloading or restarting a new attempt. For now, this behavior leads to never ending reloads and API limiting. |
An idea to solve this is to adjust the update_interval to a time delta when receiving this exception, which after the reset restores the update_interval to the old situation upon a successful API call. We have already done some testing with this, but ran into some problems with the coordinator and have not yet been able to figure it out / solve it. |
I have ran into the same senario as above, in my case the error was quite quick to resolve.
|
brand new install was working for 25 minutes then I made a single change to the configuration and now I get 429 errors. Point to note I made no reboots throughout so why should I hit the API limit? will block from internet for an hour but that doesn't seem right. |
After I reconnected to the internet, I waited another 1-2 hours (for security reasons) and then changed a few values, that worked |
This is the 'formal' response from forecast.solar
|
I just did a brand new install and was given the same error from the get go, no idea why that would be. I've reinstalled the plugin, waited one hour and still the same issue. |
Try (from desktop or phone etc) this api: https://api.forecast.solar/estimate/watthours/day/52/12/37/0/5.67 It should get you a response message 429 and in the bottom you see something that states the timestamp you should try again. Ensure you do not make any api call until that moment. After that moment, try again via the browser, when you get a response message including forecast numbers, you should be good to go again and can enable the integration again. Everytime you do an API call during your block windows, the block will be extended. |
Same issue here, maybe a fix can be implemented. I think that the problem is related to async def async_config_entry_first_refresh(self) -> None:
"""Refresh data for the first time when a config entry is setup.
Will automatically raise ConfigEntryNotReady if the refresh
fails. Additionally logging is handled by config entry setup
to ensure that multiple retries do not cause log spam.
"""
await self._async_refresh(
log_failures=False, raise_on_auth_failed=True, raise_on_entry_error=True
)
if self.last_update_success:
return
ex = ConfigEntryNotReady()
ex.__cause__ = self.last_exception
raise ex During setup the integration should not retry setup (or delay retry, if possible) if status code 429 is received? Something in the ways of try:
await coordinator.async_config_entry_first_refresh()
except ConfigEntryNotReady as e:
if isinstance(e.__cause__, ForecastSolarRatelimit):
pass # suppress ratelimit exception during setup
else:
raise # raise any other errors @klaasnicolaas i did a quick test branch at my fork: dev...bj00rn:core:fix-rate-limit-error-in-setup Cheers |
This won't fix it, especially for users who have previously set up the integration but simply made too many requests. The problem lies in the updateCoordinator and the function that retrieves the data. ./Klaas |
@klaasnicolaas Are you sure? When i say I think this will actually fix the problem (or at least a critical part of it). Maybe my understanding of how
![]() But maybe I am missing something here? . Is there more to this issue? Suppressing the RateLimitError (all other errors will still be raised, authentication etc) in https://developers.home-assistant.io/docs/config_entries_index/#setting-up-an-entry
|
As I said here, I think (independent of concrete implementation because not familiar with HA) about an abstract logic during integration installation, boot up, normal run mode etc.
Then the integration can work as now, if it runs for days/weeks fine, the (last) "retry at" is (far) before "now" and it runs smoothly :-) |
The problem as I see it is purely related to Home Assistant Once the integration has setup correctly it should be possible to implement logic to observe the response and delay any further requests if rate limit is reached. Any such logic probably won't be necessary though, since even the public still api supports 12 requests/hour per IP. The default delay in the integration is 1h so there should be no major problems with rate limit being hit. The only exceptions I can think of would probably be when you are using a public account and
|
There is another finding on my side. Independent from a Here is one example of calls with an invalid location, results in a Is it possible that not only a At the moment all calls are fully answered to give the requester the change to analyse the response, but in future it could be that such "false" requests are intercepted more generically. |
Looks like a related but separate issue, I think that during the |
Depending on how sophisticated you want the checks to be: |
So to re-cap I see three separate but related issues here with the integration:
|
Not only rate limit, any response code not equal |
Edit: Im beginning to suspect it's probably better to do proper validation in That way the integration always gets created and requests will only occur at the set refresh interval of the integration. Any errors that arise can be handled by the integration from there on. I made a PR to the lib to support validation. |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
The problem
Been rebooting my systems quite some times, and apparently I've been rate-limited by ForecastSolar. Those errors are filling up my log now 😄 Hits about every 90 seconds, it appears.
What version of Home Assistant Core has the issue?
core-2024.1.0b2
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
Forecast Solar
Link to integration documentation on our website
https://www.home-assistant.io/integrations/forecast_solar/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Additional information
No response
The text was updated successfully, but these errors were encountered: