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?