Tuya switch

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

Yes! Just after changing the status of the switch, the status is requested too quickly, and the device issues the old status. A new one only after 30 seconds. Delay fixed this.

Perfect! I can now buy more Tuya Light Switches!

today I updated to 0.98.2 and the switches do not keep me in their position I turn it on and the button is turned off again

Hello, I have the same problem as javiges since 0.98.2. Is that a bug ?

Try custom component at my link above. There are no such problems.

HI all
i’m trying to add Tuya light switch,
made set up at Tuya app and jinvoo_smart.
non luck with both of them. (working great from the phone app)

right now i add the lines configuration.yaml
but not getting any respose-
no discover, no error

do i need to add swith entitiy?
what should i do?

Hi, can this also be made to work with lights, motion sensors and what not:)?

I have only a tuya lamp, and the custom component [localtuya] only works with switches and lamps. Sorry…

Having the same issue here after the upgrade.

Please advise how to configure two gang switch. It has one local key, device id and ip address. This plugin switch just one gang.
I see in packets in SmartLife:

{"result":[{"code":"switch_all","dpId":5,"time":1567727971820,"type":"value","value":"0"},{"code":"switch_1","dpId":1,"name":"Switch1","time":1567727971820,"type":"bool","value":"false"},{"code":"switch_2","dpId":2,"name":"Switch2","time":1567727971820,"type":"bool","value":"true"}],"t":1567727996024,"success":true,"status":"ok"}

@SergeS Here is a component with several switches:
https://github.com/NameLessJedi/localtuya-homeassistant