smart home circle
Smart Home Circle
Published on

How To Setup Local Tuya With Home Assistant

How To Setup Local Tuya With Home Assistant
6 min read
Authors

In this article, we will be looking at how we control Tuya Devices Locally using Local Tuya.

Table of Contents

Pre-Requisites

  1. You have Home Assistant OS or Home Assistant Container setup.

You can check this article if you setting up Home Assistant OS for the first time or this article if you want to set up Home Assistant Container.

  1. You have HACS Installed.

If you have not installed it, here is a step-by-step guide to install it on Home Assistant OS and Home Assistant Docker container.

  1. Any Tuya device. In this case, we will be using the Tuya Wifi Plug.

You can buy it from this link:

  1. Tuya device setup with either Tuya app or Smart Life app.

Installing Local Tuya Integration in Home Assistant

Once you have HACS installed, head over to the HACs interface, click on “Explore and Download Repository” and search for Local Tuya Integration.

1-hacs-local-tuya

Once you find it, click on it and

Next, in Home Assistant UI, click on “Settings” in the left panel and then click on “Devices & Services”, then click on “Add integration” on the bottom right-hand corner.

Next, search for “Zigbee Home Automation” and click on the “Download” button, select the latest version, and click “Ok”.

Once the repository gets downloaded you will have add the integration.

For this, go to “Settings” then “Devices & Services”, click on “Add Integration” and search for Local Tuya.

2-integration-local-tuya

Now, it will ask you for a Cloud API integration.

Since we are not going to integrate with the cloud, click the checkbox a the bottom “Do not configure Cloud API Account”

3-no-cloud-api-integration

With this, the Local Tuya Integration is ready for use.

Adding Device To Home Assistant using Local Tuya

Now, let’s consider you have your Tuya device connected to your Wifi network using the Smart Life app.

Next, make sure to connect the plug to a power outlet and then connect some device to it such that it's consuming some energy. (It could be your phone charger actively charging your mobile phone).

We would be using the values of the energy consumption that shows up in the Smart Life app to properly configure the plug in Local Tuya.

With this done we will search for this plug which is connected to your Wifi network using the Local Tuya integration.

For this, we will open the Local Tuya Integration and click on “Configure” and then select the action “Add a new Device”.

4-add-local-tuya-device

Now, it will show you the device id of your Tuya device.

5-device-id-local-tuya

You can verify the device id of your device by checking the “device information” in the Smart Life app as shown above.

Next, we will have to fill in the local key.

6-empty-local-key

For this, we will have to create a Tuya developer account to find the Local key.

Finding Local Key For Tuya Devices

To find the Local key, you will have to create a Tuya developer account.

We will only need this account to find the Local Key and then we can delete the account.

For this, head to https://iot.tuya.com/ and create a developer account.

Once you have logged in, click on the “Cloud” icon on the left menu bar and then click on “Create Cloud Project”

Here, specify any project name, any industry, any development method, and then any data center that you wish.

Remember we won’t be needing this project after we find the Local keys.

7-cloud-project

Once the project is created, click on the “Devices” tab and then click on “Link Tuya app”.

8-link-app

Now, scan the QR code using your Smart Life app, by selecting the add device option in the app and scan the QR code.

With this, the app is now linked to the cloud project.

Next, click on “Cloud” on the left panel and select “API Explorer”

9-api-explorer

This will open in a new tab.

Now, in this new tab, click on “Device Management” in the left panel and then click on “Query Device Details”, enter the device id of your tuya device, and click on “Submit Request”

10-query-device

This will show a response. You need to now use the Local Key in the response as shown below.

11-local-key

Adding Local Key to Local Tuya Device

Once you have figured out the Local Key, add it to the Local Tuya setup.

12-configure-local-key

Now click next and here we will configure the Consumption value.

For this, open the power consumption section in the Smart Life app and check the current consumption values.

You will have to select the values that are close to the values in the drop. You can ignore the decimal points, but if the numbers match you can probably use the value.

13-select-voltage-values

For example, in the above image, the voltage value even though it shows, 232.1, you can select the number 2321.

Same thing you would have to do for the current and current consumption values.

Once you do that click on finish.

You should be able to see the plug now in Home Assistant.

14-switch-home-assistant

Verify Energy Consumption Values

To verify the energy consumption values are correct, click on the “Developer Tools” in Home Assistant and select the “States” tab.

Now here filter the entities by the switch entity name you gave.

Now in the fouth column compare the values with the Smart Life app.

If they match, it's all good.

But if they are not correct and don’t match that on the app, you will have to reconfigure the values.

For this, you can head over to the Local Tuya Integration again, Click on “Configure” then this time select “Edit a device”

15-edit-device

Now, when you create the energy consumption value section, you will just have to try with a different value and see if it works.

Its a bit difficult to get it correct in the first go, so you might have to keep trying different values for sometime. 🙂

Once you find the correct values, it should be all fine.

16-correct-consumption-values

If you are interested in more such Home Automation Setups and Ideas, you can read the following three articles