CO2Signal component exceeding API limit

New CO2Signal component is exceeding the API limit all the time. My log is completely flooded with this error message:

2019-02-10 14:50:41 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.co2_intensity_x_y fails Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state await self.async_device_update() File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update await self.hass.async_add_executor_job(self.update) File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/co2signal.py", line 111, in update latitude=self._latitude, longitude=self._longitude) File "/usr/local/lib/python3.6/site-packages/CO2Signal/__init__.py", line 15, in get_latest_carbon_intensity latest_data = get_latest(token, country_code, latitude, longitude) File "/usr/local/lib/python3.6/site-packages/CO2Signal/co2signal.py", line 48, in get_latest longitude = longitude, wait = False) File "/usr/local/lib/python3.6/site-packages/CO2Signal/co2signal.py", line 50, in get_latest raise ValueError("API rate limit exceeded. Please wait a few seconds before retrying the request.") ValueError: API rate limit exceeded. Please wait a few seconds before retrying the request.

Is there a way to limit API calls?

I ran into this as well. On Github there is a refresh_rate parameter mentioned:

sensor:
  - platform: co2signal
    token: SECRET # get yours for free (for personal use) from co2signal.org
    country_code: BE
    refresh_rate: 15 # minutes between polling

To be sure I added a scan_interval as well and for now everything seems to be working:

##############
# C02 Signal #
##############
- platform: co2signal
  token: !secret co2signal_api_key
  refresh_rate: 15 # minutes between polling
  scan_interval: 900

Hope this helps

1 Like

Perfect, Geoffrey! Thanks a lot!

The 15 minute interval is acutally the one used by www.electricitymap.org. This should be added to the component documentation.

edit:
Tried with and without the “scan_interval: 900” setting - it has to be added, otherwise I get the same error message!

I have added a PR for the documentation, to avoid problems with the rate limit in the future.

https://github.com/home-assistant/home-assistant.io/pull/8519

HTH,

Passie

1 Like

This not working in 0.104.1

I get this error:

2020-01-17 10:50:23 ERROR (MainThread) [homeassistant.components.sensor] co2signal: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 299, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/co2signal/sensor.py", line 110, in update
    self._token, latitude=self._latitude, longitude=self._longitude
  File "/usr/local/lib/python3.7/site-packages/CO2Signal/__init__.py", line 15, in get_latest_carbon_intensity
    latest_data = get_latest(token, country_code, latitude, longitude)
  File "/usr/local/lib/python3.7/site-packages/CO2Signal/co2signal.py", line 48, in get_latest
    longitude = longitude, wait = False)
  File "/usr/local/lib/python3.7/site-packages/CO2Signal/co2signal.py", line 50, in get_latest
    raise ValueError("API rate limit exceeded. Please wait a few seconds before retrying the request.")
ValueError: API rate limit exceeded. Please wait a few seconds before retrying the request.

I too have a problem with exceeded refresh rate. More specifically, it appears when I reboot HA. The workaround for me is to reboot HA a random amount of times and wait a random amount of time inbetween. Sooner or later HA boots without the error of the rate being exceeded.

I tried:

  • Adding the attribute refresh_rate, but it’s not accepted by HA.
  • Adding the attribute scan_interval: 900. It’s accepted by HA, but does not seem to solve the problem. I need to give it a few days to be sure, but not very promising that it’s not a documented attribute https://www.home-assistant.io/integrations/co2signal/

same problem here. refresh_rate is not accepted as it output
Invalid config for [sensor.co2signal]: [refresh_rate] is an invalid option for [sensor.co2signal]. Check: sensor.co2signal->refresh_rate. (See ?, line ?).
and scan_interval seems unrelated

As a side note, I’m having an issue with too many API calls without having any decent way of controlling the update frequency, but for a completely different use case: Customized Meteogram

I have the same problem as you and the same way to “fix it”… did it work for you to add the scan_interval parameter ?

Update: I’ve been running with scan_interval: 900 for over two weeks now, with a few reboots, and have not had the problem with exceeded refresh rate a single time! :slight_smile: There’s of course the risk that i’m just lucky, or that some other factor has changed that I’m not aware of, but right now it looks to be the solution.
@Thomas_Jacquinot - I suggest you too try it out and report result back to us all.

I have it running with scan_interval: 900 too now. It seems to be more stable that way, a few restart during the last days did not raise any problem. Would be great if this parameter was described in the documentation.

Hi, I can’t obtain a token for CO2 configuration. In the url I don’t see any link to obtain. I have signed out but I only have an email with confirmation but not any token. Who can help me? Thanks

If you sign up for the beta (https://co2signal.com/), you should receive a personal API token. Otherwise, I would get in touch with them via email, check https://docs.co2signal.com/.

have you idea for this error?

image

Did you sign up for a free API token? You also need to enter your location, check for example electricityMap | Live CO₂ emissions of electricity consumption for zone “IT-NO”. Otherwise, the API seem to be off quite often. Give it some tries.