Tuya switch

I simply mount the fs of the mobile phone on my PC, then copy/paste!
Of course, I am root on the phone.

would you spoon feed me on this one?

I used to use ftpfs and mount it on my linux.

how do you mount your mobile phone?

I simply plug the phone to USB, selecting MTP protocol on the phone and my linux mint mounts it.

1 Like

Have you seen the new HA component?

just found out that today (prior to your post). thank you.

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

3 Likes

Hello
I’m trying to get the tuya switch working. I followed the directions of the first few posts at top,
I’m running 0.49.1 ver not sure if I can have the custom_components folder on my setup,
If I can is there anything different I have to do for my setup. As HA will fails to load.

follow my instruction. it is relatively completely other than the part about getting the device ID and local key.

Hey Everybody,

First of: A big thank you to all those contributing to this platform that I just discovered yesterday. I have a small issue with the Tuya switches (I use a version from Smart Life). I am using a pre-loaded component in Hassio. I see the switches in my Home Assistant and I can toggle them. The proper switch will change state. However, as soon as it does, the slider in Home Assistant automatically slides back to the previous state. After this the switch no longer responds to HA. It does however still react to Google Assistant and/or the Smart Life app.

Any hints on how to fix this behaviour?

Thanks in advance and all the best!

Update: I have removed these switches from every app (smart life, google home) so only Hass.io has the interface. This does seem to improve behaviour. However it remains unpredictable. Sometimes the switches don’t react and then as soon as I restart Hass.io all commands that hadn’t been executed up to that point are fired in rapid succesion…

Hi,
I was able to access all my Jinvoo Smart plugs by following this guide and adding optional platform as ‘jinvoo_smart’.

hi there!
im new to HA. Therefor i struggle a lot.
I have a tuya switchan i set it up as “kngharv” told.
In my configuration.yaml under “switch:” i have following

  - platform: tuya
    host: 192.168.178.xxx
    local_key: f3a83578e8931xxx
    device_id: 01530667b4e62d517xxx
    switches:
      switch1:
        friendly_name:  schalter
        id: 1

BUT on HASSIO Webinterface there ist no switch visible. What can I do to switch on and off my device from webinterface.

Sorry for my horrible englisch :slight_smile:

I was able to use my tuya power strip via the cloud service but I’d like to keep things local. I was able to grab my local_key and device_id but it looks like HA no longer supports local connectivity. I’m on 0.83.2 and with the following switch settings:

  - platform: tuya
    name: powerstrip
    host: 192.168.1.239
    local_key: 6555asdfasdff02
    device_id: 02200145asdfasdfasdf
    switches:
      switch1:
        friendly_name: 'powersocket 1'
        id: 1
      switch2:
        friendly_name: 'powersocket 2'
        id: 2
      switch3:
        friendly_name: 'powersocket 3'
        id: 3
      switch4:
        friendly_name: 'powersocket 4'
        id: 4

I get the following error:

2018-12-01 23:33:41 ERROR (MainThread) [homeassistant.setup] Error during setup of component tuya
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)  # type: ignore
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/tuya.py", line 59, in setup
    username = config[DOMAIN][CONF_USERNAME]
KeyError: 'tuya'

Unfortunately this github repo of sean6541 is gone.
I’ve found another one, but this isn’t working:
https://github.com/aneisch/home-assistant-config/blob/master/custom_components/switch/tuya.py

Can some publish a working version?

1 Like

Great, thanks @boggiano!!

Hi all

I’ve just added my first Tuya (Smart Life) in HA.

The switch is a smart plug Houzetek AWP07L

It also measures power consumption that I can see in the Smart Life app.

Is there a way to get it also in HA?

BTW, I haven’t used the custom components, but only the integrated configuration

Thanks

1 Like

This is my config for Tuya:

tuya:
  username: !secret tuya_user
  password: !secret tuya_pass
  country_code: 31
  platform: tuya

I also added two switches, used the pull_devices and force_update procedures. I get no error messages, but I also see no sign of tuya or any switches in my dashboard. What could be causing this?

My experience with Tuya/Smart-life is the “tuya:” configuration does indeed work but only for switches, outlets and light bulbs. Also, the power monitoring does not report to HA.

These are (switchable) outlets; as described I haven’t got anything to work concerning Tuya yet. Minutes ago, I changed platform value to another value and that produced an error message. So, it is being loaded; it just refuses to pick up on my devices.

Tuya works for my cover fine for me.
But sometimes when i restart HA the following error message and the device is not found:
I restart HA then again and then the device works fine.
Has anyone the same issue?
(see below=)

Log Details (ERROR)
Mon Jan 21 2019 16:31:55 GMT+0100 (Mitteleuropäische Normalzeit)

Error during setup of component tuya
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/homeassistant/setup.py”, line 148, in _async_setup_component
component.setup, hass, processed_config) # type: ignore
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.5/dist-packages/homeassistant/components/tuya.py”, line 65, in setup
tuya.init(username, password, country_code, platform)
File “/home/pi/.homeassistant/deps/lib/python3.5/site-packages/tuyapy/tuyaapi.py”, line 45, in init
self.discover_devices()
File “/home/pi/.homeassistant/deps/lib/python3.5/site-packages/tuyapy/tuyaapi.py”, line 108, in discover_devices
response = self._request(‘Discovery’, ‘discovery’)
File “/home/pi/.homeassistant/deps/lib/python3.5/site-packages/tuyapy/tuyaapi.py”, line 161, in _request
response_json = response.json()
File “/usr/local/lib/python3.5/dist-packages/requests/models.py”, line 897, in json
return complexjson.loads(self.text, **kwargs)
File “/usr/lib/python3/dist-packages/simplejson/init.py”, line 516, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3/dist-packages/simplejson/decoder.py”, line 374, in decode
obj, end = self.raw_decode(s)
File “/usr/lib/python3/dist-packages/simplejson/decoder.py”, line 404, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)