jasonacox / tinytuya

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

Ledvance smart plug fetching and pairing issue #150

Closed devmet34 closed 1 year ago

devmet34 commented 2 years ago

Hello,

I paired Ledvance smart+ wifi plug with its own app on android. Its working ok. I tried tuyapower py. It scans find and outputs all the parameters including plugkey something like "keyj5dhdbjch". When i try to get device info with given parameters, it says no power data. I suppose plugkey is not the actual key?

I reset the device and tried to pair with both smart life and tuya smart app but it fails. During manual pairing with smart life or tuya smart app, device's led stops blinking but app fails to pair with timeout even though device connects to wifi router.

Appreciate helps. Thanks

jasonacox commented 2 years ago

Hi @devmet34, thanks for opening this issue. Can you also post a link to the specific device in case others see this?

You are correct. PlugKey (aka Product Key, Product ID) is essentially a device SKU but is not the local security KEY used to encrypt communication. When you set up a device using the App (e.g. Smart Life or Tuya Smart), a local key is created and the device is paired with the Tuya Cloud. That key is stored on the device and in the Tuya Cloud. The instructions to fetch the key is not simple, unfortunately, but if you have a Tuya compatible plug and you follow the steps it does work: https://github.com/jasonacox/tinytuya#setup-wizard---getting-local-keys

However, I'm not sure your device is compatible. You could still try the instructions to see if the Ledvance app would work. Unfortunately, it is likely not going to work. A quick search and I see several post in reddit.com about people not getting Ledvance devices to work with the Tuya ecosystem. I do wonder what they are doing.

Has anyone else had any luck with these devices?

devmet34 commented 2 years ago

Hey Jason, thanks for the quick reply. The model name and link given below. I'll try that method and post the result. If it doesnt work, which i too think it wont work, is there any workaround for getting the key from device. It's probably encrypted so cant sniff it. Maybe ledvance support can help? Or is there any other way to get power info like using ifttt, web api, mqtt etc. with given ledvance cloud credentials?

Device model: AC27825 Official link: https://www.ledvance.com/consumer/products/smart-home/smart-home-products-with-wifi-technology/smart-home-components/plug-with-smart-socket-to-control-non-smart-devices-with-wifi-technology--pairable-with-remote-controller-c6482

jasonacox commented 2 years ago

Thanks @devmet34 - appreciate the link!

I think you have some good ideas here. I don't have any of these devices so I don't have a way of testing or helping. I wish there was a better way to get these KEYs (even for traditional Tuya devices). Some thoughts I have:

Thanks again for opening this and keeping us all updated on your discovery!

devmet34 commented 2 years ago

Hi Jason, i tried all the methods but failed as expected. I found a way to get local key for the device using an old app version with frida on a rooted device. I can try it to get local key. But here is the question; if i got the key, will it 100% work to get voltage/consumption readings from the device? Cheers

devmet34 commented 2 years ago

Ok got the answer it seems like yes its working :)

devmet34 commented 2 years ago

Many thanks to you and other contributors.

jasonacox commented 2 years ago

Awesome! Thanks @devmet34 ! Can you share the method you used to get the keay?

devmet34 commented 2 years ago

Yea thanks to Francesco, below are the links. Basically, you sniff local key data using frida and ledvance app on a rooted device.

https://community.home-assistant.io/t/howto-ledvance-smart-plug-wifi-in-home-assistant-solution/350280

https://community.home-assistant.io/t/ledvance-wifi-bulbs/301478/6

jasonacox commented 2 years ago

Thanks @devmet34 ! Great tip. And just to confirm, you are able to get status and control this Ledvance device with TinyTuya once you had those keys?

devmet34 commented 2 years ago

Yes, i can get power values with the key. Cheers