home-assistant/core

Withings requires reconfiguration again and agai

Closed this issue · 74 comments

The problem

Ever since the updates a couple of weeks ago, after a restart of HA, one or two Withings profiles require reconfiguration. (I have 4 family members linked to the developer account that are using the same devices such as a scale and a blood pressure monitor). When I reconfigure, I get a dialog with no text in it, and that profile works again for a while. But at the next reboot, usually some other family member needs reconfiguration.

What version of Home Assistant Core has the issue?

2023.10.5

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

Withings

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No withings related exceptions or messages in the logs

Additional information

No response

Hey there @joostlek, mind taking a look at this issue as it has been labeled with an integration (withings) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of withings can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign withings Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


withings documentation
withings source
(message by IssueLinks)

True, same here... I am already thinking about deinstalling the integration.

How often do you get new measurements? So to speak, how often do you stand on the scale etc? Does this happen with every family member? Only specifics members?

I only linked my account so far. I stand on the scale once per day... But it is not about the values, the integration requires a new login / confirmation every few weeks or days...

I know that the values aren't relevant, but in 2023.10 we only refresh the token when we want new data from Withings. So if you only stand on the scale once per month, your token might expire and cause this issue.

@Villa-Buenavista do you only have one account setup? Do you use your Withings application credentials on something else? Or have a second HA instance?

I don't stand on the scale every day - that varies, same with blood pressure. But two family members also have a sleep mat, which has new data every day. It is not specific to any member of the household. All come by in seemingly random order every once in a while, always after a restart.

I had this before with the Withings integration, I think a year ago or so. I think it got resolved when the new OAuth method was introduced. From then it worked without a hitch ever since, until the integration was changed recently.

We're not talking months between reconfigure either, sometimes it is a couple of days. Between four people, I need to reconfigure something a couple of times a week it seems. Sometimes it is just a day inbetween, sometimes it works for longer.

(by the way this is a followup on the other issue with translation errors, where I mentioned it and said I would monitor the situation. I just had not got around to reporting that the problem persisited).

Right, can you maybe try revoking your client secret in the Withings developers dashboard and try reinstalling it via that way? I think it might involve that Withings is revoking tokens for some reason

I did that when the problem surfaced. I think I even mentioned it in the other issue. I removed all 4 profiles from HA, generated a new secret and installed all four fresh. but that didn't help then. If there's a chance now would be different I will do it again, but it is a bit of a hassle having to enable/disable all entities I want per profile all over again.

This is the other issue:
#101415 (comment)

The tokens work until a reboot, could it be the tokens get stored with the wrong user or something like that?

So let me tell you a bit how Withings tokens work.

If you login on device 1 with user X with credentials Y, you get a token. If you login on device 2 with user X with credentials Y, the first token is revoked.

As far as I know, this is based on the combination user with credentials. So I am now suspecting 2 things:

  1. This whole token song and dance has issues with this combination
  2. Withings doesn't like the fact that we are requesting 4 tokens at almost the same time at boot. (Maybe try disabling 1/2 entries and reboot, does that work?)

Do you see any stuff in the logs? Maybe there is some useful Oauth logging at boot with some debug log enabled, I'll have a look if I can find which package to do.

Right before I posted I had one user needing authentication again, then I had no Withings related entries in the logs. But I had the level set to error, so I just commented that out and restarted twice. But of course Murphy's law applies: now all users are fine and there is nothing about Withings in the logs. I'll have to wait until one starts complaining again, and/or you have a log level I need to rise.

try homeassistant.helpers.config_entry_oauth2_flow on debug

Again noneed for reinitialisation this time and nothing worth mentioning in the logs, in fact nothing to do with oauth so I'm wondering I put the right thing in configuration.yaml:

logger:
  logs:
    homeassistant.helpers.config_entry_oauth2_flow: debug

I mean I am expecting something in the logs whenever an entry needs reauth.

This could also lead to the fact that the tokens really need to expire before this happens, so not sure how that works exactly

Just had a reboot and one user needed reconfiguring. In the logfile, the only line there regarding Withings is:

2023-10-29 14:55:45.547 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Fleur' for withings integration could not authenticate: Error code 401.

The previous logfile showed this (some nicely separated token requests, then suddenly 8 close to another (2x the number of users) followed by stacktraces:

2023-10-28 09:35:19.125 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 02:12:35.114 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 02:19:19.302 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 07:14:19.712 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 08:09:18.602 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 14:53:49.132 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.133 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.135 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.147 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.242 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.248 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.251 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
2023-10-29 14:53:49.255 DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Sending token request to https://wbsapi.withings.net/v2/oauth2
...
2023-10-29 14:53:54.477 ERROR (MainThread) [homeassistant.util.logging] Exception in manage_cloudhook when dispatching 'CLOUD_CONNECTION_STATE': (<CloudConnectionState.CLOUD_DISCONNECTED: 'cloud_disconnected'>,)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 184, in manage_cloudhook
    await unregister_webhook(None)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 142, in unregister_webhook
    await async_unsubscribe_webhooks(client)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 252, in async_unsubscribe_webhooks
    await client.async_notify_revoke(
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 170, in async_notify_revoke
    await self._do_retry(call_super)
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 87, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 76, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 166, in call_super
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 332, in notify_revoke
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 828, in response_body_or_raise
    raise AuthFailedException(status=status)
withings_api.common.AuthFailedException: Error code 401
...
2023-10-29 14:53:55.159 ERROR (MainThread) [homeassistant.util.logging] Exception in manage_cloudhook when dispatching 'CLOUD_CONNECTION_STATE': (<CloudConnectionState.CLOUD_DISCONNECTED: 'cloud_disconnected'>,)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 184, in manage_cloudhook
    await unregister_webhook(None)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 142, in unregister_webhook
    await async_unsubscribe_webhooks(client)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 252, in async_unsubscribe_webhooks
    await client.async_notify_revoke(
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 170, in async_notify_revoke
    await self._do_retry(call_super)
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 87, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 76, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 166, in call_super
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 332, in notify_revoke
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 830, in response_body_or_raise
    raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 380

2023-10-29 14:53:55.196 ERROR (MainThread) [homeassistant.util.logging] Exception in manage_cloudhook when dispatching 'CLOUD_CONNECTION_STATE': (<CloudConnectionState.CLOUD_DISCONNECTED: 'cloud_disconnected'>,)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 184, in manage_cloudhook
    await unregister_webhook(None)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 142, in unregister_webhook
    await async_unsubscribe_webhooks(client)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 252, in async_unsubscribe_webhooks
    await client.async_notify_revoke(
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 170, in async_notify_revoke
    await self._do_retry(call_super)
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 87, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 76, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 166, in call_super
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 332, in notify_revoke
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 830, in response_body_or_raise
    raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 380

2023-10-29 14:53:59.147 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 142, in unregister_webhook
    await async_unsubscribe_webhooks(client)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 252, in async_unsubscribe_webhooks
    await client.async_notify_revoke(
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 170, in async_notify_revoke
    await self._do_retry(call_super)
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 87, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 76, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 166, in call_super
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 332, in notify_revoke
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 830, in response_body_or_raise
    raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 380
2023-10-29 14:53:59.158 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 142, in unregister_webhook
    await async_unsubscribe_webhooks(client)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 240, in async_unsubscribe_webhooks
    current_webhooks = await client.async_notify_list()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 143, in async_notify_list
    return await self._do_retry(call_super)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 87, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 76, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/api.py", line 141, in call_super
    return await self._hass.async_add_executor_job(self.notify_list, appli)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 315, in notify_list
    return NotifyListResponse(**self.request(path=self.PATH_NOTIFY, params=params))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 828, in response_body_or_raise
    raise AuthFailedException(status=status)
withings_api.common.AuthFailedException: Error code 401

Right, my suggestion is to wait till Wednesday, with 2023.11 I know for sure I get the error message in the logs

I have the same error
The version is 2023.11.0b3 with a withings body cardio.
To solve the error I have removed the withings integration and then readded it.
Now I have only 2 entities: weight and the hidden height.
I have been weighing myself for the last 3 days, so there should be more entities like: fat %, heart rate, PWV.
Also the weight entity shows 84.00 kg but the display of the scale and the withings app shows 83.1 kg.
Another (translating) error, the height of a person should not translate to german "Höhe" but to "Größe".

"integration_manifest": { "domain": "withings", "name": "Withings", "after_dependencies": [ "cloud" ], "codeowners": [ "@joostlek" ], "config_flow": true, "dependencies": [ "application_credentials", "http", "webhook" ], "documentation": "https://www.home-assistant.io/integrations/withings", "iot_class": "cloud_push", "loggers": [ "aiowithings" ], "quality_scale": "platinum", "requirements": [ "aiowithings==1.0.2" ], "is_built_in": true }, "data": { "has_valid_external_webhook_url": false, "has_cloudhooks": false, "webhooks_connected": false, "received_measurements": [ 1, 4 ], "received_sleep_data": false, "received_workout_data": false, "received_activity_data": false }

@NorbertHD : Happy to hear that adding the integration anew (sort of) worked for you as far as account renewal goes. I'll wait till I installed the 2023.11 release and try to do that again too.

But up until now for me it works for a while, and then I need to reconfigure. Across four users I think I did that about a dozen times the last three weeks, right after I added them all from scratch. How long was it since you added the integration again?

@NorbertHD, in your case, the integration only received 2 measurement types from withings in the last 2 weeks. If you think this is wrong, please open a new issue. My suspicion is the fact that or the integration doesn't handle the user well (as in, when someone else stands on the scale, the value is still registered, but as a "can't link to a user") or Withings has a skill issue.

For the translation error, it should be fixed in Lokalise (but you can do that yourself if you want)

@EDelsman After a few hours the reconfiguration message is back.
I will remove this integration for the time being.

If possible I would like some debug logs :)

If possible I would like some debug logs :)

Sure, tell me what to do.

Like, what I am expecting is that this error will be back in a few hours like you said. So if you can reauth, then turn on debug logging in the integration page. Then we have to wait till it happens again

Okay, I'll do.

After 3 hours the error occurred:

2023-10-31 17:43:20.252 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.129 seconds (success: True)
2023-10-31 17:43:20.254 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.267 seconds (success: True)
2023-10-31 17:43:20.465 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.227 seconds (success: True)
2023-10-31 17:43:20.548 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.153 seconds (success: True)
...
2023-10-31 17:53:20.217 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.230 seconds (success: True)
2023-10-31 17:53:20.270 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.147 seconds (success: True)
2023-10-31 17:53:20.409 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.171 seconds (success: True)
2023-10-31 17:53:20.493 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.098 seconds (success: True)
...
2023-10-31 18:03:20.158 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.172 seconds (success: True)
2023-10-31 18:03:20.270 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.147 seconds (success: True)
2023-10-31 18:03:20.402 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.163 seconds (success: True)
2023-10-31 18:03:20.526 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.132 seconds (success: True)
...
2023-10-31 18:13:20.235 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.112 seconds (success: True)
2023-10-31 18:13:20.242 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.257 seconds (success: True)
2023-10-31 18:13:20.400 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.162 seconds (success: True)
2023-10-31 18:13:20.539 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.143 seconds (success: True)
...
2023-10-31 18:23:20.191 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.205 seconds (success: True)
2023-10-31 18:23:20.274 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.150 seconds (success: True)
2023-10-31 18:23:20.393 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.154 seconds (success: True)
2023-10-31 18:23:20.499 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.104 seconds (success: True)
...
2023-10-31 18:33:20.189 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.202 seconds (success: True)
2023-10-31 18:33:20.263 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.139 seconds (success: True)
2023-10-31 18:33:20.401 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.162 seconds (success: True)
2023-10-31 18:33:20.499 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.104 seconds (success: True)
2023-10-31 18:33:20.571 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.175 seconds (success: True)
...
2023-10-31 18:43:20.216 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.229 seconds (success: True)
2023-10-31 18:43:20.282 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.159 seconds (success: True)
2023-10-31 18:43:20.365 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.126 seconds (success: True)
2023-10-31 18:43:20.511 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.116 seconds (success: True)
...
2023-10-31 18:53:20.265 ERROR (MainThread) [homeassistant.components.withings] Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid
2023-10-31 18:53:20.266 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.142 seconds (success: False)
2023-10-31 18:53:20.350 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.364 seconds (success: True)
2023-10-31 18:53:20.396 ERROR (MainThread) [homeassistant.components.withings] Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid
2023-10-31 18:53:20.396 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.157 seconds (success: False)
2023-10-31 18:53:20.478 ERROR (MainThread) [homeassistant.components.withings] Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid
2023-10-31 18:53:20.478 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.082 seconds (success: False)
2023-10-31 19:03:20.202 ERROR (MainThread) [homeassistant.components.withings] Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid
2023-10-31 19:03:20.202 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.216 seconds (success: False)
2023-10-31 19:33:20.570 ERROR (MainThread) [homeassistant.components.withings] Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid
2023-10-31 19:33:20.570 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.176 seconds (success: False)
...

After reauthentication:

2023-10-31 19:38:09.680 INFO (MainThread) [homeassistant.components.withings.config_flow] Successfully authenticated
2023-10-31 19:38:09.803 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.119 seconds (success: True)
2023-10-31 19:38:09.957 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.153 seconds (success: True)
2023-10-31 19:38:10.065 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.108 seconds (success: True)
2023-10-31 19:38:10.164 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.099 seconds (success: True)
2023-10-31 19:38:10.333 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.168 seconds (success: True)
2023-10-31 19:38:10.333 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching Withings data in 0.000 seconds (success: True)
2023-10-31 19:38:11.334 WARNING (MainThread) [homeassistant.components.withings] Webhook not registered - https and port 443 is required to register the webhook

I am also getting this error. I have had it forever. Even before the integration got some much needed love. I only have 2 profiles and I have a lot of withings gear that I use every single day.
It usually happens after home assistant restarts.

refresh_tokens are valid for a year or 8 hours after a new access_token is requested. So this theoretically should not happen?

Unless like you said, withings is invalidating all access and refresh tokens when there is more than one access_token request coming from the same client at the same time? If so, would it be possible to refresh all tokens at different intervals (say 30 minutes between each or so) ?

Right. I am now suspecting another thing and that is that Withings is doing funky with tokens. (They don't completely adhere to the Oauth2 standard).

async def _refresh_token() -> str:
await oauth_session.async_ensure_token_valid()
token = oauth_session.token[CONF_ACCESS_TOKEN]
if TYPE_CHECKING:
assert isinstance(token, str)
return token

The oauth_session currently checks if the token is expired (based on the timestamp and the time the token is alive). If it isn't expired, it will refresh it. This is all handled in Home Assistant itself.

We know this logic works as it works for example for me. I am suspecting that this is because something is off with the time Withings returns as token alive time. (For example, HA might register the expiration date of the token in 5 hours (based on Withings data) and then there will be no new token triggered since its not expired yet (while in reality it is).

The reason behind this is still a question mark.

But now: to debug it. When you're in that state, can you maybe restart HA and check the /config/.storage/core.config_entries file. In that file are all the config entries and their configs (so please DONT post it here). But I am interested in the

            "expires_in": 10800,
            "token_type": "Bearer",
            "expires_at": 1698752223.106977
          },

part of the configuration.

"expires_in": 10800, "token_type": "Bearer", "expires_at": 1698969364.02262, "error": "Same arguments in less than 10 seconds", "wait_seconds": 68 },

I have searched for the error message and found this old issue:
#42717 (comment)

Seems it's a race condition and you have to wait for/after renewal.

I have 2023.11.0 and added the withings integration.
I added profiles, each profile shows up as a device and pulls the data from the selected profile into the entities.
Well actually it only creates them for 2 family members but I believe that is just because the other 2 havent used the scale in a while.

The problem I am seeing is that I have to re-authenticate all 4 "withings" every several hours.
I followed the link to the old issue, and the last post suggests there us a fix in there, but I didn't really understand what to do.

On the youtube release party video for 2023.11 it was mentioned that Withings integration has improved, however I am experiencing this issue with that version.

I am also getting this problem - I have to reconfigure every few hours. I have had a Withings scale for just a week or so, running HA 2023.11. I weigh myself daily. No other users.

@NorbertHD I think that part what you shared might be a good lead on what is happening. My guess is that we do a request pretty close after each other, triggering some kind of rate limit (since the arguments are the same). It returned an error, which we can see in the config entry.

I am guessing they did not send an updated token as well, so after "refreshing" the token (which is "receiving an error message"), HA will use the old token, causing an error.

I am wondering 2 things:

  1. On which level is this happening? Application level or user level? (I am suspecting user level, since @JonLoose also has this problem and has only one account)
  2. When is this error at withings happening? At the start of the application? Or at an update after 3 hours? My current expectation is that this is happening because every 10 minutes, a request is being done to Withings. After 3 hours, all 3 requests try to refresh the token, resulting in 3 requests with the same parameters, and one of them will probably overwrite the result of the one that did succeed, leaving us in this state.

Let me think about a way to verify this and for a possible solution

I have the same problem. Removing it and re-adding the integration doesn't solve it. Every few hours it's wants to be reconfigured, I reauthenticate it and it works for a few more hours and repeats. Did not have an issue on 2023.10.4, however I guess it's possible Withings changed something on their end 11/1. Anyone on an older version not having any problems?

Based on the discussion of token expiration time above I wonder if this could possibly be due to a time zone issue. Maybe one side isn't using zulu for expirations/refreshes? Just a wild guess though, however if any auth code was changed in 11.1 I would definitely be looking there first.

Anyone on an older version not having any problems?

I've had reauth issues with Home Assistant and Withings on and off for a couple of years according to the different GitHub-threads I've subscribed to, but I have no idea if it has been the same or different issues.

I'm having reauth issues too. Every couple of hours. I have two users (via the one account), and once I authorise the first user, the other then needs to be re-authorised. And visa versa.

Well, please create an issue at that repo :D

Oh apparently someone already did, feel free to checkout that issue and see if you can maybe answer the questions

Same issue here on HA 2023.11.1. Withings always ask to reconfigure the integration.

@joostlek I am not a python programmer so I can not verify if the current code has already this logic,
but every 10 minutes there are a couple of data fetches.
These data fetches have to be locked against each other, so that one can not start before the former has completed.
So if one of this calls gets a new access token the next data fetch uses this new token.

The result will be something along those lines. I do have to think of a good way to solve this issue.

tdaime commented

I have the same issue (Need to reconfigure the integration every couple of hours). Two users configured in Withings account, and running 2023.11
Note that I do have a Withing ScanWatch which might generate frequent updates.

How many users do you have set up?

Same here. (Need to reconfigure the integration every couple of hours). Two users set up in the Withings account / body scale. Retrieval of one user only via HA 2023.11.1. No further Withings devices.

tdaime commented

How many users do you have set up?

2 users. I did update my previous comment (sorry ... )

Also experiencing this issue, I have 4 users set up for my scales, and 1 user for my watch

Same issue here

2 accounts set up with 3 people, reauth required every 2 to 5 hours.
Always for all 3 people

seesee commented

I'm also seeing this issue. 1 set of scales, 2 users, running HA in a docker container. The issue seems worse now the clocks have gone back for some reason. Always had to reauthenticate after rebooting/restarting HA, but since restarting on Sunday it's been every few hours (consistent with others). Happy to help investigate/poke around as needed.

I too am seeing this issue. I have 2 bed sensors, both on separate profiles. Seems to be mostly after a restart of HA. I've tried removing absolutely everything and starting from scratch but still no luck.

Logger: homeassistant.config_entries
Source: config_entries.py:426
First occurred: 8:13:58 PM (2 occurrences)
Last logged: 8:13:58 PM

Config entry 'Withings' for withings integration could not authenticate: XRequestID: Not provided invalid_token: The access token provided is invalid

I'm having the same problem. 1 scale, 1 user. HA 2023.11.1.

Logger: homeassistant.components.withings
Source: helpers/update_coordinator.py:343
Integration: Withings (documentation, issues)
First occurred: 7 november 2023 om 21:34:05 (5 occurrences)
Last logged: 02:41:22

Authentication failed while fetching Withings data: XRequestID: Not provided invalid_token: The access token provided is invalid

gNeeUs commented

I am seeing the same issue as @EDelsman is reporting, having the exact same devices registered, but the Reconfiguration request happens also without restarting HA. I use my scale daily, and the integration does not seem to last for much more than a day or two, then prompts for Reconfiguration again. Happy to help troubleshooting.

I have an attempt to fix this issue in #103688. I think my personal instance doesn't have this issue since its using webhooks thus never fetches data at the same time. So if you guys could help test it out!

cd /config
curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d withings -p 103688
seesee commented

I have an attempt to fix this issue in #103688. I think my personal instance doesn't have this issue since its using webhooks thus never fetches data at the same time. So if you guys could help test it out!

cd /config
curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d withings -p 103688

Manually installed your version into my docker instance and re-authorised the app. All looks good at the moment, I'll keep an eye on it and report back.

Thank you very much. I also installed it. Now wait and see...

Curious, just found the origial issue I had in the beginning, is this a similar problem/solution or a new one?
#42717 (comment)

for info, I'm the only one that really uses my scales, well at least for the last few years...and I only pull through weight but I get at least one reconfigure request a day and sometimes multiple...

I have an attempt to fix this issue in #103688. I think my personal instance doesn't have this issue since its using webhooks thus never fetches data at the same time. So if you guys could help test it out!

cd /config
curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d withings -p 103688

Been running it for over 12 hours now and no issues yet, looking good so far.

seesee commented

I can confirm that the patch is also working for me (after about 24 hours of being installed). The re-authentication requests every 3 hours have stopped, and my weight/exercise recordings through the scales and the app are coming through fine. I'll still keep an eye on things, but it's very encouraging. Thanks @joostlek!

Aight, I marked the fix as ready for review. We can expect it to be delivered in 2023.11.3

Have been running for 24 hours including a reboot and all going well. Thank you for your work on this @joostlek.

Oh and don't forget to remove the custom integration when you update to 2023.11.3. (not 2023.11.2 that will probably be released today)

Same issue here with 2023.11.1, tried the patch above.

`
cat home-assistant.log | grep withings

2023-11-10 11:28:59.894 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration withings which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-11-10 11:29:31.121 INFO (MainThread) [homeassistant.setup] Setting up withings
2023-11-10 11:29:31.122 INFO (MainThread) [homeassistant.setup] Setup of domain withings took 0.0 seconds
2023-11-10 11:29:35.293 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.withings
2023-11-10 11:29:35.293 INFO (MainThread) [homeassistant.components.calendar] Setting up calendar.withings
2023-11-10 11:29:35.294 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.withings
2023-11-10 11:29:35.551 WARNING (MainThread) [custom_components.withings] Webhook not registered - https and port 443 is required to register the webhook
`

Reboot done, without problem..

Oh and don't forget to remove the custom integration when you update to 2023.11.3. (not 2023.11.2 that will probably be released today)

For less well versed people like me, can you tell me how to do that?

Euh, so I think yesterday a new update of the terminal addon was released where they changed the config folder to /homeassistant. If you didn't update it should still be /config.

So do cd <one of those two> and then do cd custom_components. And then rm -rf withings

We need to wait 2023.11.3 or the yesterday's update solve the issue?

Thanks

2023.11.3

Still going strong, no issues with the fix. Thanks for all your hard work!

Good to hear :)

Need to delete the folder withings (in custom_components) before update or after?

Confirm that the issue is done?

🙏 thanks

After!

I didn’t check here and thought this was just me, so disabled the integration. Fingers crossed this solves it. Thought I was going mad.

jtommi commented

Oh and don't forget to remove the custom integration when you update to 2023.11.3. (not 2023.11.2 that will probably be released today)

I couldn't find the folder, neither in /homeassistant nor in /config; nevertheless, after updating to 2023.11.3 the Withings integration seems to work fine again

Only if you installed the custom component