Skip to main content
Skip table of contents

Enabling Local Control for your Tuya Devices

Local control allows HomeSeer to monitor and control devices directly without using the Tuya cloud

Overview

By default the Tuya plugin always use the official Tuya cloud API to communicate with your devices, however it also supports local control for a few products. The list of supported products is a JSON file in your HS4 installation directory: Data/Tuya/LocalApiProducts.json. This article describes how to add local control to your own product by editing this file.

Local control support for Tuya devices is based on reverse engineering of the Tuya local API, and because there are a lot of different Tuya devices that can have subtle differences in the way they work, we cannot guarantee that local control will work for your devices and we will offer very limited help for this.

Also, remember that even when local control is enabled for a device, the plugin still needs to access the Tuya cloud at startup to know what functions your devices support, so the plugin always must to be able to access the internet at start up.

Step-by-step guide

  1. From Plugins > Tuya > Manage Devices, write down the local IP of the device for which you want to add local control

    If no IP address appear in this column for the device, it means the plugin wasn't able to discover it on your local network. This may be caused by UDP broadcast sent by your Tuya devices not being able to reach your HS4 system (including Windows-based HomeTroller hubs). To correct this, you may need to create inbound and outbound rules for your Windows firewall. See the Local IP Address section below for details.

  2. From Plugins > Tuya > Settings, click the Logging tab and set the Log Level to Debug
  3. Disable the plugin from Plugins > Manage
  4. Edit Config/Tuya.ini and add the following line in the [GENERAL] section:

    CODE
    send_dp_query=True
  5. Enable the plugin again
  6. From Tools > Log, look for the 4 lines similar to the ones below that match the local IP Address of your device. Copy and paste those lines to a temporary text file



  7. From Devices, click on your device and go to the Tuya tab, then scroll down to the Device section


  8. Edit  Data/Tuya/LocalApiProducts.json and add a product like on the screenshot below
    1. product_id must be the one you found at step 7
    2. product_desc should be a description of your device brand and model
    3. version must be the one found  at step 6  (either 3.1 or 3.3)
    4. func_mapping must be a list of status code found at step 7 and the values for these codes must be the ids of the dps list found at step 6. For example my dps list found at step 6 is "dps":{"1":false,"2":0,"4":0,"5":0,"6":1173}, so I match "switch" with "1", "countdown_1" with "2", "cur_current" with "4", etc. Most probably the codes from step 7 and the ids from step 6 will be in the same order, but you can also double check that the values reported for code/ids in step 6 and 7 are the same, for example we can see that both cur_voltage code from step 7 and id #6 from step 6 report the same value of 1149



      Be careful about the braces, commas and quotes, so that end result is a valid JSON file.

  9.  Save the file, then restart the Tuya plugin by disabling it and enabling it again from Plugins > Manage
  10. From Devices, click on your device and go to the Tuya tab, you should now see something like the following screenshot:

  11. Enable the Use Local Connection switch and Save, then go back to Devices, you will see a new "Local Connection" feature that should have its status set to Connected



    To make sure the local connection works as expected, go to Tools > Log and you should see these kind of Ping/Pong messages every 10 seconds:



  12. If everything works as expected, you can remove the "send_dp_query=True" line from the Tuya.ini file, and set the "Log Level" back to Info.
  13. If you reinstall or update the Tuya plugin, your changes made to LocalApiProducts.json will be overwritten. Be sure to make a copy of this file with your changes, you can use to overwrite the default one any time you reinstall or update the plugin.

Local IP Address

  • Requires version 4.0.29 or later of the Tuya plugin

The local IP Address of compatible devices will show up in the respective column. If a checkmark is present, the device is locally connected. This means that the device is communicating directly to HomeSeer and not going through the Tuya cloud. Local Control allows for a more secure connection and reduces dependency on the Tuya cloud. If no IP address is showing, you may need to adjust your Windows firewall settings; skip to the section below.

Windows Firewall Settings

On Windows systems, you may need to modify your firewall settings to enable local control to work properly. On Linux systems such as the HomeTroller PI you do not need to modify the firewall.

If your Windows Defender Firewall is enabled (or any third party firewall) you will need to open some ports for local control to work properly.

  1. Open the Windows Defender Firewall control panel
  2. Click Advanced settings
  3. Select Inbound Rules in the left pane and then click New Rule... in the right pane. The New Inbound Rule Wizard will pop up.
  4. Click the Port radio button, then click Next
  5. Click UDP, then type 6666, 66677 into the Specific local ports: field, then click Next
  6. Click Allow the connection, then click Next
  7. Leave the the Domain, Private and Public rule options checked
  8. Name the rule Tuya Inbound Ports and click Finish
  9. Now, repeat the process but create an Outbound Rule instead for TCP port 6668
  10. Name this one Tuya Outbound Port and click Finish

When viewing your Tuya devices from the "Manage Devices" menu in the Tuya plugin you should see the IP address of your device. If the IP address is not displaying, try the following:

  1. Power cycle the Tuya device
  2. Select "Manage Devices" from the Tuya plugin menu then click the "Reload Devices" button. This will start the discovery process so the plugin can find the devices IP address.
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.