Tuya Device Help

hi, i’ve a question.

i’ve successfully added two tuya compatible plugs into homeassistant with this component. but why i can’t read the energy consumption values? on the smart life app i can read it.

It’s an api problem? thanks

As a caveat for prospective buyers of NEO/COOLCAM window-door sensors (which operate with the TuyaSmart app) please be aware that they cannot be integrated with ifttt or google home as they advertise. Of course neither can they be discovered or operated thru this component in HA.

Has anyone been successful in using this component with tuya window/door sensors like this one.

Also, does this component work with tuya wifi power strips like this one that have more than one plug? The power strip states you can control each switch individually and you can also control the entire power strip at once (turn off all switches if you want).

I’d like confirmation on these two tuya products before I add them to my setup.

Dear all:

I thought I had this tuya thing figured out. Afterall, I did post a summary on how to solve this tuya power switch issue:

After I upgraded HomeAssistant from 0.74 to 0.77.3, my tuya no longer works.

Mind you that all i did was upgrade my HA by typing
hassctl hass-upgrade
and I didn’t touch any of my configuration file.

But now my tuya no longer works. The error message is as cryptic as ever:

tuyapy.tuyaapi.TuyaAPIException: Get accesstoken failed. Username or password error!

Here is the thing. I didn’t change the username nor password. I didn’t touch anything else. and I double checked my username/password combo with the smartlife app on android AND iOS and the username/password pair still works on the apps

What went wrong?

I believe somewhere between .74 and .77 you had to differentiate whether you registered with a tuya app or a smart life app with the following in your configuration.yaml:

tuya:
  username: !secret tuya_username
  password: !secret tuya_password
  country_code: 1
  platform: smart_life

where platform: is either tuya or smart_life (or some other marketer’s name)

1 Like

I propose that the entire tuya component be rewritten. See my comment here for the reason and for links to code that someone has created that allows for all devices to be controlled locally and without the cloud.

thank you. you just saved DAYS of my life!

For those coming in late to this thread be aware:

there is more than one Tuya integration available in HA.

The ‘built in’ version doesn’t require a local key, works via the cloud, and requires you to know which tuya app you have been using (jinvoo, smartlife, tuya smart and others). Due to the API used it doens’t support everthing - dimmers, power readings from sockets, motion detectors and more, are not supported.

1 Like

Hoping I can get some assistance. I purchased a few smart switches that are Tuya compatible, although not branded as such.

I’ve used the TuyaSmart app on the iPhone to set one up and it works fine through the app. I created an account using my mobile number and happen to be in Australia, country_code 61.

In my config yaml I have the credentials right. I know this because if I put them in intentionally wrong I get an error on startup saying the credentials are wrong in the log file.

I’m running HA 0.80.0 in a docker container on a Synology if that makes any difference.

The switch doesn’t appear in home-assistant anywhere. The Tuya component appears, and I’ve tried doing a pull_device and force_update but no luck.

I’ve also tried adding a switch manually into the config as indicated in this thread, but to me it doesn’t make sense to include the IP address of the device on which HA is running. If for example I have 2 of these switches how will it tell one from the other? Regardless adding the switch into the config manually doesn’t work either.

I’ve tried logging into the iot website for Tuya, but it doesn’t accept my credentials. I’m wondering if there’s something about being in country code 61? Oddly when I look at the reset password page it only shows country code 86 for a reset using mobile phone number.

Any help would be amazing - hope someone can help.

2 Likes

I also purchased an Aldi Medion plug and retrieved the local_key and device_id for it. Adding these into the switch details in the config didn’t help.

I tried both the Raspberry Pi IP address and the IP address of the switch too to no avail.

I am in the same position, I can see tuya.force_update and pull_devices in the services screen, no errors just no switch either.

3 Likes

OK - so you

can switch the switch via the TuyaSmart (not smart life) app
get HA to connect to Tuya Cloud using the same account details as in the TuyaSmart (not smart life) app using something like…

