WAQI Stopped Working

The WAQI sensor on my Home Assistance instance (originally 2021.01 and now updated to 2021.03.4) has stopped working.

The log shows

2021-04-01 15:04:01 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform waqi is taking over 10 seconds.
2021-04-01 15:04:01 ERROR (MainThread) [homeassistant.components.waqi.sensor] Failed to connect to WAQI servers
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/waqiasync/__init__.py", line 47, in _get
    resp = yield from self._session.get(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
    return await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/waqi/sensor.py", line 73, in async_setup_platform
    stations = await client.search(location_name)
  File "/usr/local/lib/python3.8/site-packages/waqiasync/__init__.py", line 32, in search
    return (yield from self._get(SEARCH_URL, keyword=keyword))
  File "/usr/local/lib/python3.8/site-packages/waqiasync/__init__.py", line 49, in _get
    return (yield from resp.json())['data']
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 45, in __exit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2021-04-01 15:04:01 WARNING (MainThread) [homeassistant.components.sensor] Platform waqi not ready yet. Retrying in 30 seconds.

Looking at the code https://github.com/andrey-git/waqi-async/blob/4f3c5098fbba9fbad857958185886c1bd04d2373/waqiasync/init.py I can see it’s using the endpoint ‘https://api.waqi.info/’ so the standard WAQI API and therefore https://api.waqi.info/feed/nottingham/?token=MYTOKEN

Looking at the API Documentation shows it should be calling the following URL. Run it in POSTMAN, all good. Login into the Hass.io box,

$ curl "https://api.waqi.info/feed/nottingham/?token=MYTOKEN
{"status":"ok","data":{"aqi":55,"idx":3200,"attributions":[{"url":"http://uk-air.defra.gov.uk/","name":"UK-AIR, air quality information resource - Defra, UK","logo":"UK-Department-for-environment-food-and-rural-affairs.png"},{"url":"https://waqi.info/","name":"World Air Quality Index Project"}],"city":{"geo":[52.95473,-1.146447],"name":"Nottingham Centre, United Kingdom","url":"https://aqicn.org/city/united-kingdom/nottingham-centre"},"dominentpol":"pm25","iaqi":{"h":{"v":73.6},"no2":{"v":6.4},"o3":{"v":26.2},"p":{"v":1016.3},"pm10":{"v":27},"pm25":{"v":55},"so2":{"v":2.1},"t":{"v":8.8},"w":{"v":3.2},"wg":{"v":8.8}},"time":{"s":"2021-04-01 13:00:00","tz":"+01:00","v":1617282000,"iso":"2021-04-01T13:00:00+01:00"},"forecast":{"daily":{"o3":[{"avg":34,"day":"2021-04-01","max":39,"min":21},{"avg":33,"day":"2021-04-02","max":38,"min":27},{"avg":32,"day":"2021-04-03","max":37,"min":26},{"avg":29,"day":"2021-04-04","max":40,"min":17},{"avg":36,"day":"2021-04-05","max":36,"min":34}],"pm10":[{"avg":9,"day":"2021-04-01","max":41,"min":7},{"avg":8,"day":"2021-04-02","max":12,"min":6},{"avg":10,"day":"2021-04-03","max":11,"min":8},{"avg":13,"day":"2021-04-04","max":18,"min":7},{"avg":7,"day":"2021-04-05","max":7,"min":6}],"pm25":[{"avg":23,"day":"2021-04-01","max":104,"min":17},{"avg":24,"day":"2021-04-02","max":32,"min":17},{"avg":25,"day":"2021-04-03","max":29,"min":21},{"avg":41,"day":"2021-04-04","max":56,"min":20},{"avg":25,"day":"2021-04-05","max":25,"min":13}],"uvi":[{"avg":0,"day":"2021-04-01","max":2,"min":0},{"avg":0,"day":"2021-04-02","max":3,"min":0},{"avg":0,"day":"2021-04-03","max":2,"min":0},{"avg":0,"day":"2021-04-04","max":3,"min":0},{"avg":0,"day":"2021-04-05","max":3,"min":0},{"avg":0,"day":"2021-04-06","max":0,"min":0}]}},"debug":{"sync":"2021-04-01T22:45:50+09:00"}}}

Hmm, odd - why won’t doesn’t it want to play ball? OKAY, let’s just create a REST sensor to that URL

  - platform: rest
    name: WAQI REST
    resource: https://api.waqi.info/feed/nottingham/?token=MYTOKEN
    value_template: '{{ value_json.data.aqi }}'

drat

2021-04-01 15:25:49 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://api.waqi.info/feed/nottingham/?token=MYTOKEN failed with 

(no further text after the “with”)

Anyone have any ideas on how I could fix this / debug this further?

Mine has decided to stop working as well. I have the exact same error in the log.

I haven’t been able to work it out either.

1 Like

created issue on github:

just as a FYI, all of my Waqi sensors are alive. So it wont be a generic issue.

this was on 2021.3.4, and now on 2021.4.0b4

Interestingly I can confirm the same.
Opening URL with chrome:
https://api.waqi.info/feed/nottingham/?token=MYTOKEN
results with result:
{"status":"ok","data":{"aqi":27....

Same with rest sensor:
Logger: homeassistant.components.rest.data
Source: components/rest/data.py:67
Integration: RESTful (documentation, issues)
First occurred: 3:22:35 PM (1 occurrences)
Last logged: 3:22:35 PM

Error fetching data: https://api.waqi.info/feed/nottingham/?token=MYTOKEN failed with

My sensor started working about 4 hours ago. Not sure what changed. I updated HA to 2021.4.2 about 9 hours ago.

I’m not sure if this is the same cause that other people are seeing, but the IPv6 address for api.waqi.info does not seem to be responding for me. I tried from a couple different places, so it’s not just my connectivity.
I’m guessing that waqiasync doesn’t retry the next address if the first address fails, so it just throws an error. When I test with curl, it quickly times out on the IPv6 and succeeds with the IPv4 address.

1 Like

mine has stopped working again…

Hmm, looks like that’s my issue too.

pi@arrows:~ $ curl --verbose https://api.waqi.info/feed/nottingham/?token=MYTOKEN
*   Trying 2400:8902::f03c:91ff:fee0:ca3...
* TCP_NODELAY set
*   Trying 139.162.71.178...
* TCP_NODELAY set
* Connected to api.waqi.info (139.162.71.178) port 443 (#0)

Even more explicit error message from a machine running in EU-WEST-1 on AWS

ubuntu@euwest1sandbox:~s$ curl --verbose https://api.waqi.info/feed/nottingham/?token=MYTOKEN
* Hostname was NOT found in DNS cache
*   Trying 139.162.71.178...
*   Trying 2400:8902::f03c:91ff:fee0:ca3...
* Immediate connect fail for 2400:8902::f03c:91ff:fee0:ca3: Network is unreachable
* Connected to api.waqi.info (139.162.71.178) port 443 (#0)

Thinking about it, around a week before I noticed it had stopped working I’d setup IPv6 at home too

I ended up just switching to the AirNow integration: AirNow - Home Assistant

Obviously this isn’t going to be useful advice for anyone outside of North America, they appear to have useful data for the US, Canada, and into some parts of Mexico.

The issue is ultimately that WAQI’s DNS configuration is incorrect. I sent them a friendly email in the hopes that they might fix it, but the number of warning labels all over the contact page implied they’re pretty busy and a small team.

1 Like

It looks like at some point the v6 address started working again, the addon for waqi is working for me without modification.

Can you see you yaml? I cant configure it correctly.
Thanks

Thanks for this. I couldn’t really get WAQI working and AirNow was dead simple to setup and get what I was looking for.