[BETA] Tuya Cloud Driver (Limited device support)

If anyone wants to play with some experimental code for LOCAL control of RGBW Tuya lights then here is your chance.

  1. You must already be running the cloud driver from this thread, this driver does not work standalone.
  2. Download the LIBRARY code here: https://raw.githubusercontent.com/bradsjm/hubitat-drivers/master/Tuya/Local/TuyaProtocolLibrary.groovy
  3. Download the DRIVER code here: https://raw.githubusercontent.com/bradsjm/hubitat-drivers/master/Tuya/Local/TuyaLocalRgbLight.groovy
  4. Find the RGBW Tuya child device you wish to make local and change the driver from the Hubitat "Generic Component RGBW" to this driver "Tuya Local RGBW Light" and click save.
  5. In the driver configuration you MUST enter the IP address of the light device, the driver is unable to scan for it (due to the well known limitations of Hubitat broadcast UDP protocol support)

That's it, once you enter and save the IP address the driver will start sending and receiving updates locally using the cloud as a backup method if sending directly fails. For me, round trip command and response are under 400ms which isn't exactly speedy but the protocol has a lot of overhead (encryption of packets, use of JSON etc.) and it means it will work even if you lose internet connection or Tuya cloud does a wobbly.

You can return to full cloud again by changing the driver back to "Generic Component RGBW"

REMEMBER - This is experimental code, also, it is using Hubitat raw sockets which itself is described in the documentation as "is in alpha status" so caveat emptor. I've implemented retries in the driver because the reliability of the connection to the device is questionable and I do not know if thats due to the Tuya device or the Hubitat raw socket implementation. Probably need to get a packet sniffer to find out what is really going on.



Looking forward to the multiple devices code addition per tuya device.
I have a ceiling fan and light controller that would greatly benefit from this. If you need help testing it, let me know and I'll assist where i can

Hello Jonathan,

I tried this code for controlling the lights locally and I'm getting some trouble. Weird thing is, in the Tuya app, it says the device has some weird IP I don't recognize. I tried to configure the light for local control using both the IP address listed in the Tuya app and the IP address listed in my Ubiquiti router and I received the same results.

You should not use the IP address in the app as its your external IP, you should use the local one in Unifi which it looks like you did as you got one successful heartbeat received. However, the connection reset messages are something I used to see a lot of from my devices.

These devices will only allow a SINGLE connection to them so if the app is open on your phone or you have some other "Local" tuya solution opening connections that will cause a failure.

I also used to see this when my Tuya devices had low signal (even though they were close to the Unifi AP). I happen to have upgraded my AP from the LR to the new 6 LR model and I've had virtually no connection resets lately but can't say if this is a co-incidence or not.

1 Like

This makes sense and yes I absolutely had the native app running. I can try to test against this later; however, given that information, this solution will not work for me until the effect calling is built (because I can't automate the effects yet and I MUST rely on the app).

I'm not trying to rush you or even tell you that the effects is a priority, it just means I won't be able to switch over to local control until I can get that. I will gladly still test this out without the effects in the meantime and report back.

There is a special option in the local driver called "sendDps" which allows sending any DPS command to the device even if it's not supported via the Tuya Cloud service e.g. effects. For example, from the logs you posted before you would use DPS number 2 and the value would be "scene1" or "scene2" etc. You can then invoke this from the rule engine as a custom command.

** Update: I've added basic effect support into the local driver, just go into the settings and tell it how many effects/scenes the device has (e.g. 4 for scene1 through scene4) and use the effect number with the seteffect command.

Once again, everything you said is true. I closed the connection to the rgbw light in tuya and it allowed for local control in HE. Additionally sending DPS:2 scene2 got me exactly the scene I need to automate. I will figure out how to get it into webcore.

I plugged this in and it works great. This will make it easier to automate the scenes in Webcore. Thanks

@IguanaBob Glad it works! I do have a local driver for outlets/switches but it won't work on power strips due to the complexity of having multiple Hubitat devices for a single Tuya device and Tuya devices only allowing a single TCP connection but its not an impossible problem to solve down the road.

@SigFan86 I've not forgotten about the ceiling fan with light, now that the power strip works I'm closer to figuring a solution for this but limited time means I can't say when.

The driver now supports the Tap-to-Run automations from the Tuya app. For example, I have two automations one that turns on a group of lights, the other to turn them all off. I use this because they all turn on and off at once instead of the popcorn effect of sending individual commands. The two automations show up as Switch devices with the name of the Tuya automation and to trigger it you turn the switch ON (I considered making it a push button device vs. a switch, open to feedback on which works better)


I'm waiting on ceiling fan light :blush:

Thanks, @jonathanb this is great!
Can you please add the importUrl to the definition so we can pull down updates easier?
definition (name: 'Tuya IoT Platform (Cloud)', namespace: 'tuya', author: 'Jonathan Bradshaw’, importUrl: ‘https://raw.githubusercontent.com/bradsjm/hubitat-drivers/master/Tuya/TuyaOpenCloudAPI.groovy‘)


@damianm Good idea, will include the import url in future updates!


Amazing, I'll have to update to this version on the weekend - I had hacked together my own from your original driver, but I think it was conflicting having both running at once, as sometimes devices became unresponsive. (Which is why I hadn't yet cleaned up & shared my code!)

The Tap-to-Run lets you do anything the app can do, even if this driver or the Tuya API doesn't support it yet.
Eg. I need it for my tuya-based Genio Xmas tree lights: they have 8 different flashing "modes", but they weren't exposed via the API (no scenes - only on/off and brightness params available). So I set up 8 tap-to-run automations, one for each "mode" and it was working great!

I had mine as a switch that automatically turned off after a second or two (so you could trigger it again later). Only because I didn't have much time to play with it & I wasn't familiar with how push buttons work on a dashboard, especially with the "num of buttons" param.

1 Like

This is really great--thanks for all of your efforts.

I have a 2-channel wifi relay, which shows up in Smart Life as two switches. In Hubitat, it only shows as one switch, although the device details show two switches. Any way to be able to control both?

@eelton Please try this development driver with support for your device. Remove the existing switch device first and it should create the 2 new switch devices.


It's probably something I'm doing wrong, but I get these errors in the log:

Did you try clicking the initialize button? I'm not sure from that snippet why it doesn't have a valid token but I've fixed the missingpropertyexception in the dev branch but that should be just cosmetic and have nothing to do with the lack of token.

Yes, I did click initialize. It says "authenticating" and then "error." Here is the latest log:

Sorry--my boneheaded mistake. I put in the password for the Tuya account rather than Smart Life. It's working now, in that I can sign in. I still see only one channel for the switch.