Tuya Device Help

For info

activate developer tools on android phone and open
enable usb logging
install adb on your laptop
navigate to folder where you installed adb on cmd line
Run adb logcat > logcat.txt
start the app mentioned by @fastrax https://github.com/clach04/python-tuya/wiki/bin/Jinvoo%20Smart%201.0.3.apk 1
ensure devices are removed and re add your device whilst adb logcat is running
checkout logcat.txt
remove all apps

1 Like

Did that help anyone?

I followed your link, and mimic your setup.

My configuration is as followed:

  • platform: tuya
    host: 192.168.31.223
    name: harveyLight
    device_id: XXXXX
    local_key: YYY
    id: 1

The configuration seems to be legit.

However, when I tried to turn on the light, i still got an error:

2018-07-18 18:50:48 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall switch.turn_on: entity_id=['switch.harveylight']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1021, in _event_to_service_call
    await service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/__init__.py", line 109, in async_handle_switch_service
    await switch.async_turn_on()
  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 "/home/homeassistant/.homeassistant/custom_components/switch/tuya.py", line 132, in turn_on
    self._device.set_status(True, self._switchid)
  File "/home/homeassistant/.homeassistant/custom_components/switch/tuya.py", line 96, in set_status
    return self._device.set_status(state, switchid)
  File "/srv/homeassistant/lib/python3.5/site-packages/pytuya/__init__.py", line 294, in set_status
    data = self._send_receive(payload)
  File "/srv/homeassistant/lib/python3.5/site-packages/pytuya/__init__.py", line 167, in _send_receive
    data = s.recv(1024)
socket.timeout: timed out

Any idea where is my problem?

SOLVED: Tuya Light and Switch Both Working

HA v. 0.74.0
Mac OSX w/HASSIO

Setup Config.yaml as follows:

1. Enable Tuya Platform: (pls note: all values are strings)

tuya:
  username: 1234567890'      // this is my 10 digit mobile no starting w/area code
  password: 'your password'  // this is my password for IoT account on Tuya site
  country_code: '1'          // this is for US. change to match your country

2. Setup Entities (devices) in config.yaml:

group
  Tuya_Devices:
    name: Tuya Devices
    entities:
      - switch.000000000000000000   //ha discovered this for me after step 1 restart
      - light.00000000000000000000  //and this too
      
light:
  - platform: tuya
    host: 192.168.X.XX
    local_key: 
    device_id: 
    friendly_name: Tuya Light
    optimistic: true
    id: 2
    
switch:
  - platform: tuya
    host: 192.168.X.XX
    local_key: 
    device_id: 
    friendly_name: Tuya Switch
    optimistic: true 
    id: 1

3. Discover some devices automatically
discovery: //this may help discover devices, was always toward the top of config file in my case

Hope that helps - Liz

1 Like

Dear Liz:

you just saved my LIFE!!! I struggled with this for MONTHS, literally!

Thank you!

Harv

I summarized the instruction in the following post:

How do we remove those components? Just delete the .py files?

yes.

The location the file is typically in your homeAssistant home directory’s

$homeassistant/custom_components/switch

subdirectory.

In my own case, (hassbian), the file is located at

/home/homeassistant/.homeassistant/custom_components/switch/tuya.py

and all you have to do is delete/rename the file, and in my case, I also remove the py_cache directory just in case since I have no idea how python cache its own compiled binaries.

Thanks, got rid of it

1 Like

This had driven me crazy for so long. Some said it worked and I followed their exact instructions and nothing.

Now, after deleting the old tuya.py files, it works!

Thank you all

1 Like

I can’t seem to get my account linked. I keep getting errors upon restarting referencing an invalid config on the Tuya component even when I’m just adding the login information (Though the configuration validator says it’s good). I’m using my normal Tuya login, though I’ve seen some people reference using the IoT platform log in. Do I need to make an IoT account then transfer my devices to that?

Thanks in advance.

show us your configuration file’s tuya / switch segments, as well as error messages.

Here’s what I have. Did you have to use a Tuya IoT account to make it work?

tuya:
  username: !secret tuya_user
  password: !secret tuya_pass
  country_code: 1

switch:
  platform: tuya
  host: 192.168.2.231
  local_key: [REDACTED]
  device_id: [REDACTED]
  optimistic: true
  switches:
    switch1:
      friendly_name: Printer Camera
      id: 1
    switch2:
      friendly_name: Printer
      id: 2
    switch3:
      friendly_name: Extractor Fan
      id: 3
    switch4:
      friendly_name: Switch1
      id: 4
    switch5:
      friendly_name: Switch2
      id: 5

EDIT:

Also, the error is not present in the system log. Just a large panel on the home screen stating:

Invalid config
The following components and platforms could not be set up:

  • tuya
  • switch.tuya

Please check your config.

> switch:
>   platform: tuya

Try the following (please pay attention to every single characters)

switch:
- platform: tuya

(notice that “dash” symbol)

Also, unless your tuya switch has multiple outlets, you should be doing the following IF you happened to have mulitple tuya switches:

switch: 
  - platform: tuya
    friendly_name: switchA
    id: 1
    ....
  - platform: tuya
    friendly_name: switchB
    id: 1
    ...
  - platform: tuya
    friendly_name: switchC
    id: 1
    ....

I have NO idea what those “id: 1” is for. I think someone here in the forum managed to get tuya to work without it. Since my tuya works right now, I am not going to touch anything unless it’s absolutely necessary :slight_smile:

That doesn’t seem to be it. I looked in the server files, and in home-assistant.log, I found the error referencing Tuya. It seems like it isn’t able to authenticate. Again, I’m using my normal Tuya account, not IoT.

tuyapy.tuyaapi.TuyaAPIException: get access token failed

Also, thank you for your help. It’s very much appreciated.

EDIT: I am using a multi-socket switch (Power strip).

it looks like your devID and/or localKey is not correct. you want to make absolutely sure that you got the right pair of information (see my post above)

Both are accurate. I decided to try to make an account with the Tuya IoT site, and then use that login information for the Tuya component, and it worked. I seem to be able to login to the Tuya app using that login information, and I can add devices from there.

I’d like to know if anyone is able to get the Tuya component working with an account created in the app instead of on the Tuya site. If not, that should be added to the documentation as a possible requirement.

Hi Liz,

i following you config but still can’t get it working. can you please check for me? below is my config:

tuya:
username: 91739ddddddd
password: matdddddddd
country_code: 1

switch:

  • platform: tuya
    host: 192.168.86.22
    device_id: 012005816001xxxxxxx
    local_key: e97b2b99xxxxxxx
    switches:
    switch1:
    friendly_name: Tuya01
    id: 1

@zhide.p,

Without code formatting I can’t tell if your username, password, and country-code are surrounded by single quotes.

Also, you can eliminate the local_key and device_id with the new Tuya component - they are unnecessary.

Hope that helps - Liz

Hi Liz,

thanks for replying, below is my config, but still not working, i can control them in Tuya Smart app

tuya:
username: ‘999-999-999’
password: ‘xxxx88788’
country_code: ‘1’

switch:
- platform: tuya
host: 192.168.86.22
optimistic: true
friendly_name: Tuya01
id: 1