Tuya switch

Thanks for that, I saw a video regarding the flashing method.

It looks like when you flash, they become sonoff devices?

I don’t see a tutorial specific to putting esphome in them.

Beginner here, using HomeAssistant in docker in Synology.

I guess if I flash with a raspberry pi, does the raspberry need to be running all the time?

No, you can flash them directly to ESPhome using the instruction at the very bottom of the tuya-convert git. (flash a third party .bin file)

Create the .bin file with ESPhomeYAML and then use the method mentioned above to flash it to the ESP device. There is a tutorial on the ESPhome site that explains how to migrate from Tasmota but you don’t need to since you can simply flash the ESPhome .bin file directly.

No, once flashed the ESP communicates with HA directly (via your wifi that is)

thank ya, seriously considering it, just don’t know how this plays with google home, that’s like a whole new can of worms that I have to educate myself.

It will still be controllable with Google Home, via HA, just not directly (ie: without HA), but I see that as far better than using a Tuya cloud

It seems 0.88 broke the custom tuya integration. It looks like the custom component (“tuya” in this case) can no longer conflict with built in components (“tuya” in this case) even if they are unused. To solve this, you just need to rename config/custom_components/switch/tuya.py to something else (config/custom_components/switch/mytuya.py), then update the “platform” key to match (“mytuya”) in your configuration.yaml. I have updated the tutorial to reflect the change.

If you are just getting started and are unable to find your key and localKey data, you may need to use an older version of the SmartLife app. It appears they are hiding that data in recent versions.

All of that said, I’d really like my devices to not be cloud connected whenever possible. While I’m using the custom component, I have the Tuya switches blocked from WAN to get as close as I could. When I have the time, I’m going to dig in to what @sparkydave posted and try to get these flashed with ESPhome instead.

Very helpful thanks for sharing this solution! I rolled back to .86 but will try it on .88

Update 1: so I’m back on .88 but just FYI, even though everything is working as expected, I see an error message in dev-info

“Integrations need to be in their own folder. Change switch/mytuya.py to mytuya/switch.py. This will stop working soon.”

any idea what this might mean?

Update 2:
so, Interestingly, I renamed the “switch” folder to: “mytuya”
then, I renamed the “mytuya.py” to:"switch.py

and the dev-info error went away, also testing the tuya switches, they still work

1 Like

THANK YOU!!

Thanks to you and your guidance I think I am still in local Tuya business. I will flash when I get around to it, but for now, Thank you!

Guys what is tuya? Is it like a protocol or software that you can flash on any smart plug?

Hello All!
Relatively new to Home Assistant.

I see the switches working using the Tuya switch custom component. However, they only seem to be able to turn on and off. Is there a way to set up dimmable lights?

The built in Tuya component (web) self-identifies them as “lights” instead, similar to a bulb, but with only brightness adjustments. The code controlling a bulb is in the custom component file(s). I am unsure whether I can use that and set a dimmable light switch up as a bulb of sorts. the bulb has the RGB portion of the code, and I wonder if that would somehow mess up the dimmer (I have my doubts that setting it to white and just changing the brightness would work, though I have not tried it).

Has anyone had any experience with the dimmable light switches using local control / custom components?

It’s a brand of smart devices, which until you either flash with different firmware or use a custom component, will require the Tuya cloud service in order to work with HA. Flashing the firmware seems to be the best fix to rid oneself of the cloud dependency.

1 Like

It’s firmware used by a number of different brands that allows them to sell lights, switches etc. which can be controlled through a Tuya cloud server. Here’s a good video on how to get get rid of Tuya:
http://www.thesmarthomehookup.com/tuya-convert-walk-through-february-2019/

1 Like

It seems that version HA 0.89 (with python 3.7.2) broke again the custom tuya integration. I had to move the tuya.py from “config/custom_components/climate” to the directory “config/custom_components/mytuya” (just an example but you can change the name of the final directory until it is not “tuya”) and rename “tuya.py” as “climate.py” in my case… than I do not have any error message (except warnings that it has not been tested by HA) but…it seems that HA does not take this custom component into account. Anyone has the same issue ?

So I copied all native elements from tuya including the init file to config/custom_components/tuya (I tried an empty file for the init file but I got an error message and tuya was not loading anymore). Now it is working again with the right temperature displayed as I modified the climate.py file in the custom_components to get the correct temperature…

Hi. I have an issue with tuya curtain switch. I added the Tuya component and I can see SCENES in the HA, but no SWITCHes or COVERs… Anyone knows how to fix it?

‘tuya’ is now a forbidden word. If you declare a switch: -platform: tuya, and you have a custom_component named tuya, HA loads the embedded (cloud based) component (it bypass the custom_component). You have to use, for example: mytuya, localtuya, etc.

localtuya repository (and getting attributes for power metering devices)

https://github.com/mileperhour/localtuya-homeassistant/

I really don’t want to take the credits for this. But to share. Really I did very bad when I try to suggest sean6541 to add the power metering functionality working (on his really good work), but what I achieved was He has deleted all his project involving Tuya. I’m embarrased for it.

I’m sure the reason he take this decision was my very bad english and me don’t doing it well to explain the things. But that’s done now and I can’t do anything but to share how I solved it.

I think its clear on the code and documentation how to take this working, as really the difficult thing was to write the code as sean6541 did.

I really hope this would benefit as much as this code is working for me.

Cheers.

2 Likes

To correctly display the status, you need to add one line (sleep(0.5)) to the switch.py code:

    def status(self, switchid):
        """Get state of Tuya switch and cache the results."""
        self._lock.acquire()
        try:
            now = time()
            if not self._cached_status or now - self._cached_status_time > 30:
                sleep(0.5)
                self._cached_status = self.__get_status(switchid)
                self._cached_status_time = time()
            return self._cached_status
        finally:
            self._lock.release()

And at the beginning of the file replace:
from time import time
on
from time import time, sleep

I did this and it completely broke my HA.

Removing what you said and Home Assistant was fine.

I’m sorry. But apparently did something wrong.
Here component already changed: https://github.com/stast1/localtuya
100% working.

Thanks Stast I’ll give it a go.

And this fixes the slow status update issue?

Cheers