Tuya local

What do you mean by OTA. For local tuya you need to do several things before you could actually set it up. But for tuya device that is not supported will be very difficult to install

Have localtuya up and running and all my 9 lights working in HA. After this I used iptables on my DNS server to drop all requests coming from the lights and blocked these IPs from accessing the internet.

Now, in the Smart Life app on my phone, 7 out of 9 lights have went offline. I actually expected all lights to go offline in the app. Correct?

Strange thing about those 2 lights that are still online in the smart life app, they keep switching off and online and when they are online for a few seconds, I can control the lights. On the USG firewall, I can see requests from just one of these two lights coming in and getting dropped. All kind of strange. I powered off both lights and then on again, but that doesn’t change anything.

Questions:

  • Will they maybe remove themselves in a few days from the app???
  • If I can still control them through my phone using the smart life app, does this mean there is still a connection to the internet somehow?
  • Is my assumption correct that they should all be offline in the Smart Life app?

Thx

  1. More in a few couple of minutes (can take >20 minutes though) than in a few days.

  2. Most probably yes. Readme.md says

    NOTE - Nov 2020: If you plan on integrating these devices on a network that has internet and blocking their internet access, you must block DNS requests too (to the local DNS server eg 192.168.1.1). If you only block outbound internet then the device will sit in zombie state, it will refuse / not respond to any connections with the localkey. Connect the devices first with an active internet connection, grab each device localkey and then implement the block.

  3. Your assumption is correct.

Thank you for your reply. Strange then that some are still visible in the app though I specifically blocked them. Have to further investigate that.

My understanding of the smartlife app is it actually connects local to the device using the local keys if the phone is on the same wifi network as the devices, and doesn’t always route through the cloud. There was actually a method (not sure if it still works) where you can get the tuya keys for devices off a rooted android phone.

Therefore, I could see the devices still being controllable on the local network with the smartlife app even if the devices are blocked from accessing the internet.

Do you see a difference with the way the devices are listed in the smartlife app between being on wifi vs cell connection?

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