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
71.64k stars 29.94k forks source link

Withings Callback URL Incorrect - Nabu Casa #73200

Closed nebriv closed 1 year ago

nebriv commented 2 years ago

The problem

The current Withings integration is using the incorrect webhook URL (it is using the internal webhook endpoint, instead of the external endpoint). This appears to be an issue that was repeatedly opened in 2020/2021, however the issues have been closed and locked.

What version of Home Assistant Core has the issue?

Core-2022.6.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Withings

Link to integration documentation on our website

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

Diagnostics information

Editing /usr/local/lib/python3.9/site-packages/withings_api/init.py on line ~345 to override the callbackurl to the correct webhook url instead of using the internal IP address works. I'm not sure where the current webhook url is picked up from.

def notify_subscribe(
    self,
    callbackurl: str,
    appli: Optional[NotifyAppli] = None,
    comment: Optional[str] = None,
) -> None:
    """Subscribe to receive notifications when new data is available."""
    params: Final[ParamsType] = {}
    _LOGGER.warn("CALL BACK URL: %s" % callbackurl)
    callbackurl = "https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700"
    _LOGGER.warn("CALL BACK URL2: %s" % callbackurl)
    update_params(params, "callbackurl", callbackurl)
    update_params(params, "appli", appli, lambda appli: appli.value)

Webhook configuration: image

Network Configuration: image

Example YAML snippet

withings:
  client_id: 4*****REDACTED*****f
  client_secret: 8*****REDACTED*****1
  use_webhook: true

logger:
  default: warning
  logs:
    homeassistant.components.withings: debug

Anything in the logs that might be useful for us?

2022-06-07 23:28:37 DEBUG (MainThread) [homeassistant.components.withings] Creating withings data manager for profile: FirstName LastInitial
2022-06-07 23:28:38 DEBUG (MainThread) [homeassistant.components.withings] Confirming FirstName LastInitial is authenticated to withings
2022-06-07 23:28:38 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-06-07 23:28:38 INFO (MainThread) [homeassistant.components.withings] Updating all withings data
2022-06-07 23:28:38 DEBUG (MainThread) [homeassistant.components.withings] Updating withings measures
2022-06-07 23:28:38 DEBUG (MainThread) [homeassistant.components.withings] Updating withing sleep summary
2022-06-07 23:28:38 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching poll_data_update_coordinator data in 0.958 seconds (success: True)
2022-06-07 23:28:39 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-06-07 23:28:39 DEBUG (MainThread) [homeassistant.components.withings] Configuring withings webhook
2022-06-07 23:28:39 DEBUG (MainThread) [homeassistant.components.withings] Refreshing withings webhook configs
2022-06-07 23:28:39 DEBUG (MainThread) [homeassistant.components.withings] Attempt 1 of 3
2022-06-07 23:28:40 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.WEIGHT in 1.0 seconds
2022-06-07 23:28:45 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.CIRCULATORY in 1.0 seconds
2022-06-07 23:28:51 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.ACTIVITY in 1.0 seconds
2022-06-07 23:28:56 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.SLEEP in 1.0 seconds
2022-06-07 23:29:01 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.BED_IN in 1.0 seconds
2022-06-07 23:29:07 DEBUG (MainThread) [homeassistant.components.withings] Unsubscribing https://hooks.nabu.casa/gAAAAABioBPo_-*****REDACTED*****weDMN37ZpwTr9QyrPhVv_0XRJtk3VfMTecfUE49UR3pf3M0Wfu4NYfrX4VEiMBIuOslxK8= for NotifyAppli.BED_OUT in 1.0 seconds
2022-06-07 23:29:12 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.WEIGHT in 5.0 seconds
2022-06-07 23:29:17 WARNING (SyncWorker_5) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:17 WARNING (SyncWorker_5) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:18 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.CIRCULATORY in 5.0 seconds
2022-06-07 23:29:23 WARNING (SyncWorker_0) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:23 WARNING (SyncWorker_0) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:24 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.SLEEP in 5.0 seconds
2022-06-07 23:29:29 WARNING (SyncWorker_3) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:29 WARNING (SyncWorker_3) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:29 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.ACTIVITY in 5.0 seconds
2022-06-07 23:29:34 WARNING (SyncWorker_2) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:34 WARNING (SyncWorker_2) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:35 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.BED_IN in 5.0 seconds
2022-06-07 23:29:40 WARNING (SyncWorker_1) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:40 WARNING (SyncWorker_1) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:41 DEBUG (MainThread) [homeassistant.components.withings] Subscribing http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700 for NotifyAppli.BED_OUT in 5.0 seconds
2022-06-07 23:29:46 WARNING (SyncWorker_2) [test] CALL BACK URL: http://192.168.1.120:8123/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:46 WARNING (SyncWorker_2) [test] CALL BACK URL2: https://t*****REDACTED*****h.ui.nabu.casa/api/webhook/66*****REDACTED*****700
2022-06-07 23:29:46 DEBUG (MainThread) [homeassistant.components.withings] Finished fetching subscription_update_coordinator data in 66.865 seconds (success: True)

Additional information

Other relevant issues: https://github.com/home-assistant/core/issues/46425

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)


withings documentation withings source (message by IssueLinks)

gloaysa commented 2 years ago

Hi there, I'm running into this issue, trying to setup Withings, is there any workaround?

nebriv commented 2 years ago

I actually almost feel like this might be an issue in the async_generate_url function in the home assistant webhook module here:

https://github.com/home-assistant/core/blob/93cbb331e5212383398a5d4a0f6314bf70a8e760/homeassistant/components/webhook/__init__.py#L70

It defaults to allow_cloud=False, though I really have no idea what the implications of this are yet...

@gloaysa are you using Nabu Casa cloud?

nebriv commented 2 years ago

Aha!

Looks like this might be resolved in this pull request: https://github.com/home-assistant/core/pull/73228

danielcbit commented 2 years ago

Another issue I had was that my callback urls in Withings Dev portal had to reflect the same values configured on Configuration.yml

The external_url and internal_url values in the configuration file need to match whatever you used in the Withings page as well as when configuring the Withings integration, the URL you are using to connect to Home Assistant need to match also the external_url or internal_url values.

For example:

Assuming you have Home Assistant running on 10.0.0.20:8123 and you access it using that in the browser, I believe that the internal_url needs to have that url as well as the Withings Dev. Also, just provide the base URL and Port in the configuration.yml file. There is no need to provide ouath authentication path as this will be added automatically.

Lastly, it seems that you need to have a valid domain pointing to your Home Assistant instance for the webhooks to work.

Withings tries to Connect to those to deliver the information on sensor changes.

Hope that helps!

On Tue, Jun 14, 2022 at 5:55 PM Ben Virgilio @.***> wrote:

Aha!

Looks like this might be resolved in this pull request:

73228 https://github.com/home-assistant/core/pull/73228

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/73200#issuecomment-1155860016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMDXJ3OUOFVV6PVVFFWEHDVPESZFANCNFSM5YFA5B4A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

gloaysa commented 2 years ago

@nebriv thanks for coming back to me. I was able to fix it following this workaround. I can live with it until https://github.com/home-assistant/core/pull/73228 is merged and deployed.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.