Local Tuya - Control Tuya devices locally (Fork from localtuya)

Hi @umu_ugg , thanks for keeping localtuya alive!

I’m experiencing an issue, which perhaps you can help with. I have a Nedis Smart Plug which was working previously on HomeAssistant with rospogrigio’s localtuya. By accident I put it on pairing mode so I used the Tuya Smart app to bring it back to my wifi network. Homeassistant didn’t connect to it so I removed it and add it back on LocalTuya only to find the error: Connection to device succeeded but no datapoints could be found. Please try set-up again. If problem persists, create a new issue (including debug logs). . Meanwhile I’ve migrated to your branch of localtuya, version 2024.7.0, but I keep getting the same error… :slightly_frowning_face:

I know this smart plug is compatible with LocalTuya/HomeAssistant because I have a second one working fine.

Logs:

2024-08-12 17:07:00.567 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration localtuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-08-12 17:07:00.568 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hon which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-08-12 17:07:00.569 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-08-12 17:09:01.431 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] 3.4 or 3.5 device: negotiating a new session key
2024-08-12 17:09:01.432 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] final payload for cmd 3: b'0123456789abcdef'
2024-08-12 17:09:01.434 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 waiting for seq. number -102
2024-08-12 17:09:01.456 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Connection lost: None
2024-08-12 17:09:01.457 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.
2024-08-12 17:09:01.458 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] received null payload (None), fetch new one - 1 retries remaining
2024-08-12 17:09:01.458 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 waiting for seq. number -102
2024-08-12 17:09:06.460 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 timed out waiting for sequence number -102
2024-08-12 17:09:06.461 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] received null payload (None) but out of recv retries, giving up
2024-08-12 17:09:06.461 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] session key negotiation failed on step 1
2024-08-12 17:09:06.461 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.
2024-08-12 17:09:06.462 DEBUG (MainThread) [custom_components.localtuya.config_flow] [bf0...ol5 - Plug] Detected DPS: {}
2024-08-12 17:09:06.462 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Closing connection
2024-08-12 17:09:06.462 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.
2024-08-12 17:10:20.118 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] 3.4 or 3.5 device: negotiating a new session key
2024-08-12 17:10:20.118 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] final payload for cmd 3: b'0123456789abcdef'
2024-08-12 17:10:20.120 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 waiting for seq. number -102
2024-08-12 17:10:20.143 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Connection lost: None
2024-08-12 17:10:20.143 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.
2024-08-12 17:10:20.144 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] received null payload (None), fetch new one - 1 retries remaining
2024-08-12 17:10:20.144 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 waiting for seq. number -102
2024-08-12 17:10:25.146 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Command 3 timed out waiting for sequence number -102
2024-08-12 17:10:25.146 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] received null payload (None) but out of recv retries, giving up
2024-08-12 17:10:25.146 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] session key negotiation failed on step 1
2024-08-12 17:10:25.146 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.
2024-08-12 17:10:25.147 DEBUG (MainThread) [custom_components.localtuya.config_flow] [bf0...ol5 - Plug] Detected DPS: {}
2024-08-12 17:10:25.147 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Closing connection
2024-08-12 17:10:25.147 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [bf0...ol5] Cleaning up session.

Device diagnostics:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.1.3",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.11.6",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Lisbon",
    "os_name": "Linux",
    "os_version": "6.1.63-haos-raspi",
    "supervisor": "2024.08.0",
    "host_os": "Home Assistant OS 11.4",
    "docker_version": "24.0.7",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "localtuya": {
      "version": "2024.7.0",
      "requirements": []
    },
    "hon": {
      "version": "0.13.0",
      "requirements": [
        "pyhOn==0.16.0"
      ]
    },
    "hacs": {
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "localtuya",
    "name": "Local Tuya",
    "codeowners": [],
    "config_flow": true,
    "dependencies": [],
    "documentation": "https://github.com/xZetsubou/hass-localtuya/",
    "integration_type": "hub",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/xZetsubou/hass-localtuya/issues",
    "requirements": [],
    "version": "2024.7.0",
    "is_built_in": false
  },
  "data": {
    "region": "eu",
    "username": "localtuya",
    "no_cloud": true,
    "client_id": "...",
    "client_secret": "...",
    "user_id": "...",
    "devices": {
      "bf0c1b3ecccf3abe2coeav": {
        "friendly_name": "Nedis Smart Plug 1",
        "host": "192.168.9.68",
        "device_id": "bf0c1b3ecccf3abe2coeav",
        "local_key": "?WI...q3k",
        "protocol_version": "3.4",
        "enable_debug": false,
        "dps_strings": [
          "1 (value: True)",
          "9 (value: 0)",
          "18 (value: 0)",
          "19 (value: 0)",
          "20 (value: 2338)",
          "21 (value: 1)",
          "22 (value: 0)",
          "23 (value: 0)",
          "24 (value: 0)",
          "25 (value: 0)",
          "26 (value: 0)",
          "38 (value: memory)",
          "39 (value: False)",
          "40 (value: relay)",
          "41 (value: False)",
          "42 (value: )",
          "43 (value: )",
          "44 (value: )"
        ],
        "entities": [
          {
            "id": "1",
            "friendly_name": "Toalheiro",
            "restore_on_reconnect": false,
            "is_passive_entity": false,
            "platform": "switch"
          }
        ],
        "product_key": "keya5yka7xy4ttmp"
      },
    "updated_at": "1723478624082",
    "cloud_devices": {}
  }
}

“Nedis Smart Plug 1” is the smart plug that is essentially the same plug as the one I’m trying to add.

I’m not sure what’s going on or how to fix this. Any tips are welcomed. Thanks in advance!

thank you soo much! I was about to give up with the Ledvance lamps when I found out this fork :smiley:

I have this device, I added all the DPs to localtuya, and it works just fine.

Problem is some of the DPs are sensors yet they show up as editable on the device page (see below). I have been messing around with reconfiguring the device and can’t find the solution, whether I place the DPs under Controls or Configuration or None, it doesn’t seem to make a difference. Setting “Device Class” (or not) doesn’t seem to make any difference either.

For example, “Presence” is defined as enum in Tuya, but should realistically appear as a binary sensor: “None” or “Detected”. “Light Intensity” and “Target Distance” should be read-only numbers.

Is this fixable?

Binary Sensor accept 1 “ON” value so you can use Detected as on value, otherwise you many want to set the Presence entity as “sensor”

1 Like

Hi everyone,

I recently installed this integration as I wanted to get more info and entities out of my existing Tuya devices.

This is the only install of localtuya I have, as I read somewhere this fork has more options. I do have the native HA Tuya integration installed and working normally.

I was able to connect to my Tuya account and now have a valid hub. However, no devices at all are detected automatically!

I’m thinking there must be a simple mistake I’ve made where the auto-detection is not finding any of the 20+ Tuya devices I have connected to HA.

Any thoughts on where to start troubleshooting?

Hello community!

First of all, thank you very much for this repository.

I have a Tuya WiFi-ZigBee-BLE gateway and a BLE light in my Smart Life App. When I try to integrate the light to LocalTuya in Home Assistant, it tells me that it has a connection with the device but it can’t find the DPs.

Debug:
2024-10-03 14:10:09.407 DEBUG (MainThread) [custom_components.localtuya.config_flow] [ebd…fgd - Lámpara Guada] Detected DPS: {}

I tried changing other repositories (fork by Rodrigo) but I still can’t integrate the light to my home assistant.

I would appreciate some advice on what I can do or what I need to configure.



Usually BLE lights doesn’t have status to return or report it states if changed well it’s like write-only to add these devices try adding 0 in manual DPS field

I am in same situation that HA and Tuya BT gateway are in 2 different subnet, connected by a site-to-site VPN.

I’ve added independent Wifi device successfully, so that network setup should be fine. But I have no idea how to add BT device under the gateway, since auto discovery not work even I’ve followed posts in below to enable port forwarding.

Thanks to this post to tell that a Node ID maybe the missing piece in manual setup. Does anyone know how to get the Node ID of sub-devices (when auto discovery not work)?

Hi umu-ugg, thanks for the guidance. Maybe you can share more light about how to find the node id?

My case is that HA server & Tuya BT Gateway in 2 difference subnet, so auto discovery won’t work. I can successfully add other Wifi devices by manual setup, so I think the network is fine, except for the BT Gateway & it’s sub devices.

Where to find the entry diagnostics?

I can’t install the latest update because several devices stop working (now that I think about all the relays that have a consumption meter), the error it gives me is migration error. I already tried twice and I had to put a backup copy again! What I do? any way to solve? That’s all the information it gives me, I looked at the log, and in the log it tells me that it found those entities that are no longer provided by tuya local

Based off your helpful hint, I integrated it like this:
I made two “select” entities, on for movement on DP 101 with move_up;move_down;default;cancel and the other for memory on DP 103 with mem1;mem2;mem3;recall1;recall2;recall3;cancel. If you want you can also make a sensor on DP 105 to read the fault codes. Then I made some scripts to set the move or memory option that I want (mostly just recall1 and recall2, since what else do you really need when the tv is in a cabinet) and use that in any automations.

I just came here to say thank you!

I spent hours trying to manually set up a new light using the old localtuya integration with no luck. I tried your fork, and everything was set up and working in seconds! It turns out that my new light bulb was using the firmware version 3.5, which wasn’t even an option in the old localtuya.

You’ve saved me a ton of headache.

Thanks for your work on this.

Maybe the two projects can merge at some point when the other is more active again?

Thank you so much for this!!!

I spent days trying to manually set up 15 new tuya lights using the old localtuya integration. I stumbled upon this thread on one of my google searches on how to make the integration work and installed your custom repo. Everything was set up and working in seconds! Looks like my new light bulbs are actually using the firmware version 3.5, which is not even listed in the other localtuya integration.

Thank you so much for your work on this.

First of all, congratulations for this great work.
I don’t know if already a place to share templates, but I spent a lot of time configuring some specific devices as best as possible and wanted to share it for others to use:

https://www.dropbox.com/scl/fo/fvj3uo2bhjcmrg5uf7f2k/AJkGjguPf6E_DgbZhTZ0gqw?rlkey=45fq6kb9j6vqhr6cfoaxpcko0&st=eds6jnru&dl=0 12

Here is the device list:

Aubess Smart Switch/EM Wifi Socket
Avatto Wall Socket with USBTypeC
Cloudraker ZG-204L PIR sensor
Emteco Wifi blind motor
Generic RTCZ01 Human presence sensor 5.8G
Lock Intelbras IFR7001
Loginovo Human presence sensor 5.8G
RightSitu S18 IR WiFi control
Weten PCIe RF Computer switch
Zigbee Luminance Motion sensor
Zemismart Metering 3PN Zigbee
Zemismart ZM25RW01 Blind motor
Generic Zigbee Luminance Motion sensor

Simple download the template, and put in:

config\custom_components\localtuya\templates

And configure new device from a template

How can I submit these templates to be integrated into the main code to be part of the list of supported devices?

1 Like

First of all thank you for the integration. I have a switch with power measure capabilities from Antela, using protocol 3.4, which seems to be supported by the integration. Something weird that I noticed recently is that the Voltage sensor is updated almost every second. Same behavior with the old localtuya. Is that normal? Is there a way to change it? I think it could be affecting the device somehow (the frequent unavailable/working cycles).

I installed this fork of LocalTuya in place of my original setup using the upstream rospogrigio version.

Initially HomeAssistant complained on restart, but I just redownloaded this fork in HACS and everything worked fine (except for my dashboard device names changing to their original defaults).

However, in my Home Assistant log I get this ‘warning’:

Logger: homeassistant.const
Source: helpers/deprecation.py:222
First occurred: 12:46:43 (14 occurrences)
Last logged: 12:46:52

STATE_ALARM_DISARMING was used from localtuya, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.DISARMING instead, please report it to the author of the 'localtuya' custom integration
STATE_ALARM_TRIGGERED was used from localtuya, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.TRIGGERED instead, please report it to the author of the 'localtuya' custom integration
STATE_ALARM_DISARMED was used from localtuya, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.DISARMED instead, please report it to the author of the 'localtuya' custom integration
STATE_ALARM_ARMED_HOME was used from localtuya, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.ARMED_HOME instead, please report it to the author of the 'localtuya' custom integration
STATE_ALARM_ARMED_AWAY was used from localtuya, this is a deprecated constant which will be removed in HA Core 2025.11. Use AlarmControlPanelState.ARMED_AWAY instead, please report it to the author of the 'localtuya' custom integration

Is this something I need to worry about when HA 2025.11 gets here?

Well yes, but that’s a long way away. And in any case, the developer of the integration has just committed a fix that will likely appear in an update pretty soon.

If the integration is otherwise currently working for you, there’s nothing to worry about overall. The developer xZetsubou is very active, so we’re in good hands.

2 Likes

Repositing my issue from 9/26 as it still is not remedied.

I’m attempting to use the cloud API account to easily get the information for my Tuya devices.

I’ve double/triple checked my client ID, secret, and User ID for my cloud API account. Using the tutorial posted here:
https://xzetsubou.github.io/hass-localtuya/cloud_api/

I don’t encounter any errors when I submit the information. Logs don’t reveal any issue. I just don’t get any devices detected.

2024-11-24 19:45:24.295 DEBUG (MainThread) [custom_components.localtuya.core.cloud_api] [az1...YJG] Devices has been updated a minutes ago.
2024-11-24 19:45:29.111 INFO (MainThread) [custom_components.localtuya.core.cloud_api] [az1...YJG] Cloud API connection succeeded.
2024-11-24 19:45:29.866 INFO (MainThread) [custom_components.localtuya.core.cloud_api] [az1...YJG] Cloud API connection succeeded.

Is the Username supposed to stay “localtuya”?

EDIT:
I tried using the original localtuya and I am getting the same results, no entities/devices but also no error codes. I think there must be something not configured right in my account on Tuya cloud api?

EDIT2:
I went through the process of making a whole new cloud API project and thought I found where I went wrong. I had a pre-existing project I was using that I configured differently. In the “Development Method” field I had selected “custom” instead of “Smart Home.” You can’t change it back after the fact, it looks like.

HOWEVER, trying to link that new project’s client ID/secret and UID gives me the same result, no devices downloaded. :roll_eyes: Darn, thought I had cracked it.

EDIT3: Maybe this is a silly question, but is it okay to have HA’s native Tuya integration running along with localtuya?

EDIT4: I do have my Tuya devices on another VLAN. I don’t think that would necessarily be an issue because the regular Tuya integration sees them just fine.

What do you mean by not detected? like they don’t shows up in discovering devices step? Discovery won’t works if you having the devices on separated VLAN from HA. Also devices discovery works over LAN not cloud unlike “official integration” they aren’t the same.

However it’s possible to use other features.

If you want to retrieve the data of your devices it also possible by download entry diagnostics After opening JSON file you will find your devices data in “cloud_devices” object.

Maybe this is a silly question, but is it okay to have HA’s native Tuya integration running along with localtuya

It should be fine, In normal cases they shouldn’t interfere with each other. native works over cloud this works locally.

1 Like

Thank you for your reply!

To clarify, yes all my Tuya devices are on a different VLAN. So I would not expect the built-in LAN discovery to find them.

I was hoping, however, the cloud API option would be able to bypass that.

Is it correct then, that the cloud API just provides a list of devices, but because they are on a different VLAN, localtuya cannot proceed with adding them, because it is only looking on the same VLAN?

Here’s a shot of what I have with a properly configured cloud api account.