Config issue integrating with SmartThings via Nabu Casa

Followed the guide (and its troubleshooting steps!), but it’s clear something is still improperly configured. My attempts to remedy keep coming up short.

Running the HASS container on a Raspberry Pi (bullseye). Plenty of other integrations work, but SmartThings is being pesky. I’ve generated the PAT for SmartThings, but haven’t gotten far enough in the process to enter it.

Signed up for Nabu Casa earlier today and linked it to my local HASS instance. Looks like there’s already a webhook for SmartApp:

I keep getting this error when attempting to add an integration to SmartThings via the HASS UI (Settings > Devices & Services > Add Integration):

Error
Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

Per the troubleshooting docs, the culprit is likely my config. I initially kept my initial onboarding settings since I’m using Nabu Casa cloud:

I then tried overwriting the external_url in my config yaml (note: before attempting this, homeassistant: — nor any of its children — were present in my configuration.yaml):

homeassistant:
  external_url: "https://hooks.nabu.casa/gAA..."

Save, restart, try to add SmartThings integration again. Same 500 error. Also tried this config, yielding the same 500 error:

homeassistant:
  external_url: "https://hooks.nabu.casa/"

Enabled debug-level logs for HASS and found a couple tracebacks:

2022-12-05 12:25:42.433 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 192.168.1.10 for /api/config/config_entries/flow using bearer token
2022-12-05 12:25:42.433 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/config/config_entries/flow to 192.168.1.10 (auth: True)
2022-12-05 12:25:42.435 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 148, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 225, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 252, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/config_flow.py", line 60, in async_step_user
    await setup_smartapp_endpoint(self.hass)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 226, in setup_smartapp_endpoint
    webhook.async_register(
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 46, in async_register
    raise ValueError("Handler is already defined!")
ValueError: Handler is already defined!
2022-12-05 12:24:14.258 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 148, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 225, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 252, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/config_flow.py", line 60, in async_step_user
    await setup_smartapp_endpoint(self.hass)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 237, in setup_smartapp_endpoint
    cloudhook_url = await cloud.async_create_cloudhook(
  File "/usr/src/homeassistant/homeassistant/components/cloud/__init__.py", line 181, in async_create_cloudhook
    hook = await hass.data[DOMAIN].cloudhooks.async_create(webhook_id, True)
  File "/usr/local/lib/python3.10/site-packages/hass_nabucasa/cloudhooks.py", line 35, in async_create
    raise ValueError("Hook is already enabled for the cloud.")
ValueError: Hook is already enabled for the cloud.

Other potentially relevant logs:

2022-12-05 12:22:07.379 INFO (MainThread) [snitun.utils.aiohttp_client] AioHTTP snitun client started on 127.0.0.1:40155
2022-12-05 12:22:29.815 INFO (MainThread) [snitun.utils.aiohttp_client] AioHTTP snitun client connected to: us-west-2-2.ui.nabu.casa:443
2022-12-05 12:22:29.816 DEBUG (MainThread) [hass_nabucasa.remote] Connected
2022-12-05 12:23:48.452 DEBUG (MainThread) [hass_nabucasa.cloud_api] Fetched https://accounts.nabucasa.com/payments/subscription_info (200)
2022-12-05 12:22:04.483 DEBUG (MainThread) [hass_nabucasa.iot] Publishing message:
{'handler': 'webhook-register',
 'msgid': '~REDACTED~',
 'payload': {'cloudhook_ids': ['~REDACTED~']}}

What should I try next?

When did you start trying and where is your ST shard located? SmartThings posted an outage for Northamerica this afternoon (Dec 5)

If you’re affected I’d wait till they clear it before trying again.

Looks like the SmartThings service outage was resolved yesterday, so we’re clear of that.

Tried adding the ST integration again this morning using the default config (not overriding external_url in my config yaml) and received the same 500 error. :grimacing:

I’m thinking that preexisting web hook has to go. I’d also suggest looking at the ST side to see if it thinks you have Homeassistant setup already (you may need to run that CLI tool to clear any existing botched installs)

I deleted the SmartThings PAT for Home Assistant mid-day, then restarted HA remotely from work. Came home to find the ST webhook gone from HASS Setup > Cloud.

This is my first time using ST, so I’m not sure what to look for there. It doesn’t look like there’s an integration, but I’m new here so :man_shrugging:.

Tried creating the integration again and got the same 500 error. Here’s that traceback for good measure:

Logger: aiohttp.server
Source: components/webhook/__init__.py:46
First occurred: 10:25:19 PM (1 occurrences)
Last logged: 10:25:19 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 148, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 225, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 252, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/config_flow.py", line 60, in async_step_user
    await setup_smartapp_endpoint(self.hass)
  File "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 226, in setup_smartapp_endpoint
    webhook.async_register(
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 46, in async_register
    raise ValueError("Handler is already defined!")
ValueError: Handler is already defined!

Spent some time trying to get the hass_smartthings_remove package working, and I think I need help with this one. If it were as simple as running pip install on my Raspberry Pi I’d be done by now, but I’m a bit confused how to make this work given I’m running the HASS container. Guessing I’ll need to figure out how to compile that into a local package, then maybe leverage python script? Appreciate any pointers :slight_smile:

Fixed it! For posterity, here are the steps I took:

  1. Delete this file: <config>\.storage\smartthings
  2. Verify there’s no custom external_url set in my config (since I’m using Nabu Casa)
  3. Restart HASS
  4. Ensure there wasn’t an ST token already created for HASS
  5. Create a new PAT for HASS
  6. HASS Settings > Devices & Services > Add Integration > SmartThings, then follow the prompts as directed

What I was doing wrong:

  • Mistakenly thought I needed to run the hass_smartthings_remove script from the same python instance as HASS. Turns out the script interacts directly with SmartThings Cloud, so it can be run from any python installation with access to the internet.
  • Apparently running this script wasn’t needed anyway, as the token I created was already removed and cleared.

Always a good feeling when things work as expected. Thanks for your help @NathanCu!

1 Like

How do i delete the file? Super new to this. Thanks

In case someone else stumbles across this issue in their instance, here is an updated method to resolution:
Edit the smartthings config file on your HASS instance to include your Nabu Casa webhook URL
To do this:

  1. Get your Nabu Casa webhook URL from Settings > Home Assistant Cloud >> click “manage” and copy the URL
  2. Install the SSH add-on in your web interface
  3. Run the SSH add-on
  4. Edit the config file with the command: nano /config/.storage/smartthings
  5. On the line "cloudhook_url": null change “null” to your Nabu Casa webhook URL - contained within quotations
  6. Save changes to the config file
  7. Retry setting up Smartthings integration

@yimmyay

I’m having this issue after switching from DuckDNS and Lets Encrypt to Home Assistant Cloud. My integration is showing as not loaded and when I try to mock configure a new Smartthings integration it points back to my local IP as the webhook instead of the Cloud URL.

I followed your steps to add the cloudhook_url but still no success. I’m not sure what else I could be missing. Any ideas?