I realize that this isn’t going to be an option for everyone because not everyone has a rooted Android Device laying around that they can instrument to grab the keys but just wanted to document another method I recently used to get the Local Keys to control the bulb as the tuya-cli method doesn’t seem to reliably work anymore.
I had an old Nexus 7 2012 Tablet that I loaded with crDroid, rooted and then installed the Sylvania Smart WiFi App. I used the 1.0.0 version of the com.ledvance.smart.wifi. Followed by pairing the bulb with my Sylvania Smart Account so that it was showing in the app.
In order to extract the Local Key I needed to download the latest version of frida-server from Releases · frida/frida · GitHub where I used the frida-server-16.0.11-android-arm.xz version. Extract the file and rename it to frida-server. Make sure you also install the frida-tools on your local machine, I’m using a MacBook Pro and installed the tools with
pip install frida-tools
Connect the Android device to your computer and check to make sure that the device shows in adb:
adb devices
List of devices attached
015d2a50401c0609 device
Once you can see the device then you can push frida-server to it using adb, make it executable and then run it:
adb push frida-server /data/local/tmp/frida-server
adb shell "chmod 755 /data/local/tmp/frida-server"
adb shell "/data/local/tmp/frida-server &"
Once frida-server is running on the Android device open the Sylvania App and make sure you’re logged in and that your Smart Bulbs are paired and showing. If they aren’t paired to the app yet, do that now. Since it’s cloud based you can pair it from any device. Once the device you want the localKey is showing in the app, might need to pull down to refresh then start frida-trace on your local computer keeping the Sylvania Smart App open on the Android Device.
frida-trace -U --decorate -j '*!*getLocalKey' -F
Once the client is running you should see that it Instruments the running application and in my case it traced 9 functions as seen by the following output:
Started tracing 9 functions. Press Ctrl+C to stop.
Now just interact with your bulb in the Sylvania Smart App and frida-trace will spit out the localKey and it will look something like the following:
/* TID 0xb3a */
5383 ms DeviceBean.getLocalKey()
5383 ms <= "<localKey>"
5810 ms TuyaSmartServerManager.getLocalKey("smart/mb/in/<Virtual ID>")
5813 ms | DeviceBean.getLocalKey()
5813 ms | <= "<localKey>"
5814 ms <= "<localKey>"
That’s it, you can then go into Local Tuya on Home Assistant and add the device manually with the associated Virtual ID and localKey that you now have extracted.
I still mapped the same parameters that I used before when asked by the Local Tuya Integration:
id: 20
color_mode: 21
brightness: 22
color_temp: 23
color: 24
brightness_lower: 10
brightness_upper: 1000
color_temp_min_kelvin: 2700
color_temp_max_kelvin: 6500
scene: 25
Hope this helps people in disconnecting themselves from the Cloud!