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