Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Device Support Request] PC311-Z-TY Single-Phase Power Clamp Zigbee model 'TS0601' and manufacturer name '_TZE200_rks0sgb7 #2650

Open
lepalom opened this issue Oct 15, 2023 · 36 comments
Labels
device support request This requests support for a new device Tuya Request/PR regarding a Tuya device

Comments

@lepalom
Copy link

lepalom commented Oct 15, 2023

Problem description

I would like to kindly ask to support this device:

[PC311-Z-TY Single-Phase Power Clamp Zigbee] (https://es.aliexpress.com/item/1005005931365212.html)

This device is the same commented here, in the zigbee2mqtt project.

Solution description

Fully integrated in HA.

Screenshots/Video

No response

Device signature

Device signature
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0051",
      "input_clusters": [
        "0x0000",
        "0x0004",
        "0x0005",
        "0xef00",
        "0xff66"
      ],
      "output_clusters": [
        "0x000a",
        "0x0019"
      ]
    }
  },
  "manufacturer": "_TZE200_rks0sgb7",
  "model": "TS0601",
  "class": "zigpy.device.Device"
}

Diagnostic information

Diagnostic information
{
  "home_assistant": {
    "installation_type": "Home Assistant Supervised",
    "version": "2023.10.3",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.11.5",
    "docker": true,
    "arch": "armv7l",
    "timezone": "Europe/Andorra",
    "os_name": "Linux",
    "os_version": "5.10.0-25-armmp",
    "supervisor": "2023.10.0",
    "host_os": "Debian GNU/Linux 11 (bullseye)",
    "docker_version": "24.0.6",
    "chassis": "",
    "run_as_root": true
  },
  "custom_components": {
    "sunspec": {
      "version": "0.0.25",
      "requirements": [
        "pysunspec2==1.0.8"
      ]
    },
    "edata": {
      "version": "2023.06.3",
      "requirements": [
        "e-data==1.1.5",
        "python-dateutil>=2.8.2"
      ]
    },
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "template_sensor": {
      "version": "v1.0.0",
      "requirements": []
    },
    "local_sofar_inverter": {
      "version": "0.0.1",
      "requirements": []
    },
    "solarman": {
      "version": "1.0.0",
      "requirements": [
        "pyyaml"
      ]
    }
  },
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "after_dependencies": [
      "onboarding",
      "usb"
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "config_flow": true,
    "dependencies": [
      "file_upload"
    ],
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp",
      "universal_silabs_flasher"
    ],
    "requirements": [
      "bellows==0.36.5",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.104",
      "zigpy-deconz==0.21.1",
      "zigpy==0.57.2",
      "zigpy-xbee==0.18.3",
      "zigpy-zigate==0.11.0",
      "zigpy-znp==0.11.5",
      "universal-silabs-flasher==0.0.14",
      "pyserial-asyncio-fast==0.11"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "1A86",
        "pid": "55D4",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus v2"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "0403",
        "pid": "6015",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate+"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      },
      {
        "type": "_zigate-zigbee-gateway._tcp.local.",
        "name": "*zigate*"
      },
      {
        "type": "_zigstar_gw._tcp.local.",
        "name": "*zigstar*"
      },
      {
        "type": "_uzg-01._tcp.local.",
        "name": "uzg-01*"
      },
      {
        "type": "_slzb-06._tcp.local.",
        "name": "slzb-06*"
      }
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 15828,
    "manufacturer": "_TZE200_rks0sgb7",
    "model": "TS0601",
    "name": "_TZE200_rks0sgb7 TS0601",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4098,
    "power_source": "Mains",
    "lqi": 255,
    "rssi": -65,
    "last_seen": "2023-10-15T20:04:46",
    "available": true,
    "device_type": "Router",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4098, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": "0x0104",
          "device_type": "0x0051",
          "input_clusters": [
            "0x0000",
            "0x0004",
            "0x0005",
            "0xef00",
            "0xff66"
          ],
          "output_clusters": [
            "0x000a",
            "0x0019"
          ]
        }
      },
      "manufacturer": "_TZE200_rks0sgb7",
      "model": "TS0601"
    },
    "active_coordinator": false,
    "entities": [],
    "neighbors": [
      {
        "device_type": "Coordinator",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0000",
        "permit_joining": "Unknown",
        "depth": "0",
        "lqi": "159"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x44A6",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "26"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x816A",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "123"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Parent",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xE50B",
        "permit_joining": "Unknown",
        "depth": "15",
        "lqi": "245"
      }
    ],
    "routes": [
      {
        "dest_nwk": "0x0000",
        "route_status": "Active",
        "memory_constrained": false,
        "many_to_one": true,
        "route_record_required": false,
        "next_hop": "0x0000"
      }
    ],
    "endpoint_names": [
      {
        "name": "SMART_PLUG"
      }
    ],
    "user_given_name": "Mesurador Quadre El\u00e8ctric TS0601",
    "device_reg_id": "f87029d1f630706adc199937f095b52a",
    "area_id": "entrada",
    "cluster_details": {
      "1": {
        "device_type": {
          "name": "SMART_PLUG",
          "id": 81
        },
        "profile_id": 260,
        "in_clusters": {
          "0x0000": {
            "endpoint_attribute": "basic",
            "attributes": {
              "0x0004": {
                "attribute_name": "manufacturer",
                "value": "_TZE200_rks0sgb7"
              },
              "0x0005": {
                "attribute_name": "model",
                "value": "TS0601"
              }
            },
            "unsupported_attributes": {}
          },
          "0x0004": {
            "endpoint_attribute": "groups",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0005": {
            "endpoint_attribute": "scenes",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0xef00": {
            "endpoint_attribute": null,
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0xff66": {
            "endpoint_attribute": "manufacturer_specific",
            "attributes": {},
            "unsupported_attributes": {}
          }
        },
        "out_clusters": {
          "0x0019": {
            "endpoint_attribute": "ota",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x000a": {
            "endpoint_attribute": "time",
            "attributes": {},
            "unsupported_attributes": {}
          }
        }
      }
    }
  }
}

