CO2Signal component exceeding API limit


#1

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?


#2

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


#3

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!


#4

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