rospogrigio / localtuya

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

weird behavior, 1 of 3 smart plug cannot connected #313

Open tjengbudi opened 3 years ago

tjengbudi commented 3 years ago

hello, i have 3 smart plug by tuya system. and 2 of them is working properly. one of them have weird behavior. it looks like something in the process have some chinese character.

the error i get is

021-01-14 08:23:02 ERROR (MainThread) [custom_components.localtuya.common] [eb1...hz1] Connect to 192.168.1.113 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 557, in _decode_payload
payload = payload.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 3: invalid continuation byte

the 2 of them is connected properly, i got that error with text configuration. with ide wizard, just get error cannot authorized could you help me about this. i try to change the decoding (decode('utf-8'), error='ignore') but looks like i just do not know what i am doing

looks like it is bugs for some devices

tjengbudi commented 3 years ago

btw i trying the tuyadebug and it can received the dps status from there. so i am sure devId and localKey is OK.

ultratoto14 commented 3 years ago

Can you post the DPS dump, you configuration and maybe some logs with the message localtuya is trying to decode (in debug mode) ?

tjengbudi commented 3 years ago

this is my setting in configuration.yaml for the smart plug. the ip, localkey and devid will be deleted

  - host: "192.168.x.x"
    device_id: ""
    local_key: ""
    friendly_name: "Plug"
    protocol_version: "3.3"
    entities:
      - platform: "switch"
        friendly_name: "Plug Piano 2"
        id: 1
        current: 18 # Optional
        current_consumption: 19 # Optional
        voltage: 20 # Optional

this is the dps dump

TuyaDebug (Tuya DPs dump) [1.0.0]

Device eb at 192.168.x.x key ax protocol 3.3 dev_type type_0d:
    DPS [1] VALUE [True]
    DPS [9] VALUE [0]
    DPS [18] VALUE [0]
    DPS [19] VALUE [0]
    DPS [20] VALUE [2290]
    DPS [21] VALUE [1]
    DPS [22] VALUE [607]
    DPS [23] VALUE [26657]
    DPS [24] VALUE [15089]
    DPS [25] VALUE [1380]
    DPS [26] VALUE [0]

and this is the debug

2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.x.x', 'gwId': '', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': '', 'version': '3.3'}
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya] Device  found with IP 192.168.x.x
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.common] [eb1...hz1] Connecting to 192.168.x.x
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Started heartbeat loop
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Sending command heartbeat (device type: type_0a)
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Send payload: b'{}'
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Waiting for sequence number -100
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211)
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Got heartbeat response
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.common] [eb1...hz1] Retrieving initial state
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Sending command status (device type: type_0a)
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Send payload: b'{"gwId":"","devId":""}'
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Waiting for sequence number 1
2021-01-14 08:23:01 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Decrypted payload: {}
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Dispatching message TuyaMessage(seqno=1, cmd=10, retcode=1, payload=b'{S\x05\xc8wx\t\x90\xbd6fb\xe8\xd1x\xbba\xffk\xeb\xe7\x89\xb0\xbb>S\xf9\xccF[g\x16', crc=1633524815)
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Dispatching sequence number 1
2021-01-14 08:23:02 ERROR (MainThread) [custom_components.localtuya.common] [eb1...hz1] Connect to 192.168.1.113 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 557, in _decode_payload
payload = payload.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 3: invalid continuation byte
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Closing connection
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Stopped heartbeat loop
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [eb1...hz1] Connection lost: None
2021-01-14 08:23:02 DEBUG (MainThread) [custom_components.localtuya.common] [eb1...hz1] Disconnected - waiting for discovery broadcast