Logs

No response

Custom quirk

In Koenkk/zigbee2mqtt#18734 they have configured it.

Additional information

No response

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label Oct 16, 2023
@KPfff
Copy link

KPfff commented Oct 29, 2023

Got in the email from vladii07 an attempt at mapping values with external converter. Not so proficient in github - just posting my findings.

Tested it as I have exactly the device as linked above.

My comments are added to initial comments like this "- comment"

`const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;
const {Buffer} = require('buffer');

const valueConverter = {
divideBy10: tuya.valueConverterBasic.divideBy(10),
divideBy100: tuya.valueConverterBasic.divideBy(100),
divideBy1000: tuya.valueConverterBasic.divideBy(1000),
};

const definition = {
fingerprint: [
{
modelID: 'TS0601',
manufacturerName: '_TZE200_rks0sgb7',
},
],
model: 'TS0601_Bidirectional_Energy_Meter_with_80A_Current_Clamp',
vendor: 'TuYa',
description: 'Bidirectional Energy Meter with 80A Current Clamp',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
onEvent: tuya.onEventSetTime,
configure: tuya.configureMagicPacket,
whiteLabel: [ tuya.whitelabel('Tuya', 'PC311-Z-TY', 'Bidirectional Energy Meter with 80A Current Clamp', ['_TZE200_rks0sgb7']), ],
// whiteLabel: [{vendor: 'EARU', model: 'PC311-Z-TY'}],
exposes: [ //only report data
e.ac_frequency(),
exposes.numeric('total_power_A', ea.STATE).withUnit('W').withDescription('Total power A'),
exposes.numeric('total_power_B', ea.STATE).withUnit('W').withDescription('Total power B'),
exposes.numeric('total_power_AB', ea.STATE).withUnit('W').withDescription('Total power AB'),// - description corrected
exposes.numeric('voltage', ea.STATE).withUnit('V').withDescription('Voltage'),
exposes.numeric('current_A', ea.STATE).withUnit('A').withDescription('Current A'),
exposes.numeric('current_B', ea.STATE).withUnit('A').withDescription('Current B'),
exposes.numeric('current_AB', ea.STATE).withUnit('A').withDescription('Total Current'),
exposes.numeric('power_factor_A', ea.STATE).withUnit('%').withDescription('Instantaneous measured power factor A'),
exposes.numeric('power_factor_B', ea.STATE).withUnit('%').withDescription('Instantaneous measured power factor B'),
exposes.numeric('power_direction A', ea.STATE).withDescription('Power direction A 0/1 for forward/reverse'),
exposes.numeric('power_direction B', ea.STATE).withDescription('Power direction B 0/1 for forward/reverse'),
exposes.numeric('energy_forward_A', ea.STATE).withUnit('kWh').withDescription('Total energy A forward'),
exposes.numeric('energy_forward_B', ea.STATE).withUnit('kWh').withDescription('Total energy B forward'),
exposes.numeric('update_frequency', ea.STATE).withUnit('sec').withDescription('Update frequency'),
],

meta:{
tuyaDatapoints: [//only report data
[104, 'ac_frequency', tuya.valueConverter.raw],//known ok - not ok. always 0
[108, 'total_power_A', tuya.valueConverter.raw],//known ok - no divide needed, corrected to raw
[111, 'total_power_B', tuya.valueConverter.raw],//known ok - no divide needed, corrected to raw
[102, 'total_power_AB', tuya.valueConverter.divideBy10],//not ok, always 0
[106, 'voltage', tuya.valueConverter.divideBy10],//known ok - ok
[107, 'current_A', tuya.valueConverter.divideBy1000],//known ok - ok
[110, 'current_B', tuya.valueConverter.divideBy1000],//known ok- ok
[105, 'current_AB', tuya.valueConverter.divideBy1000],//known ok - ok with a ~second delay
[109, 'power_factor_A', tuya.valueConverter.raw],//known ok - ok
[112, 'power_factor_B', tuya.valueConverter.raw],//known ok - ok
[113, 'power_direction A', tuya.valueConverter.raw],//known ok - not ok. seems to show frequency as value is always 50
[114, 'power_direction B', tuya.valueConverter.raw],//known ok - not ok. always null
[101, 'energy_forward_A', tuya.valueConverter.divideBy100],//known ok - seems ok
[103, 'energy_forward_B', tuya.valueConverter.divideBy100],//known ok - seems ok
[113, 'update_frequency' , tuya.valueConverter.raw],//might be ok? - not ok. shows null
],
},
};

module.exports = definition;`

