jasonacox / tinytuya

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

Power Clamp error #497

Closed darckat038 closed 1 month ago

darckat038 commented 1 month ago

Hi, i'm getting {'Error': 'Check device key or version', 'Err': '914', 'Payload': None} when trying to access the status of my tuya 3 phase power clamp. Here is the code:

import tinytuya

#Connect to Device
d = tinytuya.OutletDevice(
    dev_id='bf7e7e409fbda19014zwrs',
    address='192.168.2.80',
    local_key=")7@;aNs%`?5`])R)",
    version=3.4)

def getStatus(o):
    status = o.receive()
    return status

print(getStatus(d))

I already checked the key and version with the "wizard" and they are correct. Recently i updated that device with the latest firmare. Could that be the problem? Also i would like to point out that i'm using the power clamp on the Smart Life app. Thanks for the help.

jasonacox commented 1 month ago

Hi @darckat038 - some suggestions:

darckat038 commented 1 month ago

Thanks for the fast answer. However i did as you said and:

DEBUG:Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32 DEBUG:Using pyca/cryptography 42.0.5 for crypto, GCM is supported DEBUG:sending payload quick DEBUG:final payload: b'0123456789abcdef' DEBUG:payload encrypted=b'000055aa0000000100000003000000441bbe5d9b00db73758c880f324d0f9e45948caf4fbef52658d664fb5b7610980b7078fb1d2e19988fc92ba813e8a18beecdbd4471b57726a5f3ad10c7563ef4b60000aa55' DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:received null payload (None), fetch new one - 1 retries remaining DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:received null payload (None) but out of recv retries, giving up DEBUG:session key negotiation failed on step 1 DEBUG:ERROR Check device key or version - 914 - payload: null {'Error': 'Check device key or version', 'Err': '914', 'Payload': None}

jasonacox commented 1 month ago

I should have noticed this before, but your code is only using the receive() function. I don't see where you are sending the request for status. I would try something like:

import tinytuya
tinytuya.set_debug(True)

# Connect to Device
d = tinytuya.OutletDevice(
    dev_id='DEVICE_ID_HERE',
    address='IP_ADDRESS_HERE',
    local_key='LOCAL_KEY_HERE', 
    version=3.3)

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

it was able to poll the device but it displayed No Response

Ugh. It would be good to confirm if a power cycle fixes this. Can you post a link to the Tuya "3 phase power clamp" that you are using? At a minimum it would be good to see if anyone in the community has one and has had success at getting it to work.

darckat038 commented 1 month ago

Hey, sorry for my delay in the response. However i managed to solve the problem, i don't know how exactly, but i think the power clamp only needed to be powered off and then on. Thanks for the help.