Tuya Device Help

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

i also have discovery: set up, but HA can’t discover anything from tuya

@zhide.p -
Thanks for the code formatting, that helps. YAML is fussy about spacing - it looks like you need to add 2 spaces so you get indenting like this:

tuya:
  username: '1234567890'    // each line under platform name is indented 2 spaces
  password: 'xxxx88788'     // and there are NO dashes in phone no / user name
  country_code: '1'           

switch:
  - platform: tuya         // platform is indented 2 spaces under device type
    host: 192.168.86.22    // device parameters align left under platform name
    optimistic: true       // is the IP correct for hassio server? 
    friendly_name: Tuya01  // NOTE: IP is NOT the IP for this switch
    id: 1                

FYI - I use Brackets to edit this code b/c it shows spaces. I use hass.io, + Samba Share component so that I can open configuration.yaml directly from finder on my Mac.

Lastly, have you checked your login credentials? Can you login to the Tuya site with the same username and password from above? What error messages are you getting? Next time, can you pls share the info your system displays (hassio > configuration tab > info [i with circle - last icon in dev tools)

Hope that helps - Liz

1 Like

I think it only discovered my Tuya devices AFTER I got login credentials right.

Hi Liz,

I tried to post it with the format, below is how it looks

image

I can login on Tuya website with that username and password,

192.168.86.5 is the hassio io. is that host: really for hassio not the switch? I didn’t know that XD

below is the error message.

@zhide.p - that’s just a warning - I get those too and it doesn’t affect performance. Can you share all info from your logs - as well as your system details (Mac/PC, Hassio version)?

I have a suspicion - you’re not authenticating. Are the username and password the same in the app as well? When you open the Tuya app on your phone, go to profile > Account, is your Account name your JFK… username or is it your phone number, or something else?

Lastly, do you see the switch or light in your Hassio dashboard? I assume it appears there, but doesn’t do anything, is that right?

-Liz

@zhide.p - I think I know what’s wrong. In the code snippet above you have 3 different host addresses. Assuming you’re running a single instance of Hassio - this needs to be the IP address of THE device running Hassio - again, in my case a raspberry pi.

In order to get the IP address, I use Fing, an app on my iPhone, to view all the devices on my router. If you reboot your router (and don’t have fixed IP addresses) it may assign a different address to your pi in future - then you would have to change the hostname IP again. But that hasn’t happened to me yet.

In future, I plan to assign fixed IP addresses and setup DuckDNS - there are good tutorials out there too - thanks to this fab community.

-Liz