@KPfff
Copy link

KPfff commented Oct 29, 2023

[103, 'energy_forward_B', tuya.valueConverter.divideBy100], - tested by comparing to another device, OK

@KPfff
Copy link

KPfff commented Oct 31, 2023

Details:

  • I own double clamp Zigbee version from here https://es.aliexpress.com/item/1005005931365212.html
  • Reporting tested and working on my local mains!
  • Checked multiple DPs to find right ones, didn't find any more DPs with any values reported
  • Reverse energy tested by installing clamps backwards
  • Power readings goes negative with reverse load (see screenshot)
  • Summed "AB" values are coming with a delay and are not always 1+1 accurate
  • Reporting frequency seems to be fixed at once per second

NOTE: Readings accuracy is directly impacted by distance from other wires!!! One clamp was left without wire passing through, just wire next to it and it was showing 7W consumption.

Working converter below:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;
const {Buffer} = require('buffer');

const valueConverter = {
divideBy10: tuya.valueConverterBasic.divideBy(10),
divideBy100: tuya.valueConverterBasic.divideBy(100),
divideBy1000: tuya.valueConverterBasic.divideBy(1000),
};

const definition = {
fingerprint: [
{
modelID: 'TS0601',
manufacturerName: '_TZE200_rks0sgb7',
},
],
model: 'TS0601_Bidirectional_Energy_Meter_with_80A_Current_Clamp',
vendor: 'TuYa',
description: 'Bidirectional Energy Meter with 80A Current Clamp',
fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],
onEvent: tuya.onEventSetTime,
configure: tuya.configureMagicPacket,
whiteLabel: [ tuya.whitelabel('Tuya', 'PC311-Z-TY', 'Bidirectional Energy Meter with 80A Current Clamp', ['_TZE200_rks0sgb7']), ],
// whiteLabel: [{vendor: 'EARU', model: 'PC311-Z-TY'}],
exposes: [ //only report data
e.ac_frequency(),
exposes.numeric('total_power_A', ea.STATE).withUnit('W').withDescription('Total power A'),
exposes.numeric('total_power_B', ea.STATE).withUnit('W').withDescription('Total power B'),
exposes.numeric('total_power_AB', ea.STATE).withUnit('W').withDescription('Total power AB'),
exposes.numeric('voltage', ea.STATE).withUnit('V').withDescription('Voltage'),
exposes.numeric('current_A', ea.STATE).withUnit('A').withDescription('Current A'),
exposes.numeric('current_B', ea.STATE).withUnit('A').withDescription('Current B'),
exposes.numeric('current_AB', ea.STATE).withUnit('A').withDescription('Total Current'),
exposes.numeric('power_factor_A', ea.STATE).withUnit('%').withDescription('Instantaneous measured power factor A'),
exposes.numeric('power_factor_B', ea.STATE).withUnit('%').withDescription('Instantaneous measured power factor B'),
exposes.numeric('energy_reverse_A', ea.STATE).withUnit('kWh').withDescription('Total energy A reverse'),
exposes.numeric('energy_reverse_B', ea.STATE).withUnit('kWh').withDescription('Total energy B reverse'),
exposes.numeric('energy_reverse_AB', ea.STATE).withUnit('kWh').withDescription('Total energy AB reverse'),
exposes.numeric('energy_forward_A', ea.STATE).withUnit('kWh').withDescription('Total energy A forward'),
exposes.numeric('energy_forward_B', ea.STATE).withUnit('kWh').withDescription('Total energy B forward'),
exposes.numeric('energy_forward_AB', ea.STATE).withUnit('kWh').withDescription('Total energy AB forward'),
],

