core: Netatmo timeout errors during token update

The problem

Before I used configuration.yaml to add my netatmo stations. And everything was ok. Now I used the netatmo integration but in the log I recived a lot of “error”.

Environment

Home Assistant 0.108.5 Path to configuration.yaml: /home/homeassistant/.homeassistant

Developed by a bunch of awesome people.

Published under the Apache 2.0 license Source: server — frontend-ui

Built using Python 3, Polymer, Icons by Google and MaterialDesignIcons.com.

Frontend version: 20200407.2 - latest

  • Home Assistant Core release with the issue: not sure when started. But the problem is for sure in 0.107.7 and later
  • Last working Home Assistant Core release (if known):
  • Operating environment (Home Assistant/Supervised/Docker/venv): I use a raspberry pi 4 in virtual env becouse I use raspberry also for other stuff.
  • Integration causing this issue: netatmo
  • Link to integration documentation on our website:

Problem-relevant configuration.yaml

I use UI on frontend so my configuration.yaml not report netatmo things


Traceback/Error logs

2020-04-11 13:48:39 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.netatmo_netatmo_indoor_temperature fails
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/pyatmo/auth.py", line 129, in query
    rsp = self._oauth.post(url=url, data=params, timeout=timeout)
  File "/srv/homeassistant/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 478, in request
    url, http_method=method, body=data, headers=headers
  File "/srv/homeassistant/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 198, in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired) 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 476, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/netatmo/sensor.py", line 225, in update
    self.netatmo_data.update()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/netatmo/sensor.py", line 550, in update
    self.station_data = self.station_data.__class__(self.auth)
  File "/srv/homeassistant/lib/python3.7/site-packages/pyatmo/weather_station.py", line 24, in __init__
    resp = self.authData.post_request(url=self.urlReq)
  File "/srv/homeassistant/lib/python3.7/site-packages/pyatmo/auth.py", line 143, in post_request
    resp = query(url, params, timeout, 3)
  File "/srv/homeassistant/lib/python3.7/site-packages/pyatmo/auth.py", line 137, in query
    self._oauth.token = self.refresh_tokens()
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/netatmo/api.py", line 32, in refresh_tokens
    self.session.async_ensure_token_valid(), self.hass.loop
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/config_entry_oauth2_flow.py", line 413, in async_ensure_token_valid
    new_token = await self.implementation.async_refresh_token(self.token)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/config_entry_oauth2_flow.py", line 78, in async_refresh_token
    new_token = await self._async_refresh_token(token)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/cloud/account_link.py", line 143, in _async_refresh_token
    self.hass.data[DOMAIN], self.service, token["refresh_token"]
  File "/srv/homeassistant/lib/python3.7/site-packages/hass_nabucasa/account_link.py", line 112, in async_fetch_access_token
    resp.raise_for_status()
  File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 946, in raise_for_status
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 504, message='Gateway Time-out', url='https://account-link.nabucasa.com/refresh_token/netatmo
2020-04-11 13:49:40 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.netatmo_netatmo_indoor_co2 fails
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/pyatmo/auth.py", line 129, in query
    rsp = self._oauth.post(url=url, data=params, timeout=timeout)
  File "/srv/homeassistant/lib/python3.7/site-packages/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/requests_oauthlib/oauth2_session.py", line 478, in request
    url, http_method=method, body=data, headers=headers
  File "/srv/homeassistant/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 198, in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired) 

Additional information

I have only 2 stations (one internal and one external). The data in home assistant are ok. I can use the sensor and everything is ok. (I suppose) The first error that appears on the log file is: [homeassistant.components.netatmo] Error during webhook registration - 400 - Bad request - Allowed ports for webhooks are 443 and 80. (21) when accessing ‘https://api.netatmo.com/api/addwebhook

But I can’t forward the ports 443 an 80 on my router because I already use them for other services on my raspberry (that is the same where is installed homeassistant.)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 50 (21 by maintainers)

Most upvoted comments

Here it stopped for the second time in 6/7 days and the 4/5 time in 3/4 weeks. This is really getting … What is the best thing to do now? Back to the API keys? Nabucasa linked is no options right now…

Got it to work again. Upgraded to 0.108.8 from 0.108.6 and the setup worked flawlessly from the UI. Entities got new names though.

Hi, I understand that the issue is related to Netatmo server load. I see it from time to time for the last months. Is there any other way to refresh the token than restarting Home Assistant and hoping for the best? If not; maybe a way to do it could be described? Could I for example use Postman and get a token and paste it somewhere? Or at least use Postman to verify that the Netatmo service is currently up so there is a fair chance for sucess if I reboot HA? It is a drag to restart Home Assistant 2-5 times just to get a refresh token which may or may not work…

Thanks for all your time spent on supporting this. I know how awfull it fells to support something that is not your fault!

@cgtobi you are correct, now it worked!

ok thanks it’s works with HA… don’t understand Ahah ^^ thanks for helping

The timeout comes from api.netatmo.com. We just forward your token renew requests because the token is all local on your machine. I am was going over the error logs, so it looks like the issue is mostly around 23:00 - 08:00, and NetAtmo Cloud is hosted in NL.

You can use the YAML version and it will work during the day, but I think it ends up in same issue on the night or next night (it is not every night). Let’s hope they fix the issue soon.

@Metus88 What I think you refer to by “the old way” is the configuration of the individual platforms where you’d specify the sensors and devices manually? This has been deprecated a long time ago. If you meant something else then please let me know. The way the Netatmo integration works now (for quite a while) is by auto discovery only. The one error left is irrelevant if you only have a weather station. See comment below.

@myerdacom I don’t understand what exactly you mean by that. How to setup is described here but is not relevant if you only have a weather station.