home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.33k stars 30.28k forks source link

Withings webhook not working #72614

Closed Bluhme1 closed 1 year ago

Bluhme1 commented 2 years ago

The problem

After installing Home Assistant Core 2022.6.0b1 I get the following error message

The integrations works well despite og the error message

What version of Home Assistant Core has the issue?

Home Assistant Core 2022.6.0b1

What was the last working version of Home Assistant Core?

Home Assistant Core 2022.5.*

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Withings

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Unexpected error fetching subscription_update_coordinator data: Error code 293
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 191, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 150, in _async_update_data
    return await self.update_method()
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 663, in async_subscribe_webhook
    return await self._do_retry(self._async_subscribe_webhook)
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 659, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 648, in _do_retry
    return await func()
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 705, in _async_subscribe_webhook
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/withings_api/__init__.py", line 348, in notify_subscribe
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.9/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
  File "/usr/local/lib/python3.9/site-packages/withings_api/common.py", line 830, in response_body_or_raise
    raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 293

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

withings documentation withings source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @vangorra, 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! (message by CodeOwnersMention)

mib1185 commented 2 years ago
BobRathke commented 2 years ago

Can confirm this is also happening here after upgrade to b3 from 5.5. I am rolling back.

Flameeyes commented 2 years ago

I have a theory, but I'll need one of you to confirm if that's the case.

With my change, the webhook URL sent to Withings is derived off the public URL that the Home Assistant instance has configured at startup rather than the one when the Withings integration was configured. This means that if you changed the external URL, or for instance signed up for Nabu Casa's remote, it's possible that the URL no longer matches with the one that is configured in the Withings account.

To check whether that the case, compare the Withings callback URL with what is configured (in 2022.5) under Settings → System → Network → Home Assistant URL. If those two don't match, that's why the error is showing up. I guess what we can do in the short term to avoid the error is to try with the newly-generated URL, and if it errors out, fallback to the one stored, and issue a warning instead.

BobRathke commented 2 years ago

I am taking a look now to confirm. I do indeed use Nabu Casa, but believe my URL is consistent across the 2 setups.

BobRathke commented 2 years ago

My configured callback URL matched my external_URL in HA.

image

BobRathke commented 2 years ago

image

Flameeyes commented 2 years ago