meta:{
tuyaDatapoints: [//only report data
[113, 'ac_frequency', tuya.valueConverter.raw],
[108, 'total_power_A', tuya.valueConverter.raw],
[111, 'total_power_B', tuya.valueConverter.raw],
[9, 'total_power_AB', tuya.valueConverter.raw],
[106, 'voltage', tuya.valueConverter.divideBy10],
[107, 'current_A', tuya.valueConverter.divideBy1000],
[110, 'current_B', tuya.valueConverter.divideBy1000],
[105, 'current_AB', tuya.valueConverter.divideBy1000],
[109, 'power_factor_A', tuya.valueConverter.raw],
[112, 'power_factor_B', tuya.valueConverter.raw],
[102, 'energy_reverse_A', tuya.valueConverter.divideBy100],
[104, 'energy_reverse_B', tuya.valueConverter.divideBy100],
[2, 'energy_reverse_AB', tuya.valueConverter.divideBy100],
[101, 'energy_forward_A', tuya.valueConverter.divideBy100],
[103, 'energy_forward_B', tuya.valueConverter.divideBy100],
[1, 'energy_forward_AB' , tuya.valueConverter.divideBy100],
],
},
};

module.exports = definition;

Exposed values

@lepalom
Copy link
Author

lepalom commented Nov 1, 2023

@KPfff Can you guide me to test this configuration? I have updated HA but I still have the old configuration.

@KPfff
Copy link

KPfff commented Nov 3, 2023

@lepalom, Are you familiar with setting up external converters?

  1. You need File editor - I use the "File editor" from Add-on Store
  2. Open file editor and navigate to /config/zigbee2mqtt folder
  3. Create file with .js extension. E.g., I named mine "earu-pc311-z-ty.js" (IMPORTANT - don't use capital letters in the file name!)
  4. Once file is created click on it in editor and copy paste converter from above, save the file.
  5. Go to Zigbee2MQTT add-on => Settings => External converters => Add the file with the same name, e.g. "earu-pc311-z-ty.js"
  6. Restart Zigbee2MQTT add-on

If the device is still reporting old values then try removing it and adding it again. (Worst case force remove and pair once again)

Note: Mind you that any historical data will not be brought over - it is like adding new device.

Hope it helps :)

@jmuf
Copy link

