LW IT Solutions
« Blog Overview /IT & Networks / How to Control Tuya Devices Locally in...
This post in other languages:

How to Control Tuya Devices Locally in Home Assistant

How to Control Tuya Devices Locally in Home Assistant
Contents
  1. Prerequisites
  2. Step 1: Create a Tuya IoT Developer Account
  3. Step 2: Link the Mobile App to the Developer Project
  4. Step 3: Retrieve the API Credentials
  5. Step 4: Install LocalTuya via HACS
  6. Step 5: Configure LocalTuya in Home Assistant
  7. Step 6: Add and Map the Devices
  8. Bonus Step: Isolate the Devices (VLAN)
  9. Conclusion
  10. Sources

Anyone who has dabbled in smart home tech probably owns a Tuya-based device. They are affordable, ubiquitous, and available under hundreds of different brand names. However, they share one major flaw: a heavy reliance on the Tuya Cloud.

Relying on a cloud server means latency, potential downtimes, and privacy concerns. If the internet goes down, the smart home breaks. As digital architects advocating for robust and private systems, we need a better way.

In this guide, we will walk through migrating Tuya devices away from the cloud and integrating them locally into Home Assistant (running on a Raspberry Pi 4) using the LocalTuya integration.

Prerequisites

Before we begin, the following needs to be in place:

  • A Raspberry Pi 4 (or any other machine) running a working instance of Home Assistant.
  • Tuya devices currently connected to the Tuya Smart or Smart Life mobile app.
  • HACS (Home Assistant Community Store) installed on the Home Assistant instance.
Comparison of the Tuya cloud path and the local LocalTuya connection, with the one-off key retrieval via the developer project
The migration in one picture: the device stays the same, only the path changes. The developer project hands over the local key once, after that Home Assistant talks to the device directly — and the IoT VLAN can go offline.

Step 1: Create a Tuya IoT Developer Account

To control Tuya devices locally, we need their unique “Local Keys.” To get these, we must register as a developer. Don’t worry—it is completely free.

  1. Navigate to the Tuya IoT Platform and create a free account.
  2. Once logged in, go to Cloud in the left sidebar and click Create Cloud Project.
  3. Fill in the details (Name: HA Local, Industry: Smart Home, Data Center: Choose the one closest to the installation site).
  4. The next screen asks for API authorization. Ensure that IoT Core, Authorization Token Management, and Smart Home Scene Linkage are selected. Click Authorize.

Step 2: Link the Mobile App to the Developer Project

Now the devices sitting in the mobile app need linking to this developer project.

  1. In the Tuya IoT Project, navigate to the Devices tab.
  2. Select Link Tuya App Account and click Add App Account.
  3. A QR code appears on screen.
  4. Open the Tuya Smart or Smart Life app on the phone, go to the “Me” tab, tap the scanner icon in the top right corner, and scan the QR code.
  5. Confirm the login. The devices now populate in the Tuya IoT platform.

Step 3: Retrieve the API Credentials

To automate the retrieval of the Local Keys, Home Assistant needs the project’s API credentials.

  1. In the Tuya IoT project, go to the Overview tab.
  2. The Authorization Key section holds the Access ID/Client ID and Access Secret/Client Secret.
  3. Copy both of these strings to a secure notepad; they are needed in a moment.

Step 4: Install LocalTuya via HACS

Now over to the Raspberry Pi 4 running Home Assistant.

  1. Open Home Assistant and navigate to HACS.
  2. Go to Integrations and click the Explore & Download Repositories button.
  3. Search for LocalTuya and install it.
  4. Once installed, restart the Home Assistant instance to apply the changes.

Step 5: Configure LocalTuya in Home Assistant

With the integration installed, it is time to bring the devices locally into Home Assistant.

  1. Go to Settings > Devices & Services in Home Assistant.
  2. Click Add Integration and search for LocalTuya.
  3. A prompt to configure the integration appears. Choose the option to configure it using the Tuya IoT API.
  4. Enter the Client ID and Client Secret (from Step 3), and select the user ID (usually available in the dropdown).
  5. Submit the form. LocalTuya will now communicate with the Tuya API one time to automatically pull the Local Keys for all devices.

Step 6: Add and Map the Devices

LocalTuya now discovers the devices on the local network.

  1. Select a discovered device from the dropdown list.
  2. Because Tuya devices are highly generic, the “Data Points” (DPs) have to be mapped by hand. For example, DP 1 is usually the main Power Switch, while DP 2 might be Brightness (for a bulb).
  3. Assign the correct entity type (e.g., switch, light, sensor) to the corresponding DP.
  4. Click Submit. The device is now integrated into Home Assistant.

Bonus Step: Isolate the Devices (VLAN)

Home Assistant is now talking to the Tuya devices directly over the local network.

However, the devices themselves are still trying to phone home to the Tuya Cloud. To achieve true privacy and prevent unauthorized firmware updates, Network Separation is the remaining piece.

On a capable router (like Ubiquiti UniFi or pfSense), the Tuya devices get static IPs on an isolated IoT VLAN plus a firewall rule that blocks their outbound traffic to the WAN (Internet), while the Home Assistant Raspberry Pi keeps reaching them. Check out my previous article on Zone-based Firewall Rules to see exactly how to set this up!

Conclusion

Migrating away from the Tuya Cloud takes a bit of technical legwork, but the reward is a faster, more reliable, and completely private smart home infrastructure. Keeping the data processing local on the Raspberry Pi builds a resilient architecture that answers to its owner, not to a remote server.

Lukas Wojcik

Lukas Wojcik

Systems architect and technology enthusiast specializing in scalable tracking solutions, GMP Stack (GA4 & GTM), and robust backend architectures. Advocate for clean code and privacy-first design.

Get in Touch

Briefly describe your project or inquiry for a tailored response. This site is protected by reCAPTCHA.

Leave a Reply

Your email address will not be published. Required fields are marked *

ALL ARTICLES & CATEGORIES

CCTV

Follow this category by RSS

Data Privacy

Follow this category by RSS

Digital Analytics

Follow this category by RSS

Digital Marketing

Follow this category by RSS

IT & Networks

Follow this category by RSS

Raspberry PI

Follow this category by RSS

Smart Home

Follow this category by RSS

Web Development

Follow this category by RSS

Wordpress Hacks

Follow this category by RSS