Can you enable debug logs for Withings, and see if this log line (https://github.com/home-assistant/core/blob/dev/homeassistant/components/withings/common.py#L697) reports the same webhook? I think the "Callback URL" part needs to actually have the full URL, not just the host (see https://www.home-assistant.io/integrations/withings/), so that configuration in Withings appears wrong to me.

BobRathke commented 2 years ago

I will check, but it is running fine once I rolled back to 2022.5.5.


From: Diego Elio Pettenò @.> Sent: Monday, May 30, 2022 4:18 AM To: home-assistant/core @.> Cc: Bob Rathke @.>; Comment @.> Subject: Re: [home-assistant/core] Withings error message (Issue #72614)

Can you enable debug logs for Withings, and see if this log line (https://github.com/home-assistant/core/blob/dev/homeassistant/components/withings/common.py#L697) reports the same webhook? I think the "Callback URL" part needs to actually have the full URL, not just the host (see https://www.home-assistant.io/integrations/withings/), so that configuration in Withings appears wrong to me.

— Reply to this email directly, view it on GitHubhttps://github.com/home-assistant/core/issues/72614#issuecomment-1140849468, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFYS6KVFGBUHDNITDMOJ7A3VMR2W7ANCNFSM5XEXUK3Q. You are receiving this because you commented.Message ID: @.***>

Flameeyes commented 2 years ago

I will check, but it is running fine once I rolled back to 2022.5.5.

It's possible that it's running fine, but just hiding the webhook failure because very few of the sensors rely on the webhook.

Also if you enable debug logging for withings you should be able to compare the URL used for webooks before and after the update, which might shed some light on what changed for you in particular.

It could be that the generated URL is indeed matching the one you configured on Withings website, but they never exercised the webhook in the first place, which would have otherwise failed (the configured URL there is the base instance URL, not a webhook URL.)

Bluhme1 commented 2 years ago

After some days of use, I can now say that the webhook function has stopped working. I use it for the "in-bed-binary-sensor" so I know for sure that it stopped working at the same time as I installed de first beta

BobRathke commented 2 years ago

Anyone try 2022.6?

stefanroelofs commented 2 years ago

I also cannot setup my Withings integration. The error message in the log:

2022-06-02 09:50:04 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Stefan R. for withings
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 339, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/withings/__init__.py", line 119, in async_setup_entry
    const.CONF_USE_WEBHOOK: hass.data[DOMAIN][const.CONFIG][
KeyError: 'withings'

I'm not 100% sure if this is related to this issue though. Thx.

mrlime commented 2 years ago

Having the same problem and same error messages as those above using 2022.6 and 2022.6.1. I am not using Nabu Casa - I have a local instance with a DNS name.

Prior to the 2022.6 upgrade, the webhooks worked fine.

My Withings developer account says my callback URI is "https://[mydomain]/auth/external/callback." In Home Assistant, under settings -> system -> network -> Home Assistant URL it is "https://[mydomain]."

chadderksen commented 2 years ago

Same here on 2022.6.2. I do use NabuCasa

Prior to the 2022.6 upgrade, the webhooks worked fine.

Unexpected error fetching subscription_update_coordinator data: Error code 293 Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 191, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 150, in _async_update_data return await self.update_method() File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 663, in async_subscribe_webhook return await self._do_retry(self._async_subscribe_webhook) File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 659, in _do_retry raise exception File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 648, in _do_retry return await func() File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 705, in _async_subscribe_webhook await self._hass.async_add_executor_job( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.9/site-packages/withings_api/init.py", line 348, in notify_subscribe self.request(path=self.PATH_NOTIFY, params=params) File "/usr/local/lib/python3.9/site-packages/withings_api/init.py", line 115, in request return response_body_or_raise( File "/usr/local/lib/python3.9/site-packages/withings_api/common.py", line 830, in response_body_or_raise raise InvalidParamsException(status=status) withings_api.common.InvalidParamsException: Error code 293

jarvih commented 2 years ago

This problem is related to #68760 i think.

As both gives a same error. I have had this for long time and never got it working for some reason.

Flameeyes commented 2 years ago

Can someone post the debug logs (without the hostname) and check whether the calculated webhook URL in the log matches the one on the Withings website?

chadderksen commented 2 years ago

I definitely want to do that, if you explain to me how to do this! :-)

GJT commented 2 years ago

Debug shows that it tries to subscribe to my internal url.

2022-06-06 15:19:39 DEBUG (MainThread) [homeassistant.components.withings] Attempt 3 of 3 2022-06-06 15:19:39 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook 2022-06-06 15:19:39 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://ha.localdomain.lan:8123/api/webhook/422b5a3c7ea3fdb3b81a9e1fcc7bfd99044d33c4ad70658c36870b7e30983bf1 for NotifyAppli.WEIGHT in 5.0 seconds 2022-06-06 15:19:44 DEBUG (MainThread) [homeassistant.components.withings] Failed attempt 3 of 3 (Error code 293)

Flameeyes commented 2 years ago

So, it looks like the webhook.async_generate_url() call translates to a get_url(hass, prefer_external=True, allow_cloud=False) call. Unfortunately in this case, the webhook has to be external, and that means it has to allow cloud if that's the only external URL available.

Workaround for now should be to configure explicitly the external URL in Settings→System→Home Assistant URL to use the cloud URL, then re-start Home Assistant.

Bluhme1 commented 2 years ago

Can confirm that the workaround works. Thank you @Flameeyes

Flameeyes commented 2 years ago

I have a possible fix in #73228 but I can't test it as the one setup I have this on does not have Cloud setup for it.

If anyone can help testing that it would be very helpful.

n00bcodr commented 2 years ago

Can confirm the workaround works as well.

@Flameeyes how can I help you test the possible fix in https://github.com/home-assistant/core/pull/73228

ubiquitousgimp commented 2 years ago

@Flameeyes Thanks for the workaround! Can confirm it works. I nuked and re-setup HA yesterday and thought I was going crazy with the Withings integration. I use nabu casa, let me know if I can help testing your fix.

BobRathke commented 2 years ago

Confirming that the external URL workaround solves the problem.

Thanks @Flameeyes

b3nnyk22 commented 2 years ago

I’m having the same error since the recent update. Can someone please explain to a dummy how to do the external url workaround? Haha. Thanks in advance :)

BobRathke commented 2 years ago

Workaround for now should be to configure explicitly the external URL in Settings→System→Home Assistant URL to use the cloud URL, then re-start Home Assistant. Use your NabuCasa or External URL where highlighted.

image

b3nnyk22 commented 2 years ago

Workaround for now should be to configure explicitly the external URL in Settings→System→Home Assistant URL to use the cloud URL, then re-start Home Assistant. Use your NabuCasa or External URL where highlighted.

image

Thank you!!

Flameeyes commented 2 years ago

Sorry folks, I've been a little otherwise occupied so I didn't pay enough attention here.

If you're comfortable with applying this change to your installation, you should be able to apply the diff cleanly on top of any 2022.6.x release, then restarting HA. If you're not comfortable with applying the diff it might not be the best of the ideas, though.

nebriv commented 2 years ago

@Flameeyes Feel better!

I'm more than happy to give it a shot - is there a process for applying a diff patch on HA Supervised? I was trying to work out where the HA core files are so I could make some changes myself to try to fix this but couldn't find them.

ldaume commented 2 years ago

I'm using HA with Docker and the Withings integration works well on 2022.6.6 👍

nebriv commented 2 years ago

I believe this only affects people using Nabu Casa cloud.

nebriv commented 2 years ago

I'm more than happy to give it a shot - is there a process for applying a diff patch on HA Supervised? I was trying to work out where the HA core files are so I could make some changes myself to try to fix this but couldn't find them.

I applied this patch by doing the following:

wget https://patch-diff.githubusercontent.com/raw/home-assistant/core/pull/73228.diff
cp -r /usr/src/homeassistant/homeassistant/components/withings ~/withings_backup
cd /usr/src/homeassistant/homeassistant/components/
patch --dry-run -ruN -d withings < ~/73228.diff
* confirm it looks good *
patch -ruN -d withings < ~/73228.diff
cat withings/common.py

As noted here https://github.com/home-assistant/core/pull/73228#discussion_r898009818 it doesn't look like this patch is complete yet.

mnul commented 2 years ago

I believe this only affects people using Nabu Casa cloud.

I do come across the same issue. My installation is reachable trough duckdns. Could it also be the port it tries to access? If I look at the description on the callback_uri it says only ports 80, 443 allowed. Usually HA sits on 8123...

Your URL must:

start with https be a valid URL, provided as a URL-encoded string. Please see w3schools URL encoding reference to learn more about URL encoding. not be greater than 255 characters. not contain an IP or 'localhost'. Only ports 80 and 443 are permitted.

dpedestrian commented 2 years ago

I am experiencing the same problem in terms of error code, but I observed requests using method "HEAD" were being rejected with HTTP 405 Method not Allowed from HomeAssistant. You can generate this by testing callback via Withings developer portal or locally using curl. I confirmed I did not need to logon to "GET" the callback url (https://homeassistant.url/auth/external/callback).

That said Withings cloud seems to send a HEAD method which is rejected by homeassistant. The below URL contains details around needing allowed methods of HEAD & POST along with the IP lists of their cloud for firewalls/acls.

https://developer.withings.com/developer-guide/v3/data-api/keep-user-data-up-to-date/#overview

I have a reverse proxy which sends x-forwarded-for setup using Lets Encrypt for the public name and a different cert on homeassistant itself for internal use that is not public trusted. I can access homeassistant normally using both internet and internal URL.

The workaround to use internet url explicit with auto internal does not work for me. I see no change. What is even stranger is that I don't actually see the attempt below in my traffic logs from Withings. Only when I click the test button or auth to them do I see it hit the external URL for callback and when it does it is rejected with a 405 by homeassistant.

I added this to my http: use_x_forwarded_for: true trusted_proxies:

Home Assistant 2022.8.3 Supervisor 2022.08.3 Operating System 8.4 Frontend 20220802.0 - latest

2022-08-11 14:32:45.961 INFO (MainThread) [homeassistant.components.withings.config_flow] Successfully authenticated
2022-08-11 14:32:53.154 DEBUG (MainThread) [homeassistant.components.withings] Creating withings data manager for profile: Withings Profile
2022-08-11 14:32:53.155 DEBUG (MainThread) [homeassistant.components.withings] Confirming Withings Profile is authenticated to withings
2022-08-11 14:32:53.155 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-08-11 14:32:53.155 INFO (MainThread) [homeassistant.components.withings] Updating all withings data
2022-08-11 14:32:53.155 DEBUG (MainThread) [homeassistant.components.withings] Updating withings measures
2022-08-11 14:32:53.918 DEBUG (MainThread) [homeassistant.components.withings] Updating withing sleep summary
2022-08-11 14:32:54.467 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching poll_data_update_coordinator data in 1.312 seconds (success: True)
2022-08-11 14:32:55.469 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-08-11 14:32:55.469 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook
2022-08-11 14:32:55.469 DEBUG (MainThread) [homeassistant.components.withings] Refreshing withings webhook configs
2022-08-11 14:32:55.469 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-08-11 14:32:56.781 DEBUG (MainThread) [homeassistant.components.withings] Subscribing https://homeassistant.internet.url:8123/api/webhook/<code> for NotifyAppli.WEIGHT in 5.0 seconds
2022-08-11 14:33:02.315 DEBUG (MainThread) [homeassistant.components.withings] Failed attempt 1 of 3 (Error code 293)
2022-08-11 14:33:02.816 DEBUG (MainThread) [homeassistant.components.withings] Attempt 2 of 3
2022-08-11 14:33:02.816 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook
2022-08-11 14:33:03.460 DEBUG (MainThread) [homeassistant.components.withings] Subscribing https://homeassistant.internet.url:8123/api/webhook/<code> for NotifyAppli.WEIGHT in 5.0 seconds
2022-08-11 14:33:09.001 DEBUG (MainThread) [homeassistant.components.withings] Failed attempt 2 of 3 (Error code 293)
2022-08-11 14:33:10.002 DEBUG (MainThread) [homeassistant.components.withings] Attempt 3 of 3
2022-08-11 14:33:10.002 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook
2022-08-11 14:33:10.657 DEBUG (MainThread) [homeassistant.components.withings] Subscribing https://homeassistant.internet.url:8123/api/webhook/<code> for NotifyAppli.WEIGHT in 5.0 seconds
2022-08-11 14:33:16.211 DEBUG (MainThread) [homeassistant.components.withings] Failed attempt 3 of 3 (Error code 293)
2022-08-11 14:33:17.713 ERROR (MainThread) [homeassistant.components.withings] Unexpected error fetching subscription_update_coordinator data: Error code 293
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
return await self.update_method()
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 664, in async_subscribe_webhook
return await self._do_retry(self._async_subscribe_webhook)
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 660, in _do_retry
raise exception
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 649, in _do_retry
return await func()
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 706, in _async_subscribe_webhook
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 348, in notify_subscribe
self.request(path=self.PATH_NOTIFY, params=params)
File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 115, in request
return response_body_or_raise(
File "/usr/local/lib/python3.10/site-packages/withings_api/common.py", line 830, in response_body_or_raise
raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 293
2022-08-11 14:33:17.716 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching subscription_update_coordinator data in 22.247 seconds (success: False)
livlif2dfullest commented 2 years ago

I'm running HA 2022.8.6 in docker. I'm also using NGINX to proxy incoming traffic thru CloudFlare from my external URL to the internal IP address:port. Everything works as expected in HA, except for the withings entities they're all unknown. I've verified that my HA external URL and the URL in withings developer dashboard are the same, I'm getting the same issue above in my log below:

2022-08-24 18:44:46.300 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook
2022-08-24 18:44:50.878 DEBUG (MainThread) [homeassistant.components.withings] Subscribing https://mydomain.suffix/api/webhook/<long alphanumeric value> for NotifyAppli.WEIGHT in 5.0 seconds
2022-08-24 18:45:00.390 DEBUG (MainThread) [homeassistant.components.withings] Failed attempt 3 of 3 (Error code 293)
2022-08-24 18:45:01.891 ERROR (MainThread) [homeassistant.components.withings] Unexpected error fetching subscription_update_coordinator data: Error code 293
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 664, in async_subscribe_webhook
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 660, in _do_retry
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 649, in _do_retry
File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 706, in _async_subscribe_webhook
File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 347, in notify_subscribe
File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 115, in request
File "/usr/local/lib/python3.10/site-packages/withings_api/common.py", line 830, in response_body_or_raise
withings_api.common.InvalidParamsException: Error code 293

I tried executing the Subscribing URL above, but I get a "405; Method Not Allowed" error in the body. I just pasted it in the browser so unsure if I was supposed to include headers of some sort. I get a failure when I attempt to test via the withings developer dashboard, "Our servers couldn't reach this URL: Partner error: Callback URL test failed:[Partner error: Fail to connect to callback url:[https://mydomain.suffix/auth/external/callback]]".

I'm unsure if I need to allow something in NGINX, CloudFlare or this is a configuration issue in HA.

Can anyone chime in and make some suggestions please?

StreetGuru commented 2 years ago

I am also having this issue - it rendered my sleep mat useless.

The problem Withings developer account is unable to connect to Home Assistant

What version of Home Assistant Core has the issue? Home Assistant Core 2022.8.7

What was the last working version of Home Assistant Core? Home Assistant Core 2022.6.*

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

withings:
  client_id: !secret withings_id
  client_secret: !secret withings_secret
  use_webhook: true

Anything in the logs that might be useful for us? Only one entry in the log regarding Withings (logged on a reboot of Home Assistant)

Unexpected error fetching subscription_update_coordinator data: Error code 293
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
    return await self.update_method()
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 664, in async_subscribe_webhook
    return await self._do_retry(self._async_subscribe_webhook)
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 660, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 649, in _do_retry
    return await func()
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 706, in _async_subscribe_webhook
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 348, in notify_subscribe
    self.request(path=self.PATH_NOTIFY, params=params)
  File "/usr/local/lib/python3.10/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
  File "/usr/local/lib/python3.10/site-packages/withings_api/common.py", line 830, in response_body_or_raise
    raise InvalidParamsException(status=status)
withings_api.common.InvalidParamsException: Error code 293

Additional information

I'm using a duckdns domain (using the home assistant addon) and also the Nginx Proxy Manager. Router is forwarding ports 443 and 80 to home assistant. Both my external and internal URLs are configured on Home Assistant

On Withings developer account I'm using the same external URL as configured in Home Assistant: https://myhomeassistanturl.duckdns.org/auth/external/callback

When I paste that URL in a browser I get the message: Missing state parameter

when I test from withings developer account I get the following error:

Our servers couldn't reach this URL:
Partner error: Host Unreachable

I have whitelisted all withings IP addresses on my router/firewall, as described here: https://developer.withings.com/developer-guide/v3/data-api/keep-user-data-up-to-date/#overview

While troubleshooting, I also changed the duckdns url to a new one. Home Assistant is reachable on the duckdns url and is correctly configured with https (provided by Nginx Proxy Manager with Let'sEncrypt).

EDIT: I've just noticed that the integrations is working within Home Assistant - the state of binary_sensor.withings_in_bed has changed this morning when I got up. It just seems to not be communicating with withings developer account. I still get the same behaviour as described above when i test the app in withings developer website.

wez commented 2 years ago

In addition to the source change I needed to make over here: https://github.com/home-assistant/core/issues/68760#issuecomment-1246206834 and this amendment to the PR: https://github.com/home-assistant/core/pull/73228#pullrequestreview-1106606833

what I found I needed to do to get this integration working was:

amaisano commented 2 years ago

@wez tried following your comment here and there are three things I'm not clear on:

  1. Does it matter what we enter for "Name" in the initial onboarding flow (field above ID/secret) and does it matter what the Profile name is? I've ready other forums which indicate you have to be VERY careful about what these names are and if they match something in the withings dev app.
  2. I'm getting a yellow "could not reach" every other time i test the webhook url i found in cloud settings (your "Copy the webhook URL"). It's usually yellow the first time, and when i test again it's green. Are we only supposed to have the MAGIC (initial URL), the newer Hooks.Nabucase... URL, or BOTH in the dev app registered URLs section? Does the order matter?
  3. After all that, and several restarts, i'm getting no data - all unknown for the entity values. This error appears:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 129, in async_handle_webhook
    response = await webhook["handler"](hass, webhook_id, request)
  File "/config/custom_components/withings/__init__.py", line 191, in async_webhook_handler
    if not request.body_exists:
AttributeError: 'MockRequest' object has no attribute 'body_exists'

Note - i'm overriding the core component. Anything I'm missing?

PS: When creating the new dev app, i set it to production mode. It also asked what kind of access/data I needed (several checkboxes) -- I clicked the first two ("Public API" and "SDK Integration"). Not sure if that affects Home Assistant.

PPS: Is there a waiting period before this is all expected to start working maybe?

wez commented 2 years ago
  1. Does it matter what we enter for "Name" in the initial onboarding flow (field above ID/secret) and does it matter what the Profile name is? I've ready other forums which indicate you have to be VERY careful about what these names are and if they match something in the withings dev app.

I'm assuming it does matter. I made sure to specify it exactly as it appeared in the auth flow.

  1. Are we only supposed to have the MAGIC (initial URL), the newer Hooks.Nabucase... URL, or BOTH in the dev app registered URLs section? Does the order matter?

I don't think the order matters, but you should have both URLs in there.

  1. After all that, and several restarts, i'm getting no data - all unknown for the entity values. This error appears:
Traceback (most recent call last):
AttributeError: 'MockRequest' object has no attribute 'body_exists'

Sounds like you are missing https://github.com/home-assistant/core/pull/73228/files#diff-cdee9ae23f1e4af251ba8b05163eec7c65a0d5762f102bdee92c8180739fff6c

I don't know the timing on when this will get resolved: I'm assuming that this is currently unmaintained based on the attention on these issues and PRs

amaisano commented 2 years ago

I'm assuming it does matter. I made sure to specify it exactly as it appeared in the auth flow.

So on that first HA flow screen, what should the name be? The name of the app i created in Withings? My name?

wez commented 2 years ago

For me, the oauth flow asked me to confirm which profile I wanted to auth as and I picked Wez F. That is the name I used to enter into the hass integration.

amaisano commented 2 years ago

So this has been stated elsewhere, but if you only have one profile, it is not displayed by the Withings auth page. Is there a definitive place to retrieve that string?

amaisano commented 1 year ago

Sounds like you are missing https://github.com/home-assistant/core/pull/73228/files#diff-cdee9ae23f1e4af251ba8b05163eec7c65a0d5762f102bdee92c8180739fff6

Does this mean I need an entire dev stack of homeassistant core running to implement your workaround??

wez commented 1 year ago

It's not my workaround; it's part of that PR. I've stopped using this because it is a PITA to apply and the latency of the webhook makes it unusable for my purposes.

amaisano commented 1 year ago

I feel your pain. So even AFTER all those steps you followed, it still wasn't worth it? Are you using IFTTT or any alternatives?

wez commented 1 year ago

Correct: the latency was 10 seconds in the very best case and closer to a minute otherwise; not suitable for automation IMO. I don't have an alternative but I also don't really need this :)

TimeBomb commented 1 year ago

Appreciate the effort being put into this, hopefully we get a working Withings integration - webhook and all.

For anyone trying to get anything working between Home Assistant and Withings Sleep's "in bed" sensor, here's what I did that works. What I've got will trigger an automation within 5-15 seconds after you get on or get off your bed.

You will need:

Directions:

  1. Create two automations in Home Assistant, each triggered by their own web hooks.
  2. Create two IFTTT rules. The If should be Withings Sleep IFTTT integrations -> in bed & out of bed. The Then should be webhook -> make a request -> make a request to the two webhook URLs from your home assistant. POST request method. No content type / body.
  3. The two automations you created will now be triggered by IFTTT when it's notified by Withings.

For me, this gets me pretty consistent 5-15 second automation triggers with NabuCasa, which is suitable for what I want to do (turn off lights when I am in bed for long enough). Though the network bounces to achieve this are slightly painful:

  1. Withings hardware on your network
  2. Withings own servers in their cloud
  3. IFTTT receiving webhook trigger from Withings
  4. IFTTT calling Home Assistant webhook
  5. If applicable, Nabu Casa proxying home assistant
  6. Home assistant processing webhook trigger

The only alternative I've found to an in-bed presence sensor is wiring something janky together yourself (using load cells is a common solution I've seen). If you did do this yourself, then your server bounces would be less, and local only, i.e. quicker, and you wouldn't have all the cloud services and complex hardware potentially causing your automations to unexpectedly not trigger. I'm happy sticking with the Withings Sleep for now.

Small note: Of the several tests I did, one of them never triggered the "in bed" trigger. Unsure if it was a HomeAssistant or IFTTT fault, but likely IFTTT. The test was an edge case though - I had just got out of bed, waited 5 seconds for IFTTT to notify Home Assistant I got out of bed, then I got back in bed. All these tests worked fine except one where it never triggered the "in bed" until I got out and back in. Hopefully an extremely rare fluke.

Klangen82 commented 1 year ago

I have just migrated from a dyndns domain and let's encrypt to my own domain together with Cloudflare/NGINX. I had Withings working with my old domain and I was just thinking I could remove the old working Withings integration and renew it with my new domain name...

I cannot get it working again and I don't want to use the IFTTT (had it in the past before withings had an integration)

What I did and tried:

When I go to https://mydomain/auth/external/callback I get "Missing state parameter" so it seams like this is working

I'm not sure what I do wrong here and I have tested to change the https authorize2 response URL to use my domain name as I see that is use my.home-assistant.io (but this should be fine as it set to my new domain name)

Any advise would be appreciated as now I need to manually turn of my light when I go to sleep and this is as you might understand a hard blow to my mental health;)