jmuf commented Nov 3, 2023

@KPfff: many thanks for this investigation. I guess that part of the issue is that not everybody is using zigbee2mqtt. To convert your findings to a zha-device-handlers "quirk" means writing a small python module similar to ts0601_din_power.py.
While the TUYA datapoint identifiers (107: current_A etc) hopefully are the same (and can be copied from your code), the structure is quite different.

@jmuf
Copy link

jmuf commented Nov 4, 2023

Work-in-progress "quirk":

  • gets loaded,
  • Zigbee "manage device" sees the custom cluster,
  • but does not load any data ( all values are null)
    • even for stuff like 'frequency' (0x71) which does not get translated
  • _update_attribute() is not even called (no logging)

ts0601_sp_clamp_power.py.txt

@robertstumberger
Copy link

Hi guys,
I have the same meter, PC311-Z-TY Single-Phase Power Clamp Zigbee model 'TS0601' and manufacturer name '_TZE200_rks0sgb7 but with two Clamps...
image
And of course I would ask for your help ;-)
And I use ZHA.
i need help how "quirk"

@lepalom
Copy link
Author

lepalom commented Nov 5, 2023

@KPfff thanks a lot. Well, my problem is that I'm not using zigbee2mqtt. Now I have understood the problem. I have seen that there are like two big families to manage a zigbee devices: ZHA integration and zigbee2mptt.

I have been using ZHA and I would like to test zigbee2mqtt, but I have to migrate all the devices. I will see.

@robertstumberger
Copy link

Ok,
I managed to give a "quirk" to work, but incorrectly, I assume
image
What am I doing wrong? Please help :-(

@robertstumberger
Copy link

Work-in-progress "quirk":

* gets loaded,

* Zigbee "manage device" sees the custom cluster,

* **but** does not load any data ( all values are null)
  
  * even for stuff like 'frequency' (0x71) which does not get translated

* `_update_attribute()` is not even called (no logging)

ts0601_sp_clamp_power.py.txt

@jmuf Are you working on "quirk" for ZHA?

@jmuf
Copy link

jmuf commented Nov 6, 2023

I had a look but am stuck, no idea whether the "attributes" from @KPfff have been correctly put in place in this code, or whether something basic is missing (this is my first attempt at a "quirk").

@robertstumberger
Copy link

Do we have someone who could check - validate this?
Is there any other way I can help?
As you can see from the picture above, the "quirk" was accepted, but unfortunately nothing happened, even after a reboot.

@jmuf
Copy link

jmuf commented Nov 11, 2023

Attached is a new version of the "quirk" (apparently need some offset to "translate" attributes numbers between zigbee2mqtt and ZHA), as usual need to rename to something.py (but cannot upload as such) -
ts0601_sp_clamp_power.py.txt

  • this more-or-less works for me (YMMV), although I haven't checked all values for plausibility.
  • it (ab?)uses the "phase B" attributes to report the values for the "Circuit 2" clamp (but this is a single-phase meter)
  • it does not report the energy per circuit (which arguably is the most interesting measurement..), just the total

If somebody has an idea/example on how to address the last point, I'd be happy for hints (instantiate a new "endpoint"?). This might also allow to not use "Phase B".

@robertstumberger
Copy link

Hi,
I tested a new script, Reconfiguring device,
image
But again it doesn't show me the entities...

image

@KPfff
Copy link

KPfff commented Nov 13, 2023

@robertstumberger, Apologies I see I have added to the confusion - I think I thought that this is one of the threads on zigbee2mqtt project when in fact this is for ZHA. :(

As far as mappings go I have been using this device with custom converter ever since with no issues.
I still miss configuration options (like setting intervals, accuracy etc.) but at least reported values are mapped correctly and are usable :)

I haven't used ZHA integration but apparently custom quirks are formatted completely differently - so unless you can translate my mappings to custom quirk then I can't be of any help here.

@didius62
Copy link

Hi all ,
I have just integrated this module (PC311) into Z2M/Jeedom with the external converter.
image

I only connect the circuit1 , i don't understand the value of energy reverse (displayed 5.72 KWH) , this value is wrong for me!

Didier

@jmuf
Copy link

jmuf commented Nov 17, 2023

Hi, I tested a new script, Reconfiguring device, image But again it doesn't show me the entities...

@robertstumberger : this is not so bad, the device has been recognized - please make sure you take the actual latest version of ts0601_sp_clamp_power.py , an earlier version indeed did not report any standard attribs back to HA.

@MattWestb
Copy link
Contributor

Reconfigure of "virtual cluster" is not working then the commands / attributes is not sent by the endpoint / cluster they is sent by the tuya MCU on the tuya cluster.

@robertstumberger
Copy link

Hej @jmuf ,
Thank you for your help, it worked... you're the best :-)
That's a huge improvement
image

Maybe we will manage to add both Clamps? :-)

