Tuya local

As for some ancient Smart Life app versions it was possible to extract the local keys directly from a rooted Android phone. Unfortunately this doesn’t work anymore since quite a while.

The control centre for tuya devices is surley located in the tuya cloud. The Smart Life app is only communicating directly with tuya devices during the pairing process. Just cut off your internet connection and try to switch a tuya device from your phone using the same SSID as your tuya devices. It wont work properly anymore.

Tuya based devices are obviously “reporting home” their status at regular intervals. This happens also to report back to the Smart Life app on the phone whether their actual status is online or offline. If they are considered offline for whatever reason by the tuya control centre (i.e. you have successfully blocked all ingress/egress connections from/to the Tuya Cloud, or you have an internet blackout, or the tuya device has freezed) you’ll receive that “Device Offline”-message sent onto your phone.

Although I am quite careful about where “my” data is going I did not block tuya devices from communicating with the Tuya Cloud. The main reason for installing Tuya Local to HA on my side (replacing the original Tuya integration) is because internet blackouts are happening frequently here and during those cut-offs automations controlling tuya based devices were not working reliably anymore. Even worse, if the internet connection was down for an extended period of time I had to re-pair most of the devices thereafter with the Tuya Cloud. Very annoying.

The second reason why I have installed Tuya Local is the time for the status updates from tuya devices to the Tuya Cloud back to HA. These staus updates can take up to >20 minutes (take a look here and here for an explanation of the latter). If you have automations based on the staus of tuya devices they are getting pretty much useless.

In short: If you are not too concerned about the fact that your tuya devices are reporting their actual status to the tuya control centre within the Tuya Cloud just let them do so. As for realibility install Tuya Local onto HA replacing the Tuya intergation which comes with HA. This way you’ll get the best out of two worlds: Internet cut-offs doesn’t have any impact on your automations anymore, status updates of tuya devices are happening instantly and in the rare case your HA installation gets unresponsive you can still control your tuya devices through the Smart Life app.

1 Like

Thank you for your reply and explanation. The reason I wanted to cut them off from the internet is the fear that in some firmware update in the near future, Tuya will make it impossible for them to work with Home Assistant (or other apps). Or is that too far fetched?

Well, nobody can say what the future brings. I personally don’t think they will go that far. Tuya is not a manufacturer but a service provider providing a cloud based platform to hardware manufacturers. That’s their business model. Closing things down the way you are afraid of would definitely hurt them more than it helps. There are other products/techniques after all like Tasmota, Sonoff, Zigbee, just to name a few.

1 Like

Then I’ll open up my firewall again for them :wink:

Hey Garbie, just sharing my experience here as I too was baffled how my bulbs were connecting to the Smart Life app, despite them being blocked by a firewall. I could even control them on my phone’s cellular data connection!

Turns out all the bulbs (or at least the ones I have) have bluetooth! It wasnt advertised on the listing or packaging whatsoever, but I assume its built in and Smart life can utilise that as a redundancy connection method. In my experience it doesnt come on unless the bulbs are blocked, but you can easily see them on a phone.

So the SmartLife app is using my bluetooth as a fallback to connect to them? Wow :slight_smile:

Hi all, I just bought a Tuya air sensor (it measures formaldehyde, VOC, co2 temp, hum…), I’m unable to find it in the tuya integration; there is a way to add it?
Thanks

I’m somewhat lost now.
Got my account on Iot.tuya and can see all my devices on the app platform now.
But how to integrate them into HA now?

Has an example of the config yaml but where do I get the device_id and local_key?

localtuya:
  - host: 192.168.1.101
    device_id: xxxxx
    local_key: xxxxx
    friendly_name: Tuya Device
    protocol_version: "3.3"

If you are not afraid of the Linux CLI and are running Linux OS on either the device HA is installed on or on some other Linux based rig install Node.js and npm.

After the above is done run:
sudo npm install codetheweb/tuyapi

Finally whenever you need the device_id’s and local_key’s of your Tuya based devices just run:
sudo tuya-cli wizard

Type your API credentials and provide a ‘virtual ID’ of a device currently registered with your Tuya Developer Account and stdout will give you all the needed information whenever you run sudo tuya-cli wizard.

Local Tuya has to be installed on your HA device. How this can be done is written here.

Now open the HA UI and go to Settings --> Integrations --> Add integration and choose LocalTuya Integration. Here you can add your devices one by one using their device_id and local_key you have obtained through sudo tuya-cli wizard.

