jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

Cannot get status of a new device #365

Closed fsutter closed 1 year ago

fsutter commented 1 year ago

Hi,

I own 2 Konyks Priska Max Easy FR (connected socket, product_id ux5gchwsd77db0fp) that I can access via tinytuya.

Recently I bought 2 more for a new room and I got the newer version: Konyks Priska Max Easy FR V3 (Light) (product_id zlsvppjacilyow0u). Even if I can access the two new devices from the Tuya smart app like previous ones, I cannot make them work with tinytuya.

I got this error: DEBUG:status() received data={'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}

#!/usr/bin/env python3

import tinytuya

def main():
    tinytuya.set_debug(True)

    device = tinytuya.OutletDevice(
        "xxxxxx", "192.168.1.173", "xxxxxxx"
    )
    device.set_version(3.3)

    # Get Status
    data = device.status()
    print(f"status() result: {data}")

if __name__ == "__main__":
    main()

Here is the console output:

DEBUG:TinyTuya [1.12.8]

DEBUG:Python 3.11.4 (main, Jun  7 2023, 00:42:15) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
DEBUG:Using PyCrypto (3, 18, '0')
DEBUG:status() entry (dev_type is default)
DEBUG:final payload_dict for 'bf7593e10fcb1a4b2cv6i3' ('v3.3'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'devId': '', 'uid': '', 't': ''}}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 13: {'command': {'devId': '', 'uid': '', 't': ''}}, 16: {'command': {'devId': '', 'uid': '', 't': ''}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}}
DEBUG:building command 10 payload=b'{"gwId":"bf7593e10fcb1a4b2cv6i3","devId":"bf7593e10fcb1a4b2cv6i3","uid":"bf7593e10fcb1a4b2cv6i3","t":"1686898947"}'
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000010000000a0000008863414d63962e520fc0c1c09cfed89482230ff6fafc241aa3a9b850b23682e27daa94f4cdd6e53b8e345fd5f81e6fea3c6632ad83d10c483b4fe61eaa3d3f804d920cc3a654ff69f99b43f188d9a4ae7c230ff6fafc241aa3a9b850b23682e27d680f970484c92f5bf7c81a69a7e57a0976d59e717ce071f1f49fdb3f53f705e83e648bcd0000aa55'
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 0/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 1/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 2/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 3/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 4/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 5/5
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 1049, in _send_receive
    rmsg = self._receive()
           ^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 939, in _receive
    data = self._recv_all( min_len )
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/PycharmProjects/test_tuya/venv/lib/python3.11/site-packages/tinytuya/core.py", line 920, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:ERROR Unexpected Payload from Device - 904 - payload: null
DEBUG:status() received data={'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}
status() result: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}

Many thanks in advance and kind regards,

uzlonewolf commented 1 year ago

Usually when the initial connection to the device succeeds but no response is received it means either the protocol version is wrong or the local key is wrong. New devices these days are almost always protocol v3.4 if not v3.5. Run the scanner to verify the version: python3 -m tinytuya scan

uzlonewolf commented 1 year ago

Hi @fsutter, were you able to get these to work?

fsutter commented 1 year ago

Hi @uzlonewolf, sorry I'm in vacation. Will test it as soon as I'm back home. Thanks

fsutter commented 1 year ago

Hi @uzlonewolf ,

thanks for the tip: new devices are of version 3.4!!!!! That was the problem.

Kind regards,

fsutter

uzlonewolf commented 1 year ago

That's great!

Since you got it working I'm going to close this out. Feel free to re-open it if you're still having problems.