tuya:
  username: 0414123456
  password: MyPassword
  country_code: 61

But you don’t see the switch appear as a device in HA?
(I’m going to assume your default HA page shows everything rather than having a set of custom pages which are limited.)

If you go into developer tools -> states and list all entities of type switch, so you see anything with a name like switch.00152310bcddc2ee846e ? (this is the virtual id of the device - the first number I think is your ‘home’ id, and the rest is the MAC of the device)

In the app, if you select it then menu, is the device support for third party control?

if you are using local_key and device_id, you are using the old (potentially better, direct) integration, not the smartlife cloud integration

I’ve tried both with and without the switch section and under switch the states I only see my 2 xiaomi zigbee switches, not the tuya/medion one. Also it is not showing in the default HA page.

This is my config:

tuya:
  username: '[email protected]'
  password: 'xxxxx'
  country_code: '61'

switch:
  - platform: tuya
    host: 192.168.0.15
    local_key: "62678b7f9398xxx"
    device_id: "77180230840d8e4c5xxx"
    id: 1

Supported third party control includes alexa, google assistant, ifttt and tmallgenie.
I have it working with google assistant and via the Tuya app.

Under Tuya, country code, I think you need to add something like
platform: smart_life

The platform should match whatever app you used to setup the device.

My plugs show up in the device list as switch.ReallyLongNumber
The really long number is the mac address or something like that, it matches what I see in router for my plugs.
BTW, in my router, the plugs showed up as esp’s, took me a little while to figure that out too.

EDIT: After you update the config.yaml and restart, you need to go to services and do a tuya.force.update then tuya.pull.devices

Randy

Could you please advise what version of HA you’re running and on what Hardware?

1 Like

version 77.3 on a pi3b.
I remember when I first installed on an older version, maybe 74 or 75, I didn’t need to add the platform line and it showed up differently on the device list

I could be wrong here, but AFAIK, there are two ways to control Tuya like switches.

One is via the cloud and the tuya (or other) service. Here, you configure your device with the Tuya (or similar) app, and configure them to the cloud service. Home assistant will then use your login credentials to connect to the cloud service and control them via that cloud service. So, you communicate with the cloud service to turn on the switch, and it communicates with the switch.

Tuya seems to be a platform that other manufacturers can use to avoid developing their own firmware, phone app and back-end cloud service. For example, I bought my switches from CostCo in Canada from CESmartHome. They have their own app and service that looks like a clone of Tuya. However, I was able to get my switches talking to the Tuya app, so that is the integration I used. If you’re using a different app (eg Smart Life or Jinvoo Smart)m that is what you have to define with the platform parameter.

The other way, is by determining the IP, local_ley and device_id. If you can figure out the correct details, then you can communicate with the device directly, without going thru the cloud service.

The way I understand it, you can only use one way or the other.

1 Like

Thanks @idbaker, your comment about using one or the other method was a help as I was mixing a bit of old and new methods together.
I finally succeeded in setting up the plug using the old tuya method.
Steps were:

  1. Add the old tuya.py custom component to your custom_components/switch folder

  2. Find the device Id and localkey, important here is that localkey changes each time you add the plug to an app

  3. Add the switch using the below, host is IP address of the plug.

    switch:

    • platform: tuya
      host: 192.168.0.15
      local_key: “b32ab680603abxxxx”
      device_id: “77180230840d8e4cxxxx”
      switches:
      switch1:
      friendly_name: switch1
      id: 1

It is a bit flaky, I’m getting errors sometimes but other times it works great.

I have an amazon tuya/smart life based smart multi socket plug. I am on Home assistant 0.80.2 and was able to discover the multi socket after adding the tuya user/pw and platform into the configuration.

My problem right now is it doesnt reflect my switch states in the UI. Did anyone get the tuya switch states to reflect accurately?

I ended up returning my switches as I couldn’t get then to work. I did read this though if it helps anyone.