jasonacox / tinytuya

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

Problem with connect to devices 3.4 version #258

Open rafalolb opened 1 year ago

rafalolb commented 1 year ago

I used tinytuya with 1.9.1 version. I have 4 devices (all 2 gang switch).

The devices are discovered by tiny tuya:

C:\Users\Rafał\Documents\Python>python -m tinytuya scan

TinyTuya (Tuya device scanner) [1.9.1]

Scanning on UDP ports 6666 and 6667 for devices (15 retries)...

Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.31,  Device ID = bfbe6637e3072c3743p0ad, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.31: DEVICE KEY required to poll for status
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.32,  Device ID = bfd0cc11c6a0ec7f43kyvg, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.32: DEVICE KEY required to poll for status
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.33,  Device ID = bf5060f9c36fa0a2c6etgm, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.33: DEVICE KEY required to poll for status
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.34,  Device ID = bfcb5f0ada537c9629ewob, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.34: DEVICE KEY required to poll for status
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.35,  Device ID = bfa288a9a1ef4927edqpst, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.35: DEVICE KEY required to poll for status

Scan Complete!  Found 5 devices.

I get local key from iot.tuya.com and I have a problem with get status. I get error:

C:\Users\Rafał\Documents\Python>python localtuya2.py
Device status: {'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}

My localtuya.py file:

# Example Usage of TinyTuya
import tinytuya

# d = tinytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
d = tinytuya.OutletDevice('bfbe6637e3072c3743p0ad', '192.168.10.31', 'my_key_from_iot_tuya')
d.set_version(3.4)
data = d.status()
print('Device status: %r' % data)

When I used tinytuya first time about 1 month ago, I get valid status from device. What happened? I need help.

rafalolb commented 1 year ago

Of course, the devices works fine in tuya app and Home Assistant connected by account in iot.tuya.com.

jasonacox commented 1 year ago

Hi @rafalolb can you try this to give us a bit more data?

First, make sure your devices.json file is up to date and in the same directory. The first scan above indicates that your devices.json doesn't have they key for that device (running python3 -m tinytuya wizard will pull down the latest keys). Next, run this from python3:

import tinytuya 

tinytuya.set_debug(True)
tinytuya.scan()

As to why TuyaApp and (depending on which integration you use) HA work s? Both will use the cloud to connect with these devices. TinyTuya is attempting local control.

Also, can you paste a link to this particular device (2-gang switch)? I'm looking for new v3.4 devices for testing.

rafalolb commented 1 year ago

Hi @jasonacox, tnx for reply.

My logs from 1 device (3.4 version):

C:\Users\Rafał\Documents\Python>python localtuya4zNeta.py
DEBUG:TinyTuya [1.9.1]

DEBUG:loaded=devices.json [1 devices]

TinyTuya (Tuya device scanner) [1.9.1]

[Loaded devices.json - 1 devices]

Scanning on UDP ports 6666 and 6667 for devices (16 retries)...

DEBUG:Listening for Tuya devices on UDP 6666 and 6667
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
Unknown v3.3 Device   Product ID = mPRaDY6QmEFXOTYm  [Valid payload]:
    Address = 192.168.10.30,  Device ID = 30042051a4cf12d545ac, Local Key = ,  Version = 3.3, MAC =
    No Stats for 192.168.10.30: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.34,  Device ID = bfcb5f0ada537c9629ewob, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.34: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.31,  Device ID = bfbe6637e3072c3743p0ad, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.31: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.32', 'gwId': 'bfd0cc11c6a0ec7f43kyvg', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.32,  Device ID = bfd0cc11c6a0ec7f43kyvg, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.32: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.35', 'gwId': 'bfa288a9a1ef4927edqpst', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
wentylator   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.35,  Device ID = bfa288a9a1ef4927edqpst, Local Key = my_local_key,  Version = 3.4, MAC = fc:67:1f:45:f3:53
DEBUG:status() entry (dev_type is v3.4)
DEBUG:building command 10 payload=b'{"gwId":"bfa288a9a1ef4927edqpst","devId":"bfa288a9a1ef4927edqpst","uid":"bfa288a9a1ef4927edqpst","t":"1674283959"}'
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000001000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff4949ad5df88d8f343b8185c4e31acf8716cb31191e30d9f9050e37ad9419a2290000aa55'
DEBUG:_recv_all(): no data? b''
DEBUG:received null payload (None), fetch new one - 1 retries remaining
DEBUG:received null payload (None) but out of recv retries, giving up
DEBUG:session key negotiation failed on step 1
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000002000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9fff2b4f02a3a3f26d81cbd1892bc892a4f8c084fe02ca47624670a02a2c93942780000aa55'
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:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000003000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff027e21b55bb33be330cef2a79736e32ef5fe9091e5ab30d4cebc6583b49071430000aa55'
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:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000004000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff68e3161a41aa88b5328f8a5c8ac6a0b55a0adadb8eb6499266097420dd906b6a0000aa55'
DEBUG:_recv_all(): no data? b''
DEBUG:received null payload (None), fetch new one - 1 retries remaining
DEBUG:received null payload (None) but out of recv retries, giving up
DEBUG:session key negotiation failed on step 1
DEBUG:sending payload quick
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000005000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff33ba5c0875356edb2b57210a26d2644a5dbf27bc447694a2110d7525d95d9a650000aa55'
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 Network Error: Device Unreachable - 905 - payload: null
DEBUG:status() received data={'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}
    Access rejected by 192.168.10.35: Network Error: Device Unreachable
DEBUG:Received valid UDP packet: {'ip': '192.168.10.33', 'gwId': 'bf5060f9c36fa0a2c6etgm', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid payload]:
    Address = 192.168.10.33,  Device ID = bf5060f9c36fa0a2c6etgm, Local Key = ,  Version = 3.4, MAC =
    No Stats for 192.168.10.33: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.32', 'gwId': 'bfd0cc11c6a0ec7f43kyvg', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.35', 'gwId': 'bfa288a9a1ef4927edqpst', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.33', 'gwId': 'bf5060f9c36fa0a2c6etgm', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}

Scan Complete!  Found 6 devices.

>> Saving device snapshot data to snapshot.json

DEBUG:Scan complete with 6 devices found

C:\Users\Rafał\Documents\Python>

5 another logs are the same.

I buyed 3 different device (1 device have 2 gang switch) from China and one (1 gang switch). Link from 2 gang devices (log from IP 192.168.10.35):

  1. https://pl.aliexpress.com/item/1005004732318304.html?spm=a2g0o.order_list.order_list_main.22.21ef1c24YQSQ5S&gatewayAdapt=glo2pol
  2. https://shopee.pl/Smatrul-16A-1-2-Gang-Tuya-WiFi-Prze%C5%82%C4%85cznik-Bluetooth-Inteligentne-%C5%9Awiat%C5%82o-Mini-2-dro%C5%BCny-modu%C5%82-Prze%C5%82%C4%85cznik-czasowy-Odpowiedni-dla-Google-Home-Alexa-i.573465537.12347304908
  3. https://pl.aliexpress.com/item/1005004500129457.html?spm=a2g0o.order_list.order_list_main.5.21ef1c24YQSQ5S&gatewayAdapt=glo2pol

My 1 gang device (log from IP 192.168.10.30), I buyed it 5-6 years ago, and works great

rafalolb commented 1 year ago

And another log from 1.10.0 version of tinytuya:

C:\Users\Rafał\Documents\Python>python localtuya4zNeta.py
DEBUG:TinyTuya [1.10.0]

DEBUG:loaded=devices.json [1 devices]

TinyTuya (Tuya device scanner) [1.10.0]

[Loaded devices.json - 1 devices]

Scanning on UDP ports 6666 and 6667 and 7000 for devices for 18 seconds...

DEBUG:Listening for Tuya devices on UDP 6666 and 6667 and 7000
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid Broadcast]:
    Address = 192.168.10.34   Device ID = bfcb5f0ada537c9629ewob (len:22)  Local Key =   Version = 3.4  Type = default, MAC =
    No Stats for 192.168.10.34: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid Broadcast]:
    Address = 192.168.10.31   Device ID = bfbe6637e3072c3743p0ad (len:22)  Local Key =   Version = 3.4  Type = default, MAC =
    No Stats for 192.168.10.31: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.32', 'gwId': 'bfd0cc11c6a0ec7f43kyvg', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid Broadcast]:
    Address = 192.168.10.32   Device ID = bfd0cc11c6a0ec7f43kyvg (len:22)  Local Key =   Version = 3.4  Type = default, MAC =
    No Stats for 192.168.10.32: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
Unknown v3.3 Device   Product ID = mPRaDY6QmEFXOTYm  [Valid Broadcast]:
    Address = 192.168.10.30   Device ID = 30042051a4cf12d545ac (len:20)  Local Key =   Version = 3.3  Type = default, MAC = a4:cf:12:d5:45:ac
    No Stats for 192.168.10.30: DEVICE KEY required to poll for status
DEBUG:Received valid UDP packet: {'ip': '192.168.10.35', 'gwId': 'bfa288a9a1ef4927edqpst', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.33', 'gwId': 'bf5060f9c36fa0a2c6etgm', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Unknown v3.4 Device   Product ID = keyjnuy4s3kre7m7  [Valid Broadcast]:
    Address = 192.168.10.33   Device ID = bf5060f9c36fa0a2c6etgm (len:22)  Local Key =   Version = 3.4  Type = default, MAC =
    No Stats for 192.168.10.33: DEVICE KEY required to poll for status
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000001000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff4949ad5df88d8f343b8185c4e31acf8716cb31191e30d9f9050e37ad9419a2290000aa55'
read_data() failed, retrying 192.168.10.35
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000001000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff4949ad5df88d8f343b8185c4e31acf8716cb31191e30d9f9050e37ad9419a2290000aa55'
read_data() failed, retrying 192.168.10.35
DEBUG:final payload: b'0123456789abcdef'
DEBUG:payload encrypted=b'000055aa00000001000000030000004421b4201c0d907e9c4f2ec72aedc67ab485fa9ef592866b49418151a11300f9ff4949ad5df88d8f343b8185c4e31acf8716cb31191e30d9f9050e37ad9419a2290000aa55'
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.32', 'gwId': 'bfd0cc11c6a0ec7f43kyvg', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.35', 'gwId': 'bfa288a9a1ef4927edqpst', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
wentylator   Product ID = keyjnuy4s3kre7m7  [Valid Broadcast]:
    Address = 192.168.10.35   Device ID = bfa288a9a1ef4927edqpst (len:22)  Local Key = my_local_key  Version = 3.4  Type = default, MAC = fc:67:1f:45:f3:53
    Polling 192.168.10.35 Failed: No response
DEBUG:Received valid UDP packet: {'ip': '192.168.10.33', 'gwId': 'bf5060f9c36fa0a2c6etgm', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.32', 'gwId': 'bfd0cc11c6a0ec7f43kyvg', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.30', 'gwId': '30042051a4cf12d545ac', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'mPRaDY6QmEFXOTYm', 'version': '3.3'}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.35', 'gwId': 'bfa288a9a1ef4927edqpst', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.33', 'gwId': 'bf5060f9c36fa0a2c6etgm', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.34', 'gwId': 'bfcb5f0ada537c9629ewob', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True}
Scan completed in 18.0768 seconds

Scan Complete!  Found 6 devices.
Broadcasted: 6
Versions: 3.3: 1, 3.4: 5
Unknown Devices: 5

>> Saving device snapshot data to snapshot.json

DEBUG:Scan complete with 6 devices found

C:\Users\Rafał\Documents\Python>
jasonacox commented 1 year ago

Hi @rafalolb !

[Loaded devices.json - 1 devices] .... Scan Complete! Found 6 devices.

It looks like you are missing local keys for all 5 of these 3.4 devices and the 3.3 device says the key is missing. I suspect all 6 keys are bad. If you removed or added these devices again to your SmartLife app, they will get new keys (the old ones will stop working). I would run:

python3 -m tinytuya wizard

That will pull down your new keys from the cloud.

Your previous notes showed you trying to access bfbe6637e3072c3743p0ad direction - notice it says it is missing a key for this devices in the devices.json file:

DEBUG:Received valid UDP packet: {'ip': '192.168.10.31', 'gwId': 'bfbe6637e3072c3743p0ad', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'keyjnuy4s3kre7m7', 'version': '3.4', 'token': True, 'wf_cfg': True} Unknown v3.4 Device Product ID = keyjnuy4s3kre7m7 [Valid payload]: Address = 192.168.10.31, Device ID = bfbe6637e3072c3743p0ad, Local Key = , Version = 3.4, MAC = No Stats for 192.168.10.31: DEVICE KEY required to poll for status

You will need the key to connect to these devices. Once you have the updated key, run the scan again or try direct:

# Example Usage of TinyTuya
import tinytuya

# d = tinytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE')
d = tinytuya.OutletDevice('bfbe6637e3072c3743p0ad', '192.168.10.31', 'my_key_from_iot_tuya')
d.set_version(3.4)
data = d.status()
print('Device status: %r' % data)
rafalolb commented 1 year ago

Hi @jasonacox, tnx for reply.

Device of 3.3 version works great (device have 1 gang). Devices of 3.4 version doesn't works (devices have 2 gangs).

I removed 5 devices from my "devices.json" becouse the other devices (2 gang) have the same logs - I wrote about this (maybe added not good description, I'm sorry). Look and check only device 192.168.10.35 in my 2 last comments, please. I can send you my localkey of device 192.168.10.35 in private message. If you get my localkey, can you to decode the payload?

I suspect that, problem is with the 2 gang switches.

I can change my localkey (using SmartLife app), but it's not easy, becouse my switches are located in box in wall.

uzlonewolf commented 1 year ago

Can you try shutting off the circuit they're on via the fuse or circuit breaker, waiting a few seconds, and turning them back on? Sometimes they just need to be rebooted.

rafalolb commented 1 year ago

I'm getting an extra 2 switches in about two weeks. I'll check then.

Poil commented 1 year ago

Hi,

I'm my case 3.4 works fine some hours and after I have this message too Device status: {'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}

I have to unplug/plug back my device. Also in smartapp it still working when no more working with tinytuya.

Regards

black-dragon74 commented 1 year ago

For people facing issues with 3.4 devices, just reboot the device. Nothing else seems conclusive.

I am working on a homebridge plugin that is based off of tiny tuya. Power cycling the device fixes it, always.

[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Loaded homebridge-tuya-rgb-interface v1.1.1 child bridge successfully
[2/1/2023, 8:47:50 AM] Loaded 0 cached accessories from cachedAccessories.0EDC51677212.
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Initializing platform...
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] didFinishLaunching called. Gonna discover devices now...
[2/1/2023, 8:47:50 AM] Homebridge v1.6.0 (HAP v0.11.0) (homebridge-tuya-rgb-interface) is running on port 58886.
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Found 3 local devices from the bridge
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Initializing TuyaBulb http://localhost:8586
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Initializing TuyaBulb http://localhost:8586
[2/1/2023, 8:47:50 AM] [homebridge-tuya-rgb-interface] Initializing TuyaBulb http://localhost:8586
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Power state changed to false
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Online state changed to true
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Device came back online!
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Power state changed to false
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Online state changed to true
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Device came back online!
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Power state changed to false
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Online state changed to true
[2/1/2023, 8:47:56 AM] [homebridge-tuya-rgb-interface] Device came back online!

If you used Smartlife app to control the device (locally) when tiny tuya was not working, then also it is recommended to power cycle the device.

Regards

rafalolb commented 1 year ago

I get 2 extra switches and configured them. I turned off the circuit breaker. I also disable iot.tuya cloud integration with the home assistant. Now all devices have been working since 10 days.

jasonacox commented 1 year ago

disable iot.tuya cloud integration with the home assistant

@rafalolb thanks for the update. Rebooting seems to help as @black-dragon74 mentions, but this is new information. I don't know enough about the Tuya Cloud integration with HA to know if that could be a cause too. Good observation in any case. Thanks!

hamed-jamali-software commented 2 months ago

bug

tinytuya.set_debug(True)

tinytuya.scan()

DEVICEID = "bf5e9d230926e6b12fojsu" DEVICEIP = "192.168.43.16" DEVICEKEY = "key8u54q9dtru5jw" DEVICEVERS = "3.4"

DEVICEID = os.getenv("DEVICEID", DEVICEID) DEVICEIP = os.getenv("DEVICEIP", DEVICEIP) DEVICEKEY = os.getenv("DEVICEKEY", DEVICEKEY) DEVICEVERS = os.getenv("DEVICEVERS", DEVICEVERS)

uzlonewolf commented 2 months ago

DEVICEKEY = "key8u54q9dtru5jw"

That's a product id, not a secret key. Run the wizard and copy the key from the resulting devices.json file.

hamed-jamali-software commented 2 months ago

The key cannot be created

{ "timestamp": 1724104035.3054733, "devices": [ { "id": "bf5e9d230926e6b12fojsu", "ip": "192.168.43.16", "active": 2, "encrypt": true, "productKey": "key8u54q9dtru5jw", "token": true, "wf_cfg": true, "name": "", "key": "", "mac": "", "ability": 0, "dev_type": "default", "origin": "broadcast", "ver": "3.4" } ] }

(.venv) PS E:\project\smartki> python -m tinytuya scan -d Parsed args: Namespace(debug=False, command='scan', debug2=True, max_time=None, force=None, no_broadcasts=False, nocolor=False, yes=False, device_file='devices.json', snapshot_file='snapshot.json') DEBUG:TinyTuya [1.15.1]

DEBUG:Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 DEBUG:Using pyca/cryptography 43.0.0 for crypto, GCM is supported

TinyTuya (Tuya device scanner) [1.15.1]

Scanning on UDP ports 6666 and 6667 and 7000 for devices for 18 seconds...

DEBUG:Listening for Tuya devices on UDP ports 6666, 6667 and 7000 DEBUG:Sending discovery broadcast from '192.168.43.44' to '255.255.255.255' on port 7000 DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} New Broadcast from App at 192.168.43.44 - {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'ip': '192.168.43.16', 'gwId': 'bf5e9d230926e6b12fojsu', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'key8u54q9dtru5jw', 'version': '3.4', 'token': True, 'wf_cfg': True} Unknown v3.4 Device Product ID = key8u54q9dtru5jw [Valid Broadcast]: Address = 192.168.43.16 Device ID = bf5e9d230926e6b12fojsu (len:22) Local Key = Version = 3.4 Type = default, MAC = No Stats for 192.168.43.16: DEVICE KEY required to poll for status DEBUG:Sending discovery broadcast from '192.168.43.44' to '255.255.255.255' on port 7000 DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'ip': '192.168.43.16', 'gwId': 'bf5e9d230926e6b12fojsu', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'key8u54q9dtru5jw', 'version': '3.4', 'token': True, 'wf_cfg': True} DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'ip': '192.168.43.16', 'gwId': 'bf5e9d230926e6b12fojsu', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'key8u54q9dtru5jw', 'version': '3.4', 'token': True, 'wf_cfg': True} DEBUG:Sending discovery broadcast from '192.168.43.44' to '255.255.255.255' on port 7000 DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'from': 'app', 'ip': '192.168.43.44'} DEBUG:Received valid UDP packet: {'ip': '192.168.43.16', 'gwId': 'bf5e9d230926e6b12fojsu', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'key8u54q9dtru5jw', 'version': '3.4', 'token': True, 'wf_cfg': True} Scan completed in 18.043 seconds

Scan Complete! Found 1 devices. Broadcasted: 1 Versions: 3.4: 1 Unknown Devices: 1

Saving device snapshot data to snapshot.json

jasonacox commented 2 months ago

You will need to get the local key (and the devices.json file) by running the wizard:

python3 -m tinytuya wizard

Is this not working? There are some alternative method to get the local key (via the Tuya IoT portal or google search for tools that can help).