rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.86k stars 549 forks source link

No discovered device when add local tuya integration to Home assistant #635

Open Moustik2002 opened 2 years ago

Moustik2002 commented 2 years ago

READ THIS FIRST:

The problem

Despite multiple tries to be able to browse my tuya devices on the pop up window to follow tutorial there is no way to show them, only "..."

image

Environment

Steps to reproduce

Created a dedicated Tuya IOT project, followed barely all tutorials speaking of it but sadly remained solution dried regardind my issue

Configuration configuration.yaml or config_flow

default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

Provide Home Assistant taceback/logs


Logger: homeassistant
Source: custom_components/localtuya/discovery.py:67
Integration: localtuya (documentation, issues)
First occurred: 15:39:43 (1 occurrences)
Last logged: 15:39:43

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
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()
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 148, in finalize
    data = self._ctx.finalize()
  File "/usr/local/lib/python3.9/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 180, in finalize
    raise ValueError(
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.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 1029, 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 0xad in position 10: invalid start byte

Additional information

I've followed among all tutos i remembered, Mark Watt Tech, reddit, TuyaApiKey guide ....

I use a Zigbee Hub and would like to know if there is specific process to be able to address my devices through it w/ local tuya

Thx in advance for the help you could provide !

Moustik2002 commented 2 years ago

A few steps using manual discovery.

When i try to add my Gateway through the information i've gathered with Tuya API Explorer :

i encounter the error message : An unknown error occurred. See log for details.

The log shows two errors :


Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:240
Integration: LocalTuya integration (documentation, issues)
First occurred: 16:33:08 (1 occurrences)
Last logged: 16:33:08

[bfb...vuk] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    fut.result()
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 510, in detect_available_dps
    data = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 472, in status
    status = await self.exchange(STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 451, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 240, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

and


Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/pytuya/init.py:240
Integration: localtuya (documentation, issues)
First occurred: 16:33:08 (1 occurrences)
Last logged: 16:33:08

Unexpected exception
Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire
await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
fut.result()
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
File "/config/custom_components/localtuya/config_flow.py", line 279, in async_step_basic_info
self.dps_strings = await validate_input(self.hass, user_input)
File "/config/custom_components/localtuya/config_flow.py", line 192, in validate_input
detected_dps = await interface.detect_available_dps()
File "/config/custom_components/localtuya/pytuya/init.py", line 510, in detect_available_dps
data = await self.status()
File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status
status = await self.exchange(STATUS)
File "/config/custom_components/localtuya/pytuya/init.py", line 451, in exchange
msg = await self.dispatcher.wait_for(seqno)
File "/config/custom_components/localtuya/pytuya/init.py", line 240, in wait_for
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Any thought ?

fivenote commented 2 years ago

I'm having the same problem on a fresh install on a raspberry pi 4 Buster. Home Assistant runs in a docker container (using the docker recommended image: ghcr.io/home-assistant/raspberrypi4-homeassistant:stable).

I have another system running Home Assistant OS. On that system localtuya detects tuya devices and I can set them up.

Is your system in docker or HAS OS?

If it's a docker issue, how do we get locatuya to work in docker?

fivenote commented 2 years ago

So I tried to set up a device manually in configuration.yaml per the instructions...

localtuya:
  - host: 172.23.167.171
    device_id: xxxxx
    local_key: xxxxx
    friendly_name: Tuya Device
    protocol_version: "3.3"
    entities:
      - platform: switch
        friendly_name: Plug
        id: 1
        current: 18 # Optional
        current_consumption: 19 # Optional
        voltage: 20 # Optional

The device appears on the dashboard, but is grayed-out and doesn't work. I think this may be a network issue in docker, that it can't see the local network devices.

fivenote commented 2 years ago

A little more info... I went into the container (docker exec -it homeassistant bash) and could ping and nmap all the devices on the local network. The container's network is "host" btw.

So maybe docker can see the devices, but something in localtuya can't see them when run via docker?

I hope I'm adding some useful info here and can get help to figure out what's wrong.

Thanks.

Moustik2002 commented 2 years ago

indeed i'm running HA through doker

fivenote commented 2 years ago

Good to know. Hope we get a reply from someone who knows how to make this work.

Moustik2002 commented 2 years ago

Installing Home assistant OS VM to see if there is some change.

EDIT : Sadly same result on HA OS through VM what's your Core version on your VM @fivenote ?

paul-mulvihill commented 2 years ago

If it's of any use, I'm seeing the same thing on a fresh install (PI 4, core-2021.11.4). My older VM instance (ova) is still working though (core-2021.10.6)

fivenote commented 2 years ago

If it's of any use, I'm seeing the same thing on a fresh install (PI 4, core-2021.11.4). My older VM instance (ova) is still working though (core-2021.10.6)

Docker?

fivenote commented 2 years ago

Installing Home assistant OS VM to see if there is some change.

EDIT : Sadly same result on HA OS through VM what's your Core version on your VM @fivenote ?

Latest… 2021.11.5

paul-mulvihill commented 2 years ago

If it's of any use, I'm seeing the same thing on a fresh install (PI 4, core-2021.11.4). My older VM instance (ova) is still working though (core-2021.10.6)

Docker?

I'm a bit new to the core components of the HA setup.. the PI install is the 64bit image installation through the official docs. The old VM is just the OVA you can download from the site as well. when I get into ssh and do docker --version they both come back as version 20.10.9

fivenote commented 2 years ago

Here's the log when I try to add a tuya device. I used the integration UI and manually entered the device id, local key and device IP.

2021-11-21 10:05:53 ERROR (MainThread) [custom_components.localtuya.pytuya] [121...0bd] Failed to get status: 

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire

    await fut

asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for

    fut.result()

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 510, in detect_available_dps

    data = await self.status()

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 472, in status

    status = await self.exchange(STATUS)

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 451, in exchange

    msg = await self.dispatcher.wait_for(seqno)

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 240, in wait_for

    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)

  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for

    raise exceptions.TimeoutError() from exc

asyncio.exceptions.TimeoutError

2021-11-21 10:05:53 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire

    await fut

asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for

    fut.result()

asyncio.exceptions.CancelledError

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

Traceback (most recent call last):

  File "/config/custom_components/localtuya/config_flow.py", line 279, in async_step_basic_info

    self.dps_strings = await validate_input(self.hass, user_input)

  File "/config/custom_components/localtuya/config_flow.py", line 192, in validate_input

    detected_dps = await interface.detect_available_dps()

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 510, in detect_available_dps

    data = await self.status()

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 472, in status

    status = await self.exchange(STATUS)

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 451, in exchange

    msg = await self.dispatcher.wait_for(seqno)

  File "/config/custom_components/localtuya/pytuya/__init__.py", line 240, in wait_for

    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)

  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for

    raise exceptions.TimeoutError() from exc

asyncio.exceptions.TimeoutError
Moustik2002 commented 2 years ago

yeah it's similar to my log error, seems to be bind to some timeout when integration would like to discover tuya devices on LAN from what i am understanding, or maybe it's trying to parse local id from tuya iot and can't. I'm an IT guy not a developper one, so i'm stuck.

Sadly there is no local tuya guys showing up so far, let's be patient... @mileperhour, @mrdarrengriffin are you there ?

Moustik2002 commented 2 years ago

nevermind the mention just above I've done a mistake ;) it is not related

Back to this subject, @fivenote and @paul-mulvihill are you using zigbee-hub for this purpose ? Maybe the root of my issue here so that why i wondering .

fivenote commented 2 years ago

nevermind the mention just above I've done a mistake ;) it is not related

Back to this subject, @fivenote and @paul-mulvihill are you using zigbee-hub for this purpose ? Maybe the root of my issue here so that why i wondering .

Not using a zigbee-hub. I just have tuya bulbs and switches on my local subnet.

fivenote commented 2 years ago

I may have figured out my problem. I made sure no smartlife app or Home Assistant instance was running and possibly connected to the devices. I also made sure the firewall lets in 6666/udp and 6667/udp. After that, localtuya detected all of them.

I thought I had done this before, but something must have still been connected to the devices. Tuya devices only allow one connection at a time and don’t seem to broadcast their presence when already connected.

Let me know if this helps any.

paul-mulvihill commented 2 years ago

nevermind the mention just above I've done a mistake ;) it is not related

Back to this subject, @fivenote and @paul-mulvihill are you using zigbee-hub for this purpose ? Maybe the root of my issue here so that why i wondering .

Likewise no hub.. I have just done the same as @fivenote and it is working.. I didn't think the old instance would be maintaining the connection, blocking all else.

jeremyfry commented 2 years ago

Tuya devices only allow one connection at a time and don’t seem to broadcast their presence when already connected.

Wow didn't expect this. I had to force close the Home Life app on my phone and the device connected instantly. No firewall rules needed on my end.

shiftylilbastrd commented 2 years ago

Same issue here. Running HA in Docker on an Unraid machine. Completely shut down my phone to try and get this to work and still get the same discovery screen as OP.