Dear all:
After 6 months of struggling (literally), I FINALLY got tuya-based switch to work.
The following is instruction to get it work:
1) For early adapter, or those who tried so hard to trying to get tuya-based switch to work in the past, the very first step is to make sure you REMOVE the custom tuya components you at one time downloaded from
https://github.com/sean6541/tuya-homeassistant
As of Home Assistant 0.74.0, tuya component is built in. You absolutely need to remove the custom component or entire HA is going to shorten your life span.
2) get the device ID and local keys. There are plenty of post show you how to do this, different methods can be used. The method I used is the one posted on this thread by boggiano simply because I rooted all my phones so this wasn’t a problem. All the info is in the following file in your android phone if you installed “Smart Life” app:
/data/data/com.tuya.smartlife/shared_prefs/dev_data_storage.xml
There are a couple pitfalls to watch out for. First, there are many information out there, the two absolutely needed are devId and localKey Let me repeat this, what you are looking for is devId, AND localKey . There are other attributes such as uuid and key. And for our purpose, they only exist to confuse the weak minds. Second pitfall is that this localKey do changes if you decided to switch apps to control tuya-based devices (exactly when the localKey changes is something I still don’t exactly know). Since there are plenty of apps (efamilyCloud, Smartlife, tuya, jimvoo, etc) that control tuya, I recommend you stick with ONE app to avoid localkey being changed without your knowledge.
3) Once you have all the deviceID and localKeys ready, you need to put these into your configuration.yaml file:
tuya:
username: XXX
password: YYY
country_code: ZZ
In the switch section, there are two formats which both work:
switch:
- platform: tuya
host: your_local_IP_address
local_key: yourKey
device_id: yourDevID
friendly_name: switchName
optimistic: 1 // I have no idea what is this for
id: 1
The following format would work too: I think this is for those tuya device which has multiple outlet/swtich in one device:
switch:
- platform: tuya
host: yourLoacalIP
device_id: deviceID
local_key: localKey
switches:
switch1:
friendly_name: nightLight
id: 1
That is it.
Good luck