rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
3k stars 565 forks source link

Tuya Smart Breaker (Similar to SMT006) not adding #1103

Open stumain opened 2 years ago

stumain commented 2 years ago

The problem

Have a Tuya smart breaker that is physically the same as SMT006 which is already supported. But when trying to add my device it errors: "Connection to device succeeded but no datapoints found, please try again. Create a new issue and include debug logs if problem persists." The devices are seen on the network correctly based on pulling details from Tuya Cloud.

Can add the devices using cloud Tuya integration but it only reports Current(A), Voltage(V), Active Power(kW) and Switch status (on/off). It is not reporting Leakage Value(mA) which Tuya app is showing - leakage_fault_value or leakage_current. I think the devices are based on the following: [https://developer.tuya.com/en/docs/cloud/electric-energy-open-capacity?id=Kbi599hlehgkn]

This error originated from a custom integration.

Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:259 
Integration: LocalTuya (documentation, issues) 
First occurred: October 26, 2022, 10:26:13 PM (5 occurrences) 
Last logged: 12:36:21 AM

[bf8...hzx] Failed to get status:
[bf2...emr] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 574, in detect_available_dps
    data = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 507, in status
    status = await self.exchange(STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 486, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 259, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Environment

Steps to reproduce

  1. Add new device (devices detected with details and local key correctly populated)
  2. Select either 3.1 or 3.3 protocol
  3. Error

Configuration configuration.yaml or config_flow

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

recorder:
  db_url: !secret recorder_db_url

sensor:
  - platform: systemmonitor
    resources:
        - type: processor_use
        - type: memory_free
        - type: disk_use_percent
          arg: /
        - type: disk_use
        - type: disk_free
        - type: throughput_network_in
          arg: enp0s3
        - type: throughput_network_out
          arg: enp0s3

#lametric:
#  client_id: xxxxxx-xxxxxx-xxxxx-xxxxx
#  client_secret: xxxxxxxxxxx==

#notify:
#  name: lametric
#  platform: lametric

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

switch:
  - platform: template
    switches:
      ac_lr:
        friendly_name: "Living Room AC"
        unique_id: ac_lr
        value_template: "{{ is_state('climate.ac_lr', 'cool') or is_state('climate.ac_lr', 'heat') or is_state('climate.ac_lr', 'dry') or is_state('climate.ac_lr', 'fan_only') }}"
        icon_template: >-
          {% if is_state('climate.ac_lr', 'cool') %}
            mdi:snowflake
          {% elif is_state('climate.ac_lr', 'dry') %}
            mdi:water
          {% else %}
            mdi:hvac-off
          {% endif %}
        turn_on:
          service: climate.set_hvac_mode
          target:
            entity_id: climate.ac_lr
          data:
            hvac_mode: cool
        turn_off:
          service: climate.set_hvac_mode
          target:
            entity_id: climate.ac_lr
          data:
            hvac_mode: off

DP dump

Exception raised using tuyadebug test.py script:

INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.8.2 (default, Dec 21 2020, 15:06:04) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device bf2624e25637c6a316aemr [192.168.1.191], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf2624e25637c6a316aemr","devId":"bf2624e25637c6a316aemr"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:READING AGAIN!
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.191. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes
INFO:localtuya:Detecting list of available DPS of device bf2624e25637c6a316aemr [192.168.1.191], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf2624e25637c6a316aemr","devId":"bf2624e25637c6a316aemr"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:READING AGAIN!
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.191. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes
INFO:localtuya:Detecting list of available DPS of device bf2624e25637c6a316aemr [192.168.1.191], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf2624e25637c6a316aemr","devId":"bf2624e25637c6a316aemr"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:READING AGAIN!
DEBUG:localtuya.pytuya:Failed to connect to 192.168.1.191. Raising Exception.
WARNING:localtuya.pytuya:Failed to get status: unpack requires a buffer of 20 bytes
INFO:localtuya:TIMEOUT: No response from device bf2624e25637c6a316aemr [192.168.1.191] after 2 attempts.

Using Tuya IoT platform there are no DP's listed in the getdeviceinfo / attributes / Specification....

GetDeviceSpecification

{
  "result": {
    "category": "dlq",
    "functions": [
      {
        "code": "switch_prepayment",
        "lang_config": {
          "false": "",
          "true": ""
        },
        "name": "Switch prepayment",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "lang_config": {
          "empty": ""
        },
        "name": "Clear energy",
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "charge_energy",
        "lang_config": {
          "unit": "kWh"
        },
        "name": "charge energy",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "switch",
        "lang_config": {
          "false": "OFF",
          "true": "ON"
        },
        "name": "Switch",
        "type": "Boolean",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "total_forward_energy",
        "lang_config": {
          "unit": "kWh"
        },
        "name": "Total forward energy",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "phase_a",
        "lang_config": {
          "unit": ""
        },
        "name": "Phase A",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_b",
        "lang_config": {
          "unit": ""
        },
        "name": "Phase B",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_c",
        "lang_config": {
          "unit": ""
        },
        "name": "Phase C",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "fault",
        "lang_config": {
          "credit_alarm": "credit alarm",
          "fire_alarm": "fire alarm",
          "high_power_alarm": "high power alarm",
          "leakagecurr_alarm": "",
          "magnetism_alarm": "magnetism alarm",
          "miss_phase_alarm": "",
          "no_balance_alarm": "no_balance alarm",
          "outage_alarm": "outage alarm",
          "ov_cr": "",
          "ov_vol": "",
          "overload_alarm": "",
          "self_test_alarm": "self test alarm",
          "short_circuit_alarm": "",
          "surge_alarm": "",
          "temp_dif_fault": "Temp dif fault",
          "unbalance_alarm": "unbalance alarm",
          "undervoltage_alarm": ""
        },
        "name": "Fault",
        "type": "Bitmap",
        "values": "{\"label\":[\"short_circuit_alarm\",\"surge_alarm\",\"overload_alarm\",\"leakagecurr_alarm\",\"temp_dif_fault\",\"fire_alarm\",\"high_power_alarm\",\"self_test_alarm\",\"ov_cr\",\"unbalance_alarm\",\"ov_vol\",\"undervoltage_alarm\",\"miss_phase_alarm\",\"outage_alarm\",\"magnetism_alarm\",\"credit_alarm\",\"no_balance_alarm\"]}"
      },
      {
        "code": "switch_prepayment",
        "lang_config": {
          "false": "",
          "true": ""
        },
        "name": "Switch prepayment",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "lang_config": {
          "empty": ""
        },
        "name": "Clear energy",
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "balance_energy",
        "lang_config": {
          "unit": "Kilowatt·hour"
        },
        "name": "Balance energy",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "charge_energy",
        "lang_config": {
          "unit": "kWh"
        },
        "name": "charge energy",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "switch",
        "lang_config": {
          "false": "OFF",
          "true": "ON"
        },
        "name": "Switch",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "breaker_number",
        "lang_config": {
          "unit": ""
        },
        "name": "Breaker id",
        "type": "String",
        "values": "{\"maxlen\":255}"
      }
    ]
  },

GetDeviceInformation

{
  "result": {
    "active_time": 1666792802,
    "category": "dlq",
    "category_name": "Switch Module",
    "create_time": 1666784058,
    "gateway_id": "",
    "icon": "smart/icon/bay1591839287906taVN/073f2e2ff5f3c3c3b62c096c74145863.png",
    "id": "bf2624e25637c6a316aemr",
    "ip": "x.x.x.x",
    "lat": "",
    "local_key": "xxxlocal_keyxxx",
    "lon": "",
    "model": "",
    "name": "Garden Lights Breaker",
    "online": true,
    "owner_id": "692xxxxx",
    "product_id": "r9kg2g1uhhyicycb",
    "product_name": "Breaker ",
    "sub": false,
    "time_zone": "+08:00",
    "update_time": 1666792802,
    "uuid": "490c456b2xxxxxxx"
  },

GetSpecificationAndPropertiesOfDevice

{
  "result": {
    "category": "dlq",
    "functions": [
      {
        "code": "switch_prepayment",
        "desc": "{}",
        "name": "预付费功能开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "desc": "{\"range\":[\"empty\"]}",
        "name": "电量清零",
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "charge_energy",
        "desc": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":2,\"step\":1}",
        "name": "电量充值",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "switch",
        "desc": "{}",
        "name": "断路器开关",
        "type": "Boolean",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "total_forward_energy",
        "name": "正向总有功电量",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "phase_a",
        "name": "上报A相电压,电流及功率",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_b",
        "name": "上报B相电压,电流及功率",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "phase_c",
        "name": "上报C相电压,电流及功率",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "fault",
        "name": "故障告警",
        "type": "Bitmap",
        "values": "{\"label\":[\"short_circuit_alarm\",\"surge_alarm\",\"overload_alarm\",\"leakagecurr_alarm\",\"temp_dif_fault\",\"fire_alarm\",\"high_power_alarm\",\"self_test_alarm\",\"ov_cr\",\"unbalance_alarm\",\"ov_vol\",\"undervoltage_alarm\",\"miss_phase_alarm\",\"outage_alarm\",\"magnetism_alarm\",\"credit_alarm\",\"no_balance_alarm\"]}"
      },
      {
        "code": "switch_prepayment",
        "name": "预付费功能开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "energy_reset",
        "name": "电量清零",
        "type": "Enum",
        "values": "{\"range\":[\"empty\"]}"
      },
      {
        "code": "balance_energy",
        "name": "剩余可用电量",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "charge_energy",
        "name": "电量充值",
        "type": "Integer",
        "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":999999,\"scale\":2,\"step\":1}"
      },
      {
        "code": "switch",
        "name": "断路器开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "breaker_number",
        "name": "断路器设备号",
        "type": "String",
        "values": "{\"maxlen\":255}"
      }
    ]
  }
r14n commented 2 years ago

I'm having the same issue adding a temperature and humidity sensor, my tuyadebug test.py looks pretty much the same

The error from localtuya integration says there are no datapoints when I add the device, but there are DPs when I use tinytuya wizard to poll my network and see the device

[Temperature and humidity alarm] - 192.168.100.181 - Off - DPS: {'1': 264, '2': 451, '4': 78, '9': 'f', '10': 500, '11': -10, '12': 900, '13': 100, '14': 'cancel', '15': 'cancel', '16': 88, '17': 30, '18': 30, '21': False, '23': 0, '24': 0}
stumain commented 2 years ago

I didn't know about tinytuya - cool. Just installed it and configured it. Devices detected from cloud correctly, but the scan of those devices fails:

TinyTuya (Tuya device scanner) [1.7.1]

Loaded devices.json - 2 devices:

Device Listing

[
    {
        "name": "Garden Lights Breaker",
        "id": "bf2624e25637c6xxxxxr",
        "key": "fd508xxxxxxxx",
        "mac": "fc:67:1f:2f:xx:xx",
        "category": "dlq",
        "product_name": "Breaker ",
        "product_id": "r9kg2g1uhhyicycb",
        "biz_type": 0,
        "model": "",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/bay1591839287906taVN/073f2e2ff5f3c3c3b62c096c74145863.png"
    },
    {
        "name": "Pool Breaker",
        "id": "bf8aa2ec768926xxxxx",
        "key": "861eb8xxxxxxx",
        "mac": "fc:67:1f:2f:xx:xx",
        "category": "dlq",
        "product_name": "Breaker ",
        "product_id": "r9kg2g1uhhyicycb",
        "biz_type": 0,
        "model": "",
        "sub": false,
        "icon": "https://images.tuyaeu.com/smart/icon/bay1591839287906taVN/073f2e2ff5f3c3c3b62c096c74145863.png"
    }
]

Poll local devices? (Y/n): y

Scanning local network for Tuya devices (retry 17 times)...
    0 local devices discovered

Polling local devices...
    [Garden Lights Breaker] - 0 - Error: No IP found
    [Pool Breaker] - 0 - Error: No IP found

>> Saving device snapshot data to snapshot.json

Done.

Have enabled the devices via the Tuya Smart Life app and the app is not currently running. Devices are pinging on my network.