1 Like

Spinning up a new VM with Debian to get this installed and toy around with it first, then install supervised. Looks like it’s not possible on the managed OS supplied by HA I have just installed. My older ubuntu ha had full access but just migrated that as I got fed up with the unhealthy state and not supported errors on it.

Basically it should also work through Windows although I have not tested it: How to Install Node.js and NPM on Your Windows System.

Use Debian 10 instead of Ubuntu. It’s fully supported by HA and you’ll get a healthy state with all the conveniences coming with it.

PS. Don’t use HA’s Tuya Inegration when using Local Tuya to avoid potential conflicts.

1 Like

Thanks. Debian all set up and npm installed etc. Went through the tuya wizard and retrieved the device ids etc.
Just working on installing hacs etc etc.

I’ll see how it goes with this localtuya.
On my other vm I have customtuya which isn’t all that bad tbh
Thanks!

Great got in.

What is the local key for each device?

Update: got it from the cli wizard, Thanks

image

Not 100% clear what I’m supposed to choose for ID (1 true or false(0)). Current state leave blank?

Woww but instant update on HA after switching on/off for the first device added!

1 Like

I was wondering the same thing. I’ve got some Eva Logik switches configured through Tuya/Smart Life and am looking at setting up the Local Tuya in case the web interface is removed from support as well as to ensure automation operability during internet outages.

I’ve acquired the id/key ok and set up a local tuya configuration. I can turn the switch off and on ok; however, the state is not held in HA – i.e. if I flip the switch on the Smart Life integration shows “on” in HA. When I try it using the local tuya config it “flashes” on, turns the light on, but then shows off in HA even though light is still on.

Did you remove the Tuya Integration which comes with HA before adding Tuya Local? You should not have both integrations installed on your HA.

I do still have the Tuya Integration. I have it working now. I am seeing entity id options 1 and 7. I was only adding one of the two entity id options. I think one is the state and the other is the switch action. Once I added both of them, then I could toggle the switch and the state would be captured as expected under the “local” integration.

I’ll look at removing the standard Tuya as there’s no longer a need for me to have it with the local working. Out of curiosity, what problem(s) are caused by having both? I saw the notes about not having “tuya” included with the naming any of the local items and didn’t do that.

Adding floodlight as what type of device?

Got a new Tuya Floodlight with motion detector (product ID p34tkhljhjgfr5vl). I figured out the DP IDs you see below. Now I just don’t know how I should add this to localTuya. What type of entity should I add? I can use the light entity but then I don’t have the motion part. Or is this not doable through the wizard and do I need to add this to the configuration.yaml file?

And if I add this to the configuration.yaml, do I need to move all my lights that are currently in use through LocalTuya, also to the configuration.yaml?

DP ID App item Tuya code Tuya Type Tuya Value
20 on/off switch_led Boolean {true,false}
21 (not found) work_mode Enum {“range”:[“white”,“colour”]}
22 brightness bright_value Integer {“min”:10,“max”:1000,“scale”:0,“step”:1}
23 colorwarmth temp_value Integer {“min”:0,“max”:1000,“scale”:0,“step”:1}
control_data String {“maxlen”:255}
51 Manual / Sensor operated device_mode Enum {“range”:[“auto”,“manual”]}
53 Sensitivity Light sensor cds Enum {“range”:[“2000lux”,“300lux”,“50lux”,“10lux”,“5lux”,“now”]}
54 Motion detection range pir_sensitivity Enum {“range”:[“low”,“middle”,“high”]}
55 Duration light after detection pir_delay Integer {“unit”:“s”,“min”:5,“max”:3600,“scale”:0,“step”:1}
56 PIR sensor on / off switch_pir Boolean {true,false}
58 Duration light dimmed standby_time Integer {“unit”:“min”,“min”:1,“max”:480,“scale”:0,“step”:1}
59 Brightness dimmed standby_bright Integer {“min”:0,“max”:1000,“scale”:0,“step”:1}

Hi , May have been answered before , But i have HA running in a docker container.
Local Tuya working ok , the Local Tuya entity within HA is none responsive.
Questions, 1) do i have to open any ports to allow communication between Local Tuya and the Device. 2) any issues running Local Tuya and the normal (cloud based) tuya integration at the same time… Reason for this question , new device listed on both integrations but only working on Normal Tuya Integration. Could be related to question 1

Thanks in advance
LeeB