Tuya Device Help


#42

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.


#43
> 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:


#44

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).


#45

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)


#46

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.


#47

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

#48

@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


#49

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


#50

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


#51

@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


#53

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


#54

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.


#55


#56

@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


#57

@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


#58

@liz_myers, i am using a Raspberry Pi 3+ and it’s the only HA instance. I am sure the usrname and pw is correct. i have a 2 accounts set up by a phone nubmer and email, but no luck. When i put a wrong pw, it will give me the below message:

When i put the correct usrname and pw, there is no above error message and dashboard doesn’t show anything about tuya switch, either <> page on developer tools.

TP-link switches are working fine in my config, the IPs are correct and required for tp-link platform


#59

@zhide.p,

I don’t know what else to suggest. Is the Tuya device actually a switch or a light?


#60

@zhide.p it’s a switch


#61

Have you tried assigning the host: 192.168.86.5 (IP of the Hassio server) to all switches and then using a unique id:

Example:
friendly_name: tv
id: 1

friendly_name: shelf_power_strip
id: 2

friendly_name: tuya_switch
id: 3

maybe there’s a collision going on …


#62

hi liz, i also try to disable all tplink switches and leave only the tuya one, but it still not showing anything. dont really know what the issue is T_T. can you tell me what model of tuya switches you are using?

this is my model and it works in the Tuya Smart app.