@didius62
Copy link

Hi ,
I am not under HA !
Didier

@robertstumberger
Copy link

robertstumberger commented Nov 19, 2023

Hej @jmuf ,
I checked a little what I get and so on:

and if i go:
image
i get correct values:
image
image
image
image
and so on...
for all of them (16 values)
And the Power (on the right side) it's the same as power_A (on the left side)
image

this means, that the declarations for these entities are defined somewhere else and not in this Quirk (ts0601_sp_clamp_power.py)
I can't find these declarations in the entire script
how to get these entities?

@jmuf
Copy link

jmuf commented Nov 19, 2023

As you've seen, the Tuya_EnergyMeter_2Clamp class "knows" how to read the interesting attributes from the device (based on the work by @KPfff ). It then stuffs data into two helper classes:

  • PowerMeasurement_2Clamp - this is derived from ElectricalMeasurement, and ZHA seems to look at the attributes of that class for "Voltage", "AC frequency", "Current" etc reported in the right panel. And it indeed seem to ignore the measurements for "Phase B" (which is where the data from the second clamp goes.. for now). Ideally we'd find a way to create a second instance of ElectricalMeasurement and report the second clamp data there.
  • Metering_2Clamp - derived from Metering, and ZHA looks at that for "Summation delivered" (which should have the sum over both clamps)

@OwlBawl
Copy link

OwlBawl commented Dec 9, 2023

Hi, I tested a new script, Reconfiguring device, image But again it doesn't show me the entities...

@robertstumberger : this is not so bad, the device has been recognized - please make sure you take the actual latest version of ts0601_sp_clamp_power.py , an earlier version indeed did not report any standard attribs back to HA.

The quirk is partly functional...
Only 2nd clamp is showing. Half success
Would be great if someone could fix it to show full info for both clamps

@jmuf
Copy link

jmuf commented Dec 10, 2023

Here is a new version that has both clamps individually (as well as the total)
ts0601_sp_clamp_power.py.v2.txt

However, I haven't yet found a way to give them different entity names (so you'll get 3x "xyz Summation delivered" and so on - you can always rename them yourself, of course). Pointers to some similar device than can do this would be welcome...

@robertstumberger
Copy link

Hi @jmuf
I I used your new version and I'm impressed, fantastic work. I'll do some testing and report back, but it looks promising
As you mentioned, you just need to rename the entities and you're done
Screenshot_20231214_071836_Home Assistant

@robertstumberger
Copy link

After the first tests, I can say that it does not measure bidirectionally
Screenshot_20231214_125418_Home Assistant

@jmuf
Copy link

jmuf commented Dec 14, 2023

@robertstumberger - thanks for the test. Could you edit the "quirk" and change t.uint16_t to t.int16s in the following?

     62         TOTAL_POWER_AB_ATTR: ("power_both", t.uint16_t, True),
     63         TOTAL_POWER_A_ATTR: ("power_A", t.uint16_t, True),
     64         TOTAL_POWER_B_ATTR: ("power_B", t.uint16_t, True),

(per above "Power readings goes negative with reverse load"..).

There also should be some "Sum received" attributes somewhere that sum up outgoing kWh...

@jmuf
Copy link

jmuf commented Dec 17, 2023

Latest version (with the above "negative" power for outgoing load, also some cleanups): ts0601_sp_clamp_power.py.v3.txt

The issue of metric names (3x "Power") is still open..

jmuf added a commit to jmuf/zha-device-handlers that referenced this issue Dec 28, 2023
* use separate classes for AB/A/B readings, with several Bus()es as Hash
* allow to report negative power reading (under reverse load)
* use constants from ElectricalMeasurement, Metering and for divisors
* do not set voltage/current/energy multipliers, just divisors
jeverley added a commit to jeverley/zha-device-handlers that referenced this issue Feb 1, 2024
Aims to address device support requests:

2 bidirectional clamps:
zigpy#2549 (_TZE204_81yrt3lo)
zigpy#2650 (_TZE200_rks0sgb7)

1 bidirectional clamp:
zigpy#2420 (_TZE204_ac0fhfiq)

1 clamp:
zigpy#1973 (_TZE204_cjbofhxw)

@jmuf I've just spotted that in parallel you've also been working on zigpy#2870 for 
_TZE200_rks0sgb7, shall we pool ideas?
jeverley added a commit to jeverley/zha-device-handlers that referenced this issue Feb 1, 2024
Amendments from details in zigpy#2650 & zigpy#2870 (however that approach uses attributes directly rather than datapoints).
@lebeck69
Copy link

lebeck69 commented Jul 2, 2024

Originally I was in same situation than robertstumberger : using ZHA, PC311-Z-TY .. and only had 2 values (LQI and RSSI)
I learned about Quirks .. which I knew nothing .. already thx ;)
I directly used V3.

But numbers does seems good on my side.

I've put one on a working oven and the other one on a fridge.
Either values are null.. or equals and very smalls (not over 7W)

Questions :

  1. I have 120A clamps .. they seems huge compare to the oven electrical oven, is that normal ?
  2. All infos are in tripple .. what are there for ? clamp 1, clamp 2 .. and device itself ?
  3. Do you know a other clamp model that works out of the box ?

pc31-z-ty

Thx for you help and for publishing all this ;)

@didius62
Copy link

didius62 commented Oct 2, 2024

Hi all ,
i have a question about this device about the traffic , This device communicates constantly, I wonder if it doesn't load the Zigbee network too much!
do you know a parameter to read the values ​​every minute for example (like a linkee module)
image

many thanks
DD

@SabatoArdolino
Copy link

Hi to all
I've configure today ZHA and I try to setup the tuya clamp but I can understand where and how I cam install them with quirks. I've configure in my configuration.yaml

ZHA

zha:
custom_quirks_path: /config/custom_zha_quirks/
enable_quirks: true

in the path I've uploaded the .py file, repairing the devide and restart HA but I see only 2 entities.
Can explain How can i solve my issue ?
Thanks

@rabievdm
Copy link

@jmuf Was there any plans to merge https://github.com/zigpy/zha-device-handlers/files/13695705/ts0601_sp_clamp_power.py.v3.txt back into the main dev branch and also any luck in fixing the naming, specifically the A+B portion?

@jmuf
Copy link

jmuf commented Dec 24, 2024

@jmuf Was there any plans to merge https://github.com/zigpy/zha-device-handlers/files/13695705/ts0601_sp_clamp_power.py.v3.txt back into the main dev branch

There are currently two "competing" pull requests open

and also any luck in fixing the naming, specifically the A+B portion?

looks like that would need support in the base code (not happening?), or could possibly unclear how) be addressed if we go from "quirk" to "integrated in ZHA" (per #2840 )

@jeverley
Copy link
Contributor

jeverley commented Dec 24, 2024

We should be able to resolve the naming issue using the new quirks v2 format.

I'm planning to reimplement mine using quirks v2 in the new year, exposing config options in the UI that should allow flipping the negative values for people who have that issue.

It should make creating tests a fair bit easier too based on experience I've had with some other V2 quirks.

@TheJulianJES TheJulianJES added the device support request This requests support for a new device label Jan 26, 2025
@jmuf
Copy link

jmuf commented Jan 26, 2025

[..]

There are currently two "competing" pull requests open

FWIW, the update to homeassistant 2025.1 broke "my" quirk, will close the pull request. Hope that @jeverley 's version can move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
device support request This requests support for a new device Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging a pull request may close this issue.