rospogrigio / localtuya

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

Can't connect to gateway #645

Open Santanachia opened 2 years ago

Santanachia commented 2 years ago

The problem

I cannot connect to the gateway either through the configuration.yaml, config_flow or DP dump

Environment

Configuration

config_flow

Device Discovery found my device: bfc...hen (192.168..) I put a name for the device and local_key, left the rest unchanged an error occurred: Failed to authenticate with device. Verify that device id and local key are correct.

configuration.yaml

  - host: 192.168.*.*
    device_id: bfc...hen
    local_key: ...
    friendly_name: Bramka
    protocol_version: '3.3'
    entities:
      - platform: light
        friendly_name: Gabinet
        id: 1

DP dump

INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device bfc...hen [192.168.*.*], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bfc...hen","devId":"bfc...hen"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'V\xad\x80ap\x9c\xc6\x1a\x95CJSll~\x10'
DEBUG:localtuya.pytuya:decrypted result='devid not found'
DEBUG:localtuya.pytuya:Failed to connect to 192.168.*.*. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: Expecting value: line 1 column 1 (char 0)
INFO:localtuya:TIMEOUT: No response from device bfc...hen [192.168.*.*] after 2 attempts.

Provide Home Assistant taceback/logs

[bfc...hen] Connect to 192.168.*.* failed
Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 149, in _make_connection
    status = await self._interface.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 457, in exchange
    payload = self._decode_payload(msg.payload)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 559, in _decode_payload
    return json.loads(payload)
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Additional information

I have one more device that I couldn't add via config_flow, but it was detected by DP Dump and works fine when added to configuration.yaml

ThomasCr commented 2 years ago

try different protocol version... or maybe your key is wrong?

I tested before with https://github.com/jasonacox/tinytuya

Maybe your get it a try. There is a simple monitor example u can try.