Tuya switch

I’ve made something similiar for thermostat ( BHT-6000 Thermostat (tuya) support )

Have you found if there is a delay on retrieving states?
Example: if I manually set the thermostat hass is updated after a while

I know that it depends by scan_interval, but with low values the device does not responds

I’ve found that tuya app has low delay, so I think that it pushes data to tuya server on events, maybe is possible to listen to that states

If I toggle the switch manually or via the Smart Life app, it takes about a minute before the new state is reflected in hassio. I’ve not found a way to make it faster. Adding scan_interval made no difference.

do i need old tuya component to be listed in configuration file

From here you get the first 30 seconds delay:

def status(self):
    """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:
            self._cached_status = self.__get_status()
            self._cached_status_time = time()
        return self._cached_status
    finally:
        self._lock.release()

That combined to the standard hass scan_interval (30 seconds) can explain your 1 minute delay

In my code i’m testing without the if statement and with a scan interval of 5sec, for now it seems to work and the average delay is acceptable (and maybe the scan interval can be lowered)

Remember that if the tuya app is open readings will fail

Anyone tried to get this going with the Eurom Heaters or any other re-branded Tuya Heater?
I got one hooked up and configured via the Tuya component but it is really unreliable, gets unreachable after a couple of days and need to be power cycled.
Would love to get local control over it to see if it fixes the problem.

Probably this can work out-of-the-box BHT-6000 Thermostat (tuya) support
Or at least can be a start point (most probably parameters ids won’t fit, but device specific ids can be retrieved with https://github.com/clach04/python-tuya and the following code)

import pytuya

d = pytuya.OutletDevice('<devid>','<devip>', '<devlocalkey>')
data = d.status()  
print('Data %r' % data)

No. In fact, you need to take it out. You are effectively defining your own custom tuya component. If you have the built in tuya component in your config file, the custom component will not work.

Are you saying you have “scan_interval: 5” in your configuration.yaml, and have monkey patched the tuya.py code to comment out the " if not self._cached_status or now - self._cached_status_time > 30" conditional?

Yes,
so the timing is given by hass and not by the component. To make a try i’ve commented out the if-statement and adjusted the indentation, and it works great.

With scan_interval: 5 I’ve found that sometimes the commands where not caught (probably the readings blocks the settings).
Now I’m testing with scan_interval:10 but something must be implemented to suspend readings when dps were set.

This does make tuya switch to work locally to turn on and off only.
I am using tuya rgbw light,
which doesn’t show any option to change colour, scene, brightness, etc.
Please guide if some one get lights to work.

pytuya itself supports rgbw light, https://github.com/clach04/python-tuya/
it has only to be integrated on the ObedientOwl tuya switch device

Trying to make this work with Tuya Curtain Switches (double-checked Device IP, Device ID and Local Key), but they show up as Switch (On/Off only) instead of Cover (Up/Stop/Down). Is there anything I can do to mark them as Covers? Thanks!

I don’t have RGB lights to play with. Feel free to document the changes you made to add support for setting colors.

Any help on making my arilux rgbw would be appreciated.
I am on Hass.io installed on Raspbian strech lite on rpi3b+
Thanks in adv

Unfortunately I didn’t have an RGB light to make some try. I can only suggest to integrate the ObedientOwl code (that uses pytuya) with all the ability of the pytuya code. In pytuya code there’s the BulbDevice class that supports rgb lights. Get the ObedientOwl code, integrate it with RGB support (watching the code of other RGB light already supported) and adapt the commands to match the pytuya BulbDevice support

1 Like

Hi, I followed the instructions by ObedientOwl on Jan 24th. But seem to be getting the below error. Could anyone point me in the right direction!?

Blockquote2019-02-26 08:11:28 ERROR (MainThread) [homeassistant.setup] Error during setup of component tuya
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py”, line 154, in _async_setup_component
component.setup, hass, processed_config) # type: ignore
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tuya/init.py”, line 54, in setup
username = config[DOMAIN][CONF_USERNAME]
KeyError: ‘tuya’
2019-02-26 08:11:28 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of tuya.switch. Setup failed for dependencies: tuya

I’m running home assistant .88.1 with no luck on the tuya.py and init.py

1 Like

Thanks for this,

Are you able to use tuya on lan still with home assistant 0.88?

Thanks

Just in case you guys don’t already know about it, you can use this to flash Tuya devices OTA and then put ESPhome on them to get them working natively in HA without any worrying about custom python components etc… much easier than the trouble I read in this thread

ESPhome

ESPhome HA API

Another handy link