Local Tuya failed to set up

I added a device in Localtuya, the device didn’t work correctly so I deleted it and tried to add it again. I couldn’t get it to add again so I restarted HA, now my LocalTuya integration just says “failed to set up”. I have several error logs.

Logger: homeassistant
Source: custom_components/localtuya/common.py:125
Integration: LocalTuya ([documentation](https://github.com/rospogrigio/localtuya/), [issues](https://github.com/rospogrigio/localtuya/issues))
First occurred: 11:32:32 PM (236 occurrences)
Last logged: 11:41:22 PM

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()

Traceback (most recent call last): File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 1027, in _read_ready self._protocol.datagram_received(data, addr) File "/config/custom_components/localtuya/discovery.py", line 70, in datagram_received self.device_found(decoded) File "/config/custom_components/localtuya/discovery.py", line 79, in device_found self._callback(device) File "/config/custom_components/localtuya/__init__.py", line 105, in _device_discovered entry = async_config_entry_by_device_id(hass, device_id) File "/config/custom_components/localtuya/common.py", line 125, in async_config_entry_by_device_id if device_id in entry.data[CONF_DEVICES]: KeyError: 'devices'
Logger: homeassistant.config_entries
Source: custom_components/localtuya/__init__.py:242
Integration: LocalTuya ([documentation](https://github.com/rospogrigio/localtuya/), [issues](https://github.com/rospogrigio/localtuya/issues))
First occurred: 11:32:29 PM (2 occurrences)
Last logged: 11:36:27 PM

Error setting up entry localtuya for localtuya

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 365, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/localtuya/__init__.py", line 242, in async_setup_entry region = entry.data[CONF_REGION] KeyError: 'region'
Logger: aiohttp.server
Source: custom_components/localtuya/config_flow.py:532
Integration: LocalTuya ([documentation](https://github.com/rospogrigio/localtuya/), [issues](https://github.com/rospogrigio/localtuya/issues))
First occurred: 11:36:05 PM (1 occurrences)
Last logged: 11:36:05 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 94, 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 241, in post return await super().post(request, flow_id) 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 110, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 280, in async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/localtuya/config_flow.py", line 417, in async_step_init return await self.async_step_edit_device() File "/config/custom_components/localtuya/config_flow.py", line 532, in async_step_edit_device for dev_id, configured_dev in self.config_entry.data[CONF_DEVICES].items(): KeyError: 'devices'
Logger: aiohttp.server
Source: custom_components/localtuya/config_flow.py:507
Integration: LocalTuya (documentation, issues)
First occurred: 11:36:02 PM (1 occurrences)
Last logged: 11:36:02 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 94, 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 241, in post
    return await super().post(request, flow_id)
  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 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 280, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 415, in async_step_init
    return await self.async_step_add_device()
  File "/config/custom_components/localtuya/config_flow.py", line 504, in async_step_add_device
    devices = {
  File "/config/custom_components/localtuya/config_flow.py", line 507, in <dictcomp>
    if dev["gwId"] not in self.config_entry.data[CONF_DEVICES]
KeyError: 'devices'

Has anyone else had this issue or know how to fix it?

I’m on HA v. 2022.11.1
LocalTuya V. 4.1.1

same thing here. It was working, tried to add a new device, and now it’s not working. :frowning:

same issue here, I have to keeo trying to reload the integration until it eventially initialize correctly.

I ended up deleting the Local Tuya integration and starting over. Not a great solution but it worked

Same issue here after trying to add new device.

restore backup? works all the time :slight_smile: