Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Add Devices to LocalTuya #1840

Open
2 tasks done
sirj0k3r opened this issue Nov 7, 2024 · 9 comments
Open
2 tasks done

Cannot Add Devices to LocalTuya #1840

sirj0k3r opened this issue Nov 7, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@sirj0k3r
Copy link

sirj0k3r commented Nov 7, 2024

The problem

While trying to add a new device the following happens:

  • No dropdown shows up listing any available device;
  • While adding manually the following error is displayed: "Connection to device succeeded but no datapoints found, please try again. Create a new issue and include debug logs if problem persists."

The latter happens when using protocol v3.3. Any other protocol does not display an error but also doesn't add the device.

Environment

  • Localtuya version: 5.2.1 (installed from HACS)
  • Home Assistant Core version: 2024.10.4
  • Does the device work using the Home Assistant Tuya Cloud component?
  • [] Does the device work using the Tinytuya (https://github.com/jasonacox/tinytuya) command line tool? Apparently not. Finds 0 devices
  • [] Was the device working with earlier versions of localtuya ? Which one? First time using LocalTuya.
  • Are you using the Tuya/SmartLife App in parallel ? The app is installed and configured, as well as the native plugin.

Steps to reproduce

  1. Install LocalTuya from HACS
  2. Restart HASS
  3. Add LocalTuya Integration
  4. Configure using Cloud API Account
  5. Configure again to add a new device

DP dump

INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
INFO:localtuya:Using pytuya version '10.0.0'
/home/ha/Downloads/tuyadebug/./test.py:37: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  now = datetime.datetime.utcnow()
INFO:localtuya:Detecting list of available DPS of device … […], protocol 3.3.
DEBUG:localtuya.pytuya:[bfa...rqs] Sending command 10 (device type: type_0a)
DEBUG:localtuya.pytuya:[bfa...rqs] Sending payload: b'{"gwId":"…","devId":"…","uid":"…","t":"…"}'
DEBUG:localtuya.pytuya:[bfa...rqs] Command 10 waiting for sequence number 1
DEBUG:localtuya.pytuya:[bfa...rqs] Connection lost: None
ERROR:localtuya.pytuya:[bfa...rqs] Failed to get status: 
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/locks.py", line 386, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ha/Downloads/tuyadebug/localtuya/pytuya/__init__.py", line 849, in detect_available_dps
    data = await self.status()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ha/Downloads/tuyadebug/localtuya/pytuya/__init__.py", line 781, in status
    status = await self.exchange(DP_QUERY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ha/Downloads/tuyadebug/localtuya/pytuya/__init__.py", line 755, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ha/Downloads/tuyadebug/localtuya/pytuya/__init__.py", line 446, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

Provide Home Assistant traceback/logs

This error originated from a custom integration.

Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:863
integration: LocalTuya (documentation, issues)
First occurred: 7:53:44 AM (1 occurrences)
Last logged: 7:53:44 AM

[bfa...rqs] Failed to get status:
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/locks.py", line 386, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ha/.homeassistant/custom_components/localtuya/pytuya/__init__.py", line 863, in detect_available_dps
    data = await self.status()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ha/.homeassistant/custom_components/localtuya/pytuya/__init__.py", line 795, in status
    status = await self.exchange(DP_QUERY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ha/.homeassistant/custom_components/localtuya/pytuya/__init__.py", line 769, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ha/.homeassistant/custom_components/localtuya/pytuya/__init__.py", line 450, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

I also get Device status: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None} when running the following example from TinyTuya:

# Example Usage of TinyTuya
import tinytuya

d = tinytuya.Device('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE', version=3.3)
data = d.status() 
print('Device status: %r' % data)

One of the problems might be that tinytuya is considering an IP range for which the devices are not there.

TinyTuya (Tuya device scanner) [1.15.1]

[Loaded devices.json - 6 devices]

Scanning on UDP ports 6666 and 6667 and 7000 for devices for 18 seconds...

New Broadcast from App at 172.20.0.1 - {'from': 'app', 'ip': '172.20.0.1'}
Scan completed in 18.0366 seconds                  
                    
Scan Complete!  Found 0 devices.
Broadcasted: 0
Versions: 

>> Saving device snapshot data to snapshot.json
@sirj0k3r sirj0k3r added the bug Something isn't working label Nov 7, 2024
@rwilkin
Copy link

rwilkin commented Nov 11, 2024

I am also getting this error. Not sure if you want me to create a new issue or just add to this one though. Happy to create a new issue if that's preferred.

The problem

While trying to add a new device the following happens:

  • No dropdown shows up listing any available device;
  • While adding manually the following error is displayed: "Connection to device succeeded but no datapoints found, please try again. Create a new issue and include debug logs if problem persists."
    It doesn't matter what protocol version I select it tells me the same thing.

Environment

Localtuya version: 5.2.1 (installed from HACS)
Home Assistant Core version: 2024.10.4

Does the device work using the Home Assistant Tuya Cloud component? Yes

  • Does the device work using the Tinytuya (https://github.com/jasonacox/tinytuya) command line tool? Yes - I only have the one device for now (it is a light).
    Output from TinyTuya: Address = 192.168.1.228 Device ID = bf0d05e0bf187749d4wdf6 (len:22) Local Key = Version = 3.5 Type = default
  • Was the device working with earlier versions of localtuya ? Which one? This is the first time I've used LocalTuya.

Are you using the Tuya/SmartLife App in parallel ? The Tuya app is installed and working on my phone.

Steps to reproduce

  1. Install LocalTuya from HACS
  2. Restart HASS
  3. Add LocalTuya Integration
  4. Configure without Cloud API Account -- (Also tried configuring with cloud API account)
  5. Configure again to add a new device

Logs

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
integration: LocalTuya (documentation, issues)
First occurred: November 10, 2024 at 7:28:56 PM (2497 occurrences)
Last logged: 11:36:06 AM

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready() (None)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1238, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 0: invalid start byte
This error originated from a custom integration.

Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:863
integration: LocalTuya (documentation, issues)
First occurred: November 10, 2024 at 8:13:51 PM (7 occurrences)
Last logged: 11:05:26 AM

[bf0...df6] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/locks.py", line 386, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 863, in detect_available_dps
    data = await self.status()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 795, in status
    status = await self.exchange(DP_QUERY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 769, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 450, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

@MartinKoubek
Copy link

I have the same problem with python3.12, v5.2.2

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/locks.py", line 386, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 863, in detect_available_dps
    data = await self.status()
           ^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 795, in status
    status = await self.exchange(DP_QUERY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 769, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 450, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

@false-coder
Copy link

I have the same problem:

Эта ошибка возникла в пользовательской интеграции.

Регистратор: homeassistant
Источник: custom_components/localtuya/discovery.py:67
интеграция: LocalTuya integration (документация, проблемы)
Первое сообщение: 14 ноября 2024 г. в 16:09:36 (16152 сообщений)
Последнее сообщение: 14:36:58

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready() (None)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1238, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 2: invalid start byte

@alex-1987
Copy link

I have same Problem

Dieser Fehler stammt von einer benutzerdefinierten Integration

Logger: homeassistant
Quelle: custom_components/localtuya/discovery.py:67
Integration: LocalTuya integration (Dokumentation, Probleme)
Erstmals aufgetreten: 09:13:05 (76 Vorkommnisse)
Zuletzt protokolliert: 09:16:25

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready() (None)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x84 in position 0: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1238, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 1: invalid continuation byte

@hostand
Copy link

hostand commented Nov 18, 2024

Same here! Newly added devices are not showing up in the list and can't even be configured manually.

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
integration: LocalTuya (documentation, issues)
First occurred: 5:08:06 PM (12 occurrences)
Last logged: 5:09:01 PM

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready() (None)
Traceback (most recent call last):
  File "/config/custom_components/localtuya/discovery.py", line 65, in datagram_received
    data = decrypt_udp(data)
           ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/discovery.py", line 30, in decrypt_udp
    return _unpad(decryptor.update(message) + decryptor.finalize()).decode()
                                              ^^^^^^^^^^^^^^^^^^^^
ValueError: The length of the provided data is not a multiple of the block length.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1238, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/config/custom_components/localtuya/discovery.py", line 67, in datagram_received
    data = data.decode()
           ^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfb in position 0: invalid start byte

@hostand
Copy link

hostand commented Nov 18, 2024

I have solved the problem following this comment in another tread (using another fork of localtuya) #1452 (comment)

@rwilkin
Copy link

rwilkin commented Nov 27, 2024

I have solved the problem following this comment in another tread (using another fork of localtuya) #1452 (comment)

Perfect! Thank you that solved the issue for me. Thank you so much.

@sirj0k3r
Copy link
Author

I have solved the problem following this comment in another tread (using another fork of localtuya) #1452 (comment)

Definitely works. Thanks!

However, I still have trouble discovering devices. Did you manage to get it working or just added everything manually?

@hostand
Copy link

hostand commented Nov 27, 2024

I have solved the problem following this comment in another tread (using another fork of localtuya) #1452 (comment)

Definitely works. Thanks!

However, I still have trouble discovering devices. Did you manage to get it working or just added everything manually?

Like you not all my devices were discovered (just one was missing) but I added it manually and it worked. Even not discovering the device after entering the initial information (IP, Local Key, device ID) this forked version of local tuya was able to map the dp_ids. So far so good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants