Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TH sensors: json obj data unvalid #589

Open
fkonrad opened this issue Jan 28, 2025 · 4 comments
Open

TH sensors: json obj data unvalid #589

fkonrad opened this issue Jan 28, 2025 · 4 comments

Comments

@fkonrad
Copy link

fkonrad commented Jan 28, 2025

Hi,

I'm trying to get temp, humidity out of a ZY-TH02 sensor locally, It's correctly configured with the smart app, I've got the localkey,
but I'm not able to communicate with the sensor:

  • It broadcasts the "discovery" UDP packet for some time when I power it up (by placing the batteries) and then go idle.
Unknown v3.4 Device   Product ID = x3o8epevyeo3z3oa  [Valid Broadcast]:
    Address = 192.168.0.110   Device ID = bf76b1b98633be00c0zre6 (len:22)  Local Key =   Version = 3.4  Type = default, MAC = 
    No Stats for 192.168.0.110: DEVICE KEY required to poll for status
  • During that time I try to get the status with:
while(True):                                                                                                                                                                                                                                  
    d = tinytuya.OutletDevice('bf76b1b98633be00c0zre6', '192.168.0.110',  'xxx')                                                                                                                                                              
    d.set_version(3.4)                                                                                                                                                                                                                        
    data = d.status()                                                                                                                                                                                                                         
    print(data)                                                                                                                                                                                                                               
    data = d.status()                                                                                                                                                                                                                         
    print (data)

At the first round it get "json obj data unvalid" and switch to device22:

DEBUG:decrypted 3.x payload=b'json obj data unvalid'
DEBUG:payload type = <class 'bytes'>
DEBUG:'data unvalid' error detected: switching to dev_type 'device22'

The next rounds it keeps timeouting waiting for replies:

DEBUG:final payload: b'3.4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{"devId":"bf76b1b98633be00c0zre6","uid":"bf76b1b98633be00c0zre6","t":"1738028383","dps":{"1":null}}'
DEBUG:payload encrypted=b'000055aa000000060000000d000000a4e4c324393ba5b22ca63886763b3a7abfbd19a19f393870e47b686b2ccc5ab30ea373a7ac56258c6082d62d9ad46aa31106bae1c08d35739d35dde516429a204d06d0497c253bcb5f2f5134e6b0ca172a3828b10cceaee16823907cacfcf42f8f897a3124d6205d97887fa653d453e4255d965acdfccaf6314d1221e44cd7737d303036811af30f966af166d7dfb9dcd1a8ecccb18cbac1cf6064567545d962f40000aa55'
DEBUG:Timeout in _send_receive() - retry 1 / 5

Also it seems like that kind of device have been successfully used with LocalTuya here.

Do I miss anything here? Does somebody got any success with those devices?

Best Regards,

@jasonacox
Copy link
Owner

You may want to try the https://github.com/jasonacox/tinytuya/blob/master/examples/monitor.py script.

Also, you can specify device22 on initialization:

a = tinytuya.OutletDevice('here_is_my_key', '192.168.x.x', 'secret_key_here', 'device22', version=3.4)
data =  a.status()
print(data)

You could also set up a constant ping to the device once it comes online to keep it awake.

Note: Battery powered devices are not compatible with local access. They are designed to send their data to the cloud and go to sleep. If you get a local access to work, you are likely going to drain the battery fairly quickly. But good luck on your reserach!

@fkonrad
Copy link
Author

fkonrad commented Jan 30, 2025

Hi, ok thanks for your pointer.

What I had in mind actually was detecting the UDP broadcast and query the dps just after, (there is time to do it if the device doesn't have access to the tuya server.) Unfortunately that query packet isn't answered by the device, maybe the query is malformed or the BK7231N firmware has been programmed not to answer..

@jasonacox
Copy link
Owner

I suspect the UDP broadcast it sent when it wakes up to send an update to the cloud. But that's a clever approach. Let us know if you figure it out!

@uzlonewolf
Copy link
Collaborator

These things are cheap enough I went ahead and picked up a couple myself, they should be here later next week. Since they are responding with an 'unvalid' error they should be online long enough to poll them. Hopefully I can figure out what sort of magic sequence they're expecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants