xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"
https://xzetsubou.github.io/hass-localtuya/
GNU General Public License v3.0
284 stars 30 forks source link

[Bug]: Support for energy meter QS-Wifi-CT02 #291

Open ehran opened 3 days ago

ehran commented 3 days ago

LocalTuya Version

2024.6.0

Home Assistant Version

2024.6.4

Environment

What happened?

Unable to connect to one of my energy meter QS-WIFI-CT02 (https://www.aliexpress.com/item/1005006212527242.html)

The second one I was able to integrate first time I tried ! but the first one I am unable to repeat the steps and I am always getting the same error message.

I am able to get to the add device screen and enter the necessary details (IP, device ID, device local key) however the local tuya instance is unable to detect DPIs (error : Connection to device succeeded but no datapoints could be found. )

From the tuya developer platform I am able to query the device and see the DPs that are supposed to be available under "query properties" (see logs) but even if I insert manually some of the DPs (i.e. 101, 102...) I get the same error message.

I have tried changing the control mode instructions from the tuya dev. portal from "standard instructions" to "DP instructions" but this does not seem to help either.

My other device is 100% similar and is showing data in HA... but the first one is a stubborn sob...

Steps to reproduce.

in localtuya integration , select configure, then add new device enter IP adress, device id, local key and submit

Relevant log output

QUERY PROPERTIES
{
  "result": {
    "properties": [
      {
        "code": "sync_request",
        "custom_name": "",
        "dp_id": 101,
        "time": 1719514578406,
        "type": "enum",
        "value": "request"
      },
      {
        "code": "sync_response",
        "custom_name": "",
        "dp_id": 102,
        "time": 1719455061005,
        "type": "enum",
        "value": "idle"
      },
      {
        "code": "device_state1",
        "custom_name": "",
        "dp_id": 103,
        "time": 1719421488171,
        "type": "enum",
        "value": "working"
      },
      {
        "code": "add_ele1",
        "custom_name": "",
        "dp_id": 104,
        "time": 1719499657069,
        "type": "value",
        "value": 1
      },
      {
        "code": "cur_power1",
        "custom_name": "",
        "dp_id": 105,
        "time": 1719514578406,
        "type": "value",
        "value": 13
      },
      {
        "code": "cur_current1",
        "custom_name": "",
        "dp_id": 106,
        "time": 1719514578406,
        "type": "value",
        "value": 545
      },
      {
        "code": "cur_voltage1",
        "custom_name": "",
        "dp_id": 107,
        "time": 1719514571334,
        "type": "value",
        "value": 1205
      },
      {
        "code": "total_energy1",
        "custom_name": "",
        "dp_id": 108,
        "time": 1719513067425,
        "type": "value",
        "value": 3414
      },
      {
        "code": "today_acc_energy1",
        "custom_name": "",
        "dp_id": 109,
        "time": 1719513067425,
        "type": "value",
        "value": 17
      },
      {
        "code": "power_type1",
        "custom_name": "",
        "dp_id": 110,
        "time": 1719421488171,
        "type": "enum",
        "value": "normal"
      },
      {
        "code": "warn_power1",
        "custom_name": "",
        "dp_id": 111,
        "time": 1719421485438,
        "type": "value",
        "value": 6000
      },
      {
        "code": "today_energy_add1",
        "custom_name": "",
        "dp_id": 112,
        "time": 1719491646897,
        "type": "value",
        "value": 1
      },
      {
        "code": "device_state2",
        "custom_name": "",
        "dp_id": 113,
        "time": 1719507817184,
        "type": "enum",
        "value": "working"
      },
      {
        "code": "add_ele2",
        "custom_name": "",
        "dp_id": 114,
        "time": 1719513697441,
        "type": "value",
        "value": 1
      },
      {
        "code": "cur_power2",
        "custom_name": "",
        "dp_id": 115,
        "time": 1719514327428,
        "type": "value",
        "value": 30
      },
      {
        "code": "cur_current2",
        "custom_name": "",
        "dp_id": 116,
        "time": 1719514327428,
        "type": "value",
        "value": 59
      },
      {
        "code": "cur_voltage2",
        "custom_name": "",
        "dp_id": 117,
        "time": 1719514327428,
        "type": "value",
        "value": 1205
      },
      {
        "code": "total_energy2",
        "custom_name": "",
        "dp_id": 118,
        "time": 1719514327435,
        "type": "value",
        "value": 647
      },
      {
        "code": "today_acc_energy2",
        "custom_name": "",
        "dp_id": 119,
        "time": 1719514327435,
        "type": "value",
        "value": 182
      },
      {
        "code": "power_type2",
        "custom_name": "",
        "dp_id": 120,
        "time": 1719421431130,
        "type": "enum",
        "value": "normal"
      },
      {
        "code": "warn_power2",
        "custom_name": "",
        "dp_id": 121,
        "time": 1719421493622,
        "type": "value",
        "value": 6000
      },
      {
        "code": "today_energy_add2",
        "custom_name": "",
        "dp_id": 122,
        "time": 1719513967468,
        "type": "value",
        "value": 1
      },
      {
        "code": "all_energy",
        "custom_name": "",
        "dp_id": 123,
        "time": 1719514327428,
        "type": "value",
        "value": 4061
      },
      {
        "code": "net_state",
        "custom_name": "",
        "dp_id": 124,
        "time": 1719421431130,
        "type": "enum",
        "value": "cloud_net"
      }
    ]
  },
  "success": true,
  "t": 1719514590447,
  "tid": "f6fc72d334b611ef9c7442b1fe1466b5"
}

Diagnostics information.

No response

xZetsubou commented 3 days ago

Without logs we don't know what happening here, maybe ur device is low-power device maybe not, I'm not sure however enable the debug for both integration and when you connect to the device check on the "enable debug for the device then connect if it fails post the logs here...

ehran commented 2 days ago

I've uploaded the diags from the localtuya plugin, I do not see the failing energy meter appearing however, same for the HA logs, no mention of the device... am I missing a log somewhere ? Both devices are on the same power socket so unless the failing device has a hardware issue, they really are installed the exact same way. config_entry-localtuya-776d96a82796e55e115ca5598d8dbb0b(2).json

xZetsubou commented 2 days ago

am I missing a log somewhere ?

You need to enable the debug for both integration and device... Report an issue

The entry diags you posted contains all the devices you have already set-up I don't know which one has the issue and also if it's already added or not.

ehran commented 1 day ago

Thanks, I followed the steps above and restarted HA.

I checked 2 files, home-assistant.log and the config_entry-localtuya. Please let me know if I am missing a place that needs checking.

These are the mentions in the home-assistant.log pertaining to the missing energy meter (I am searching by device ID 'eb9b8b0c94e25ee065hlbh'): 2024-06-29 22:29:11.847 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.1.145', 'gwId': 'eb9b8b0c94e25ee065hlbh', 'uuid': '19fca43f552bc628', 'active': 2, 'ablilty': 0, 'encrypt': True, 'productKey': 'dhto3y4uachr1wll', 'version': '3.5', 'token': True, 'wf_cfg': True, 'clientLink': 3}

then later on:

2024-06-29 22:44:38.464 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending command 10 (device type: type_0a) DPS: None 2024-06-29 22:44:38.465 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending payload: b'{"gwId":"eb9b8b0c94e25ee065hlbh","devId":"eb9b8b0c94e25ee065hlbh","uid":"eb9b8b0c94e25ee065hlbh","t":"1719715478"}' 2024-06-29 22:44:38.473 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Command 10 waiting for seq. number 1 2024-06-29 22:44:38.869 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb2...jyr - Lampster (localtuya)] Dispatching message CMD 9 TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crc_good=True, prefix=21930, iv=None) 2024-06-29 22:44:38.874 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb8...gck - Lampe terre cuite (localtuya)] Dispatching message CMD 9 TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crc_good=True, prefix=21930, iv=None) 2024-06-29 22:44:38.877 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Connection lost: [Errno 104] Connection reset by peer 2024-06-29 22:44:38.878 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Cleaning up session. 2024-06-29 22:44:38.879 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Wait was aborted for seqno 1 2024-06-29 22:44:39.017 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending command 10 (device type: type_0a) DPS: None 2024-06-29 22:44:39.017 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending payload: b'{"gwId":"eb9b8b0c94e25ee065hlbh","devId":"eb9b8b0c94e25ee065hlbh","uid":"eb9b8b0c94e25ee065hlbh","t":"1719715479"}' 2024-06-29 22:44:39.019 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Command 10 waiting for seq. number 1 2024-06-29 22:44:40.205 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb8...djh - Wattmetre VE-Cuisinière] Dispatching message CMD 8 TuyaMessage(seqno=43309, cmd=8, retcode=0, payload=b'3.5\x00\x00\x00\x00\x00\x01\x97\xfd\x00\x00\x00\x01{"protocol":4,"t":1719715479,"data":{"dps":{"103":"monitor","105":0,"106":0,"101":"request"}}}', crc=b'\xe6\xaf\x11g\x96?\xed\xd8\x82\n#P\xe4YX\xca', crc_good=True, prefix=26265, iv=b'>\xad5\x8e\xda\xb1\x1e~\xf7FW\x97') 2024-06-29 22:44:40.608 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Connection lost: [Errno 104] Connection reset by peer 2024-06-29 22:44:40.609 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Cleaning up session. 2024-06-29 22:44:40.611 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Wait was aborted for seqno 1 2024-06-29 22:44:40.619 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb6...eo3 - Deshumidificateur (localtuya)] Dispatching message CMD 9 TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211, crc_good=True, prefix=21930, iv=None) 2024-06-29 22:44:40.715 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending command 10 (device type: type_0d) DPS: None 2024-06-29 22:44:40.716 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Sending payload: b'{"devId":"eb9b8b0c94e25ee065hlbh","uid":"eb9b8b0c94e25ee065hlbh","t":"1719715480","dps":{"1":null,"2":null,"3":null,"4":null,"5":null,"6":null,"7":null,"8":null,"9":null,"10":null}}' 2024-06-29 22:44:40.720 DEBUG (MainThread) [custom_components.localtuya.core.pytuya] [eb9...lbh] Command 13 waiting for seq. number 1

In the config_entry-localtuya JSON file, it does not appear which seems to be consistent with the fact that only added devices appear in that config file.

Thanks for the help and thanks for your work.

xZetsubou commented 6 hours ago

Try to fully turn off the device "from the power" then power it on back and re-add the device ensure to select protocol version 3.5.