As most of you know tuya is rolling out updates which stops Tuya convert from working correctly. however i have put together this tutorial on how to get tuya local control to work.
First of all you will need your local key and device id. Follow these steps.
Install Bluestacks (find a link on the Bluestacks Tweaker page)
Root Bluestacks: BmB8I63ea-o at YouTube
Install SmartLife version 3.6.1 using an APK (newer versions seem to be hiding the key and localKey data we need)
Install ES File Explorer
Click the three lines at the top and scroll down and enable “Root Explorer” then click allow
permission from superuser
Navigate to the app’s data directory (in my case, /data/data/com.tuya.smartlife/shared_prefs
Open preferences_global_key(numbers and characters).xml
Highlight and copy and paste to word then use “Ctrl and f” to use the find tool to search for
local and id key
Write these down along with each device’s IP
Next we need to setup the python script, this acts as a tuya server and allows us to control our tuya devices
use the samba addon to add it to hassio, create a "custom_components"folder under the
config directory, inside it paste the “localtuya” folder and restart hassio
3 your done
Now add your switch to home assistant to control it
1.add this to your config file and replace dev id, localkey and IP with yours
Notes
if you have multiple plugs add them one at a time so finding the local key and device id is easier
local and devids change when you re add you tuya device
your dev id is longer than local key
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 261, in async_update_ha_state
await self.async_device_update()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 441, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/localtuya/light.py”, line 220, in update
status = self._device.status(self._bulb_id)
File “/config/custom_components/localtuya/light.py”, line 122, in status
self._cached_status = self.__get_status(switchid)
File “/config/custom_components/localtuya/light.py”, line 92, in __get_status
status = self._device.status()[‘dps’][switchid]
File “/config/custom_components/localtuya/pytuya/init.py”, line 311, in status
result = json.loads(result)
File “/usr/local/lib/python3.7/json/init.py”, line 348, in loads
return _default_decoder.decode(s)
File “/usr/local/lib/python3.7/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/local/lib/python3.7/json/decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I’ve followed this guide exactly to enable me to find my devices Local & ID Keys but I cannot find the information in the preferences_global_key.xml file or any of the other files in the folder.
Is obtaining the keys still possible?
I got excited when i saw this working. however if i use switch: i get a startup error
2020-01-21 22:53:12 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for localtuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2020-01-21 22:53:14 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform localtuya
File "/config/custom_components/localtuya/switch.py", line 68, in setup_platform
File "/config/custom_components/localtuya/switch.py", line 129, in __init__
File "/config/custom_components/localtuya/switch.py", line 111, in status
File "/config/custom_components/localtuya/switch.py", line 87, in __get_status
File "/config/custom_components/localtuya/pytuya/__init__.py", line 311, in status
If i use light:, i get an error when trying to change its status as per @francisp
Thanks for replying but I ended up moving away from using Tuya local and started custom firmware flashing my plugs with Tuya-Convert as was suggested by many people on this forum. I flash them with tasmota and after I had done 1 I never looked back, I’ve done over 20 plugs, about 10 bulbs and a couple of LED controllers.
Thanks anyway
Take a look at https://github.com/TradeFace/tuyamqtt/ That might solve your problem. I be releasing v1.1 in a few days. TuyaFace ( the library to connect to the devices was released yesterday v1.3.1)