Smartthings integration issue 1

Hi. i am trying Home Assistant for the third time, but now i really mean to stick around. Ive done a fresh install of HA in a Docker on a RPI and i am hoping to run it as both a server and a viewer through web ui.

when i reactivated my nabu casa account it seemed to have an old Smartthings webhook (from the two earlier attempts) but i couldnt get it past the api token part. I tried the script to remove old integration for Smartthings and it seemed to work. However, now i cant even start to add the integrations, it only says “config flow could not be loaded (swe) 500 Internal Server Error Server got itself in trouble” and i cant seem to add it after i ran the script.

what can i do to fix this? having it work with Smartthings is sort of a big thing.

i tried other integrations and they work so it would seem it just the ST one afaik.

again, really appriciate if any replies have detailed instructions since the whole command based OS is new to me.

EDIT
think the logg is picking up on the error, posting it below in quote

Logger: aiohttp.server
Source: components/webhook/__init__.py:46
First occurred: 18:47:45 (5 occurrences)
Last logged: 19:20:29

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

Hi all!

I got the same problem. Also joined Nabu Casa (test period) and set up everything.
There is already a smartthings webhook token on the Home Assistant Cloud Page. It was there from the beginning, without having the SmartThings integration running/set up.

But I did not set up the Smart Things Integration. If I try to add the Integration, this error pops up:

2022-10-15 12_30_09-Settings – Home Assistant

Logger: aiohttp.server
Source: components/webhook/__init__.py:46
First occurred: 12:09:03 (5 occurrences)
Last logged: 12:21:16

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!
Logger: homeassistant.components.webhook
Source: components/smartthings/smartapp.py:503
Integration: webhook (documentation, issues)
First occurred: 12:12:25 (1 occurrences)
Last logged: 12:12:25

Error processing webhook 
[REDACTED] 6bbce
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 "/usr/src/homeassistant/homeassistant/components/smartthings/smartapp.py", line 503, in smartapp_webhook
    manager = hass.data[DOMAIN][DATA_MANAGER]
KeyError: 'smartthings'

Running the newest HA OS and HA Core on an RPi4

Home Assistant 2022.10.4
Supervisor 2022.10.0
Operating System 9.2
Frontend 20221010.0

Of course I tried to add the SmartThing Integration in the past but the webhook URL was wrong (my internal network IP). As I am lazy I choose Nabu Casa do enable the external Access to my local HA instance.
What I tried for troubleshooting:

  • I restarted HA core a few times
  • Also I tried the following: I put the Nabu Casa URL of my HA Instance manually under Settings > System > Network > HA URL

At first the smartthing webhook under Settings > HA Cloud was gone, but I got another error when I tried to add the smartthings integration:

Logger: aiohttp.server
Source: components/cloud/__init__.py:181
First occurred: 12:43:47 (1 occurrences)
Last logged: 12:43:47

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.

I’m out of ideas. :frowning:

Thanks for looking into this.

@ kexan82

I found a workaround, which is pretty sketchy.

  • Logoff your HA Cloud account in your local HA instance.

  • There is a file under /config/.storage/ called smartthings. In there is the (old or wrong) webhook ID.
    Delete this file.

  • Then reconnect your local HA to your Nabu Casa account.

  • Make sure that under Settings > System > Network > Home Assistant URL “Use Home Assistant Cloud” is active.

  • Add the Smartthings App to your integrations. This time it should work.

1 Like

@ahpex

i tried reinstalling the whole system plus HA yesterday and i ran into the same issue. just ran the script to remove the old app but its returning that “Translation Error: The intl string context variable “token_url” was not provided to the string” error. Tried your method after finding the advanced mode to check network. Now it just says “unknown error” but the log has new info.

EDIT: also, i have to doublecheck, im assuming the connection is made without the old smartapp HA used to have in ST? Could the errors be due to the migrations to the new platform?

Logger: aiohttp.server
Source: components/smartthings/config_flow.py:168
First occurred: 21:59:38 (2 occurrences)
Last logged: 21:59:49

Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/data_entry_flow.py", line 280, in async_configure
    result = await self._async_handle_step(
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/smartthings/config_flow.py", line 159, in async_step_pat
    return await self.async_step_select_location()
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/smartthings/config_flow.py", line 168, in async_step_select_location
    locations = await self.api.locations()
  File "/srv/homeassistant/lib/python3.9/site-packages/pysmartthings/smartthings.py", line 38, in locations
    resp = await self._service.get_locations()
  File "/srv/homeassistant/lib/python3.9/site-packages/pysmartthings/api.py", line 53, in get_locations
    return await self.get_items(API_LOCATIONS)
  File "/srv/homeassistant/lib/python3.9/site-packages/pysmartthings/api.py", line 384, in get_items
    resp = await self.request("get", self._api_base + resource, params, None)
  File "/srv/homeassistant/lib/python3.9/site-packages/pysmartthings/api.py", line 376, in request
    resp.raise_for_status()
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://api.smartthings.com/v1/locations')

Your error log looks like the old Smartthings App is beeing used or maybe both versions are active.

New (the location my errors came from)
/site-packages/homeassistant/components/smartthings/smartapp.py

Old
/site-packages/pysmartthings/smartthings.py

As I’m running HA OS with HA Core I’m not able to replicate this exact scenario.
I’f you’re able to run Linux VMs (via kvm/qemu) I would also recommend looking into HA OS, it makes things (mostly) easier.

i want to run the client and server on the same rpi so i cant use HA OS sadly.

ive tried multiple times, now the smartthings says its discovered but i get errors when trying to add it. ive deleted the file and it keeps returning without fixing the issue.

ive resorted to editing the smartthings file but it doesnt seem to help.

so i noticed something. i reran the remove old smart app-script and it removed four instances. ran it again, removed none. i then tried the “add integrations” and it came up with the same error as always. reran the script and it removed one instance of the old app.

so it would seem that the integration is still trying to connect to the old smartapp and not the new login way.

can i edit anything or make it so that the integration goes for the new method?