core: Error fetching co2signal data

The problem

Every hour, I’m getting an Error fetching co2signal data in my logs. However, data seems to populate, except once an hour when the call fails.

image

What is version of Home Assistant Core has the issue?

core-2021.8.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

co2signal

Link to integration documentation on our website

https://www.home-assistant.io/integrations/co2signal/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-08-04 16:18:49 ERROR (SyncWorker_7) [homeassistant.components.co2signal] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/co2signal/__init__.py", line 119, in get_data
    data = CO2Signal.get_latest(
  File "/usr/local/lib/python3.9/site-packages/CO2Signal/co2signal.py", line 34, in get_latest
    latest_data = (requests
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
--- snip ---
2021-08-04 17:18:49 ERROR (SyncWorker_1) [homeassistant.components.co2signal] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/co2signal/__init__.py", line 119, in get_data
    data = CO2Signal.get_latest(
  File "/usr/local/lib/python3.9/site-packages/CO2Signal/co2signal.py", line 34, in get_latest
    latest_data = (requests
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2021-08-04 17:18:49 ERROR (MainThread) [homeassistant.components.co2signal] Error fetching co2signal data:

Additional information

Since this is configured from the new energy component, I’m not sure how to gather more information to help, sorry.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 32 (7 by maintainers)

Most upvoted comments

Hi! Product Manager at electricityMap (and CO2 signal) here.

We’re currently experiencing a large influx of CO2signal beta-users, which has interfered with the activation of new tokens and the performance of the API. We’re currently investigating this issue - I’ll make an update on this issue when we know more!

Hello again,

We believe we have a fix now.

It seems that the root issue was the memory, so we’ve tried to increase it quite a bit, and currently, the checks are looking promising. Let’s hope this resolves it!

Hi all,

Thanks for highlighting some of these issues. We are aware that they are issues with the CO2 Signal API especially in terms of error handling and the overall UX of the service. I’m seeing a lot of issues due to using lat/lon and not being able to find the right country codes. Several users have also reached out to us regarding this, and have unfortunately spent a long time on setup even though we do not have data for the zone yet.

I’m wondering whether we should open a new issue around potentially adding functionality into home assistant to test whether there is actually real-time data for the zone the user is trying to get data from? That way we’ll be able to potentially save a lot of people from troubleshooting. I’d be happy to help however I can.

In the short term, for the people in this thread, and I am not quite sure how this integration is set up, I think the easiest solution is to find the relevant country codes by looking at our live map on electricitymap.org in case the lat/lon is having issues.

Specifically for the US, as I see a lot of comments about that. We do have data for all of the US, but most of the data is delayed by up to 24 hours which does indeed mean that the CO2 Signal API won’t work for most of the grids colored grey. Unfortunately, there’s not much for us to do except hope that the data providers will allow for real-time data in the future.

The team is really excited about your interest in the API. We’re a fairly small team and are not able to dedicate as much time as we want to on this, but hopefully, we can integrate some of the feedback we’ve received to make it a bit more stable and easier to use.

Same here, new setup of the integration -> unexpected error

I just got my API key and tried to set up the co2 sensor myself. I am getting Unexpected error on the config flow dialogue. I get this error when the Use home location option is selected.

When i take a look at the logs, I see this as the culprit:

file "/usr/src/homeassistant/homeassistant/components/co2signal/sensor.py", line 127, in state
return round(self.coordinator.data["data"][self._description.key], 2) # type: ignore[misc]
TypeError: type NoneType doesn't define __round__ method

This is a distinct/different stack trace from the one @andriej posted. I am more than happy to open a new issue if it turns out that the two stack traces are not related.

EDIT I tried again with manually supplying the lat/lon and got a different error:

2021-08-04 20:16:55 ERROR (SyncWorker_2) [homeassistant.components.co2signal] Unexpected exception
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/co2signal/__init__.py", line 119, in get_data
data = CO2Signal.get_latest(
File "/usr/local/lib/python3.9/site-packages/CO2Signal/co2signal.py", line 34, in get_latest
latest_data = (requests
File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.9/site-packages/simplejson/__init__.py", line 525, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 370, in decode
obj, end = self.raw_decode(s)
File "/usr/local/lib/python3.9/site-packages/simplejson/decoder.py", line 400, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Which seemed suspicious… so i tried do do things manually:

❯ curl -H 'auth-token: 9<...>d' "https://api.co2signal.com/v1/latest?lon=35.....&lat=-120....."
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.15.3</center>
</body>
</html>

So they may be having some issues w/ their API endpoint

That did the trick for me. Instead of using my home location i used a country code and it worked

On Fri, Aug 6, 2021, 23:27 Simone Chemelli @.***> wrote:

Since the US is not exactly small, it’ll be nice when we can be a little more specific on our locations

Here the list of available zones: http://api.electricitymap.org/v3/zones

Simone

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/53982#issuecomment-894613176, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFS346YLQPHPVBMFRJATZTT3TG6HANCNFSM5BRUHUIA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Since the US is not exactly small, it’ll be nice when we can be a little more specific on our locations

Here the list of available zones: http://api.electricitymap.org/v3/zones

Simone

Thanks for confirming, @Kongkille . I suspected that the HA launch would be the ‘hug of death’.

I am still not able to add the integration successfully, though. I’ll try again in a few days.

It looks like two things need to happen:

  • the co2 signal API needs some fortification; loads of good SREs on the market right now 😃
  • this integration needs a lot more work on failure handling. At a minimum, “unknown error” messages should not propagate to the front end if the error is known; the API didn’t return 200/OK and valid JSON. Ideally, some basic failure / exponential back off logic would also be a very good idea. Show the sensor as ‘unavailable’ in the frontend and keep checking periodically to see if the API is back up or not.

For me it’s back online since a couple of minutes 👍