zigpy / zha-device-handlers

ZHA device handlers bridge the functionality gap created when manufacturers deviate from the ZCL specification, handling deviations and exceptions by parsing custom messages to and from Zigbee devices.
Apache License 2.0
773 stars 703 forks source link

[Device Support Request] _TZE204_81yrt3lo TS0601 Zigbee power meter with clamp #2549

Open Srjosep opened 1 year ago

Srjosep commented 1 year ago

Problem description

The device is discovered, but with no sensors. I have all connected fine, I can see total and instantaneous power in Tuya app. Where to start?

Solution description

Any

Screenshots/Video

Screenshots/Video [Paste/upload your media here]

Device signature

Device signature ```json { "node_descriptor": "NodeDescriptor(logical_type=, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=, mac_capability_flags=, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=, *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" ], "output_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601", "class": "zigpy.device.Device" } ```

Diagnostic information

Diagnostic information ```json { "home_assistant": { "installation_type": "Home Assistant Supervised", "version": "2023.5.4", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.10.11", "docker": true, "arch": "armv7l", "timezone": "Europe/Madrid", "os_name": "Linux", "os_version": "5.10.103-v7l+", "supervisor": "2023.08.1", "host_os": "Raspbian GNU/Linux 10 (buster)", "docker_version": "20.10.14", "chassis": "", "run_as_root": true }, "custom_components": { "sonoff": { "version": "3.5.2", "requirements": [ "pycryptodome>=3.6.6" ] }, "smartir": { "version": "1.17.7", "requirements": [ "aiofiles>=0.6.0" ] }, "hacs": { "version": "1.32.1", "requirements": [ "aiogithubapi>=22.10.1" ] }, "localtuya": { "version": "5.2.1", "requirements": [] }, "midea_ac_lan": { "version": "v0.3.18", "requirements": [] } }, "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" ], "requirements": [ "bellows==0.35.5", "pyserial==3.5", "pyserial-asyncio==0.6", "zha-quirks==0.0.99", "zigpy-deconz==0.21.0", "zigpy==0.55.0", "zigpy-xbee==0.18.0", "zigpy-zigate==0.11.0", "zigpy-znp==0.11.1" ], "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": "_slzb-06._tcp.local.", "name": "slzb-06*" } ], "is_built_in": true }, "data": { "ieee": "**REDACTED**", "nwk": 11971, "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601", "name": "_TZE204_81yrt3lo TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "manufacturer_code": 4417, "power_source": "Mains", "lqi": 128, "rssi": -68, "last_seen": "2023-08-28T21:08:34", "available": true, "device_type": "Router", "signature": { "node_descriptor": "NodeDescriptor(logical_type=, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=, mac_capability_flags=, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=, *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" ], "output_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601" }, "active_coordinator": false, "entities": [], "neighbors": [], "routes": [], "endpoint_names": [ { "name": "SMART_PLUG" }, { "name": "unknown 97 device_type of 0xa1e0 profile id" } ], "user_given_name": null, "device_reg_id": "c7f139fc3dc0c3829df8cef20d87199b", "area_id": "594729d4701c4d73b9edf7c14a5818d8", "cluster_details": { "1": { "device_type": { "name": "SMART_PLUG", "id": 81 }, "profile_id": 260, "in_clusters": { "0x0004": { "endpoint_attribute": "groups", "attributes": {}, "unsupported_attributes": {} }, "0x0005": { "endpoint_attribute": "scenes", "attributes": {}, "unsupported_attributes": {} }, "0xef00": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} }, "0x0000": { "endpoint_attribute": "basic", "attributes": { "0x0001": { "attribute_name": "app_version", "value": 74 }, "0x0004": { "attribute_name": "manufacturer", "value": "_TZE204_81yrt3lo" }, "0x0005": { "attribute_name": "model", "value": "TS0601" } }, "unsupported_attributes": {} } }, "out_clusters": { "0x0019": { "endpoint_attribute": "ota", "attributes": {}, "unsupported_attributes": {} }, "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} } } }, "242": { "device_type": { "name": "unknown", "id": 97 }, "profile_id": 41440, "in_clusters": {}, "out_clusters": { "0x0021": { "endpoint_attribute": "green_power", "attributes": {}, "unsupported_attributes": {} } } } } } } ```

Logs

Logs ```python [Paste the logs here] ```

Custom quirk

Custom quirk ```python [Paste your custom quirk here] ```

Additional information

No response

Srjosep commented 1 year ago

I saw there is quirk data for z2m, so I created a /config/zha_quirks/ folder, create the file Tuya_TZE204_81yrt3lo.js with this data, and added custom_quirks_path: /config/zha_quirks/ to configuration.yaml. But after reboot and repair, still no sensors. Must I delete pycache?Have no idea how to do it...

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: '_TZE204_81yrt3lo', }, ], 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', 'PJ-1203A', 'Bidirectional Energy Meter with 80A Current Clamp', ['_TZE204_81yrt3lo']), ], // whiteLabel: [{vendor: 'MatSeePlus', model: 'PJ-1203A'}], 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 A'), 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('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('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('update_frequency', ea.STATE).withUnit('sec').withDescription('Update frequency'), ],

meta: { tuyaDatapoints: [//only report data [111, 'ac_frequency', tuya.valueConverter.divideBy100], [101, 'total_power_A', tuya.valueConverter.divideBy10], [105, 'total_power_B', tuya.valueConverter.divideBy10], [115, 'total_power_AB', tuya.valueConverter.divideBy10], [112, 'voltage', tuya.valueConverter.divideBy10], [113, 'current_A', tuya.valueConverter.divideBy1000], [114, 'current_B', tuya.valueConverter.divideBy1000], [110, 'power_factor_A', tuya.valueConverter.divideBy100], [121, 'power_factor_B', tuya.valueConverter.divideBy100], [102, 'power_direction A', tuya.valueConverter.raw], [104, 'power_direction B', tuya.valueConverter.raw], [106, 'energy_forward_A', tuya.valueConverter.divideBy100], [108, 'energy_forward_B', tuya.valueConverter.divideBy100], [107, 'energy_reverse_A', tuya.valueConverter.divideBy100], [109, 'energy_reverse_B', tuya.valueConverter.divideBy100], [129, 'update_frequency' , tuya.valueConverter.raw], ], }, };

module.exports = definition;

Srjosep commented 1 year ago

I think the quirk it's not applied, but I can't figure why... I followed all the steps... this is the log:

"manufacturer": "_TZE204_81yrt3lo", "model": "TS0601", "name": "_TZE204_81yrt3lo TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device",

MattWestb commented 1 year ago

In the opening post you have signature and diagnostic from the coordinator and not the device you have described. "device_type": "Coordinator". Pleas updating them with information for the right device (device card).

Srjosep commented 1 year ago

Sorry, wrong device..... Fixed now. ( I Hope) :-)

Srjosep commented 1 year ago

Tried to add custom quirk to ZHA following https://github.com/home-assistant/home-assistant.io/pull/23884/files/e03462d75c7ad37c611ab3cf4d47210f7114bc94#diff-f6bd4d42fd2565238968333a466474a25384fb4eecddc0235902e5ff5e798c8d but still no sensors. This means quirk isn't been applied, right? (Diagnose dump) "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601", "name": "_TZE204_81yrt3lo TS0601", "quirk_applied": false, "quirk_class": "zigpy.device.Device",

I am sure I followed all steps, creating the quirks folder and adding to yaml... where could I start to look for the problem?

MattWestb commented 1 year ago

"quirk_class": "zigpy.device.Device" = the device signature is ont matching your device, so need being fixed by adding it i the right device class in the quirk of if no working one making one new for your device.

Srjosep commented 1 year ago

I created a file called TS0601_Router.py inside "customs_zha_quirks" folder. And zha: enable_quirks: true custom_quirks_path: /config/custom_zha_quirks/
to configuration.yaml The data inside the file is 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), }; const definition = { fingerprint: [ { modelID: 'TS0601', manufacturerName: '_TZE204_81yrt3lo', }, ], model: 'TS0601_Bidirectional_Energy_Meter_with_80A_Current_Clamp', vendor: 'TuYa', description: 'Bidirectional Energy Meter with 80A Current Clamp', fromZigbee: [tuya.fz.datapoints], //, fz.ignore_tuya_set_time not working for No converter available for friendly_name with cluster manuSpecificTuya and type commandMcuSyncTime and data {payloadSize:XXX} toZigbee: [tuya.tz.datapoints], onEvent: tuya.onEventSetTime, // Add this if you are getting no converter for 'commandMcuSyncTime' configure: tuya.configureMagicPacket, whiteLabel: [ tuya.whitelabel('Tuya', 'PJ-1203A', 'Bidirectional Energy Meter with 80A Current Clamp', ['_TZE204_81yrt3lo']), ], // whiteLabel: [{vendor: 'MatSeePlus', model: 'PJ-1203A'}], 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 A'), 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('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('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('update_frequency', ea.STATE).withUnit('sec').withDescription('Update frequency'), ], meta: { tuyaDatapoints: [//only report data [111, 'ac_frequency', tuya.valueConverter.divideBy100], [101, 'total_power_A', tuya.valueConverter.divideBy10], [105, 'total_power_B', tuya.valueConverter.divideBy10], [115, 'total_power_AB', tuya.valueConverter.divideBy10], [112, 'voltage', tuya.valueConverter.divideBy10], [113, 'current_A', tuya.valueConverter.divideBy100], [114, 'current_B', tuya.valueConverter.divideBy100], [110, 'power_factor_A', tuya.valueConverter.divideBy100], [121, 'power_factor_B', tuya.valueConverter.divideBy100], [102, 'power_direction A', tuya.valueConverter.raw], [104, 'power_direction B', tuya.valueConverter.raw], [106, 'energy_forward_A', tuya.valueConverter.divideBy100], [108, 'energy_forward_B', tuya.valueConverter.divideBy100], [107, 'energy_reverse_A', tuya.valueConverter.divideBy100], [109, 'energy_reverse_B', tuya.valueConverter.divideBy100], [129, 'update_frequency' , tuya.valueConverter.raw], ], }, }; module.exports = definition;

This is wrong? I have some devices apart of this one I'd like to fix to contribute. I'm on the learning process :-) THANKS for your help

MattWestb commented 1 year ago

You have posting Z2M code in the ZHA quirk and its not working. You must doing one quirk from scratch if not can using one as temples and changing it so its working for your device.

MattWestb commented 1 year ago

I think one good start i using this quirk and caning it so its working for your device if that is using the same DPs (tuya MCU commands). https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0601_din_power.py

lhanneus commented 1 year ago

I bought the same device and had the same problem.

I found this information : https://github.com/Koenkk/zigbee2mqtt/issues/18419#issuecomment-1657066719

Hope it can help to fix the problem.

Srjosep commented 1 year ago

Quirk applied finally, and getting some data. Only Total power delivered and Power factor. Log: "data": { "ieee": "**REDACTED**", "nwk": 56699, "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601", "name": "_TZE204_81yrt3lo TS0601", "quirk_applied": true, "quirk_class": "TS0601_Router.TuyaPowerMeter_GPP", "manufacturer_code": 4417, "power_source": "Mains", "lqi": 76, "rssi": -81, "last_seen": "2023-09-03T12:31:15", "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=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, 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", "0x0702", "0x0b04", "0xef00" ], "output_clusters": [ "0x000a", "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "_TZE204_81yrt3lo", "model": "TS0601" }, "active_coordinator": false, "entities": [ { "entity_id": "sensor.tze204_81yrt3lo_ts0601_power_factor", "name": "_TZE204_81yrt3lo TS0601" }, { "entity_id": "sensor.tze204_81yrt3lo_ts0601_summation_delivered", "name": "_TZE204_81yrt3lo TS0601" } ], "neighbors": [ { "device_type": "Coordinator", "rx_on_when_idle": "On", "relationship": "Parent", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x0000", "permit_joining": "Unknown", "depth": "0", "lqi": "33" }, { "device_type": "Router", "rx_on_when_idle": "On", "relationship": "Sibling", "extended_pan_id": "**REDACTED**", "ieee": "**REDACTED**", "nwk": "0x527C", "permit_joining": "Unknown", "depth": "0", "lqi": "112" } ], "routes": [], "endpoint_names": [ { "name": "SMART_PLUG" }, { "name": "PROXY_BASIC" } ], "user_given_name": null, "device_reg_id": "c7f139fc3dc0c3829df8cef20d87199b", "area_id": null, "cluster_details": { "1": { "device_type": { "name": "SMART_PLUG", "id": 81 }, "profile_id": 260, "in_clusters": { "0x0000": { "endpoint_attribute": "basic", "attributes": { "0x0001": { "attribute_name": "app_version", "value": 74 }, "0x0004": { "attribute_name": "manufacturer", "value": "_TZE204_81yrt3lo" }, "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": "tuya_manufacturer", "attributes": { "0x0201": { "attribute_name": "energy", "value": 6580 } }, "unsupported_attributes": {} }, "0x0b04": { "endpoint_attribute": "electrical_measurement", "attributes": { "0x0603": { "attribute_name": "ac_current_divisor", "value": 1000 }, "0x0602": { "attribute_name": "ac_current_multiplier", "value": 1 }, "0x0601": { "attribute_name": "ac_voltage_divisor", "value": 10 }, "0x0600": { "attribute_name": "ac_voltage_multiplier", "value": 1 } }, "unsupported_attributes": { "0x0400": { "attribute_name": "ac_frequency_multiplier" }, "0x0401": { "attribute_name": "ac_frequency_divisor" }, "0x0000": { "attribute_name": "measurement_type" }, "0x0403": { "attribute_name": "power_divisor" }, "0x0604": { "attribute_name": "ac_power_multiplier" }, "0x0605": { "attribute_name": "ac_power_divisor" }, "0x0402": { "attribute_name": "power_multiplier" }, "0x0508": { "attribute_name": "rms_current" }, "0x0505": { "attribute_name": "rms_voltage" }, "0x050a": { "attribute_name": "rms_current_max" }, "0x050b": { "attribute_name": "active_power" }, "0x050d": { "attribute_name": "active_power_max" }, "0x0507": { "attribute_name": "rms_voltage_max" }, "0x050f": { "attribute_name": "apparent_power" }, "0x0300": { "attribute_name": "ac_frequency" }, "0x0302": { "attribute_name": "ac_frequency_max" } } }, "0x0702": { "endpoint_attribute": "smartenergy_metering", "attributes": { "0x0000": { "attribute_name": "current_summ_delivered", "value": 6580 }, "0x0302": { "attribute_name": "divisor", "value": 100 }, "0x0300": { "attribute_name": "unit_of_measure", "value": 0 } }, "unsupported_attributes": { "0x0400": { "attribute_name": "instantaneous_demand" }, "0x0301": { "attribute_name": "multiplier" }, "0x0100": { "attribute_name": "current_tier1_summ_delivered" }, "0x0303": { "attribute_name": "summation_formatting" }, "0x0304": { "attribute_name": "demand_formatting" }, "0x0102": { "attribute_name": "current_tier2_summ_delivered" }, "0x0306": { "attribute_name": "metering_device_type" }, "0x0104": { "attribute_name": "current_tier3_summ_delivered" }, "0x0106": { "attribute_name": "current_tier4_summ_delivered" }, "0x0108": { "attribute_name": "current_tier5_summ_delivered" }, "0x010a": { "attribute_name": "current_tier6_summ_delivered" }, "0x0200": { "attribute_name": "status" } } } }, "out_clusters": { "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} }, "0x0019": { "endpoint_attribute": "ota", "attributes": {}, "unsupported_attributes": {} } } }, "242": { "device_type": { "name": "PROXY_BASIC", "id": 97 }, "profile_id": 41440, "in_clusters": {}, "out_clusters": { "0x0021": { "endpoint_attribute": "green_power", "attributes": {}, "unsupported_attributes": {} } } } } } }

Srjosep commented 1 year ago

This sentences make the difference. With this, quirk isn't applied, and device have no sensor. Doesn't matter if the signature is right, quirk isn't applied. PROFILE_ID: zgp.PROFILE_ID, DEVICE_TYPE: zgp.DeviceType.PROXY_BASIC, With this, quirk is applied, but only sensors for total power and power factor are show. PROFILE_ID: 41440, DEVICE_TYPE: 97,

I have no idea what means the numbers or where find how it work,,,not much info about quirks development out there, anyway, I'll keep trying....

BiduleMac commented 1 year ago

Hello, I've just read your post, even following your parameters I don't get the power entities. Can you post your file ts0601_din_power.py for _TZE204_81yrt3lo please?

Do you confirm that once the file is placed in the custom_zha_quirks folder, I have to clear the ts0601_din_power.cpython-311.pyc cache and reboot HA? and rebuild or do I have to delete the device and reinstall it?

Srjosep commented 1 year ago

Yes, every time I do any change I delete the device, delete pycache file inside zha_quirks folder, and reboot HA. This is what I get after pair again the device (only Power factor sensor): image

And this after reboot again HA (one more sensor is discovered, "Summation delivered"). More HA reboots don't add more sensors. image And this is the file ts0601_din_power.py for _TZE204_81yrt3lo I use. `"""Tuya Din Power Meter.""" from zigpy.profiles import zha import zigpy.types as t from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time, GreenPowerProxy from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks import Bus, LocalDataCluster from zhaquirks.const import ( DEVICE_TYPE, ENDPOINTS, INPUT_CLUSTERS, MODELS_INFO, OUTPUT_CLUSTERS, PROFILE_ID, ) from zhaquirks.tuya import ( NoManufacturerCluster, TuyaManufClusterAttributes, TuyaSwitch, )

import logging _LOGGER = logging.getLogger(name)

TUYA_TOTAL_ENERGY_ATTR = 0x0201 #total energy /100 0x0211 TUYA_CURRENT_ATTR = 0x0011 #0x0212 TUYA_POWER_ATTR = 0x0006 #0x0213 TUYA_VOLTAGE_ATTR = 0x0004 #0x0214

class TuyaManufClusterDinPower(TuyaManufClusterAttributes): """Manufacturer Specific Cluster of the Tuya Power Meter device."""

attributes = {
    TUYA_TOTAL_ENERGY_ATTR: ("energy", t.uint16_t, True),
    TUYA_CURRENT_ATTR: ("current", t.int16s, True),      #t.int16s
    TUYA_POWER_ATTR: ("power", t.uint64_t, True),         #t.uint16_t
    TUYA_VOLTAGE_ATTR: ("voltage", t.uint16_t, True),
}

def _update_attribute(self, attrid, value):
    #super()._update_attribute(attrid, value)
    if attrid == TUYA_TOTAL_ENERGY_ATTR:
        self.endpoint.smartenergy_metering.energy_reported(value)
        super()._update_attribute(attrid, value)
    elif attrid == TUYA_CURRENT_ATTR:
        _LOGGER.warning("TUYA_CURRENT_ATTR (0x%04x) value: %d (0x%x)" % (attrid, value, value))
    elif attrid == TUYA_POWER_ATTR:
        self.endpoint.electrical_measurement.voltage_reported((value >> 48) & 0xffff)
        self.endpoint.electrical_measurement.current_reported((value >> 24) & 0xffffff)
        self.endpoint.electrical_measurement.power_reported(value & 0xffffff)
        super()._update_attribute(TUYA_VOLTAGE_ATTR, (value >> 48) & 0xffff)
        super()._update_attribute(TUYA_CURRENT_ATTR, (value >> 24) & 0xffffff)
        super()._update_attribute(TUYA_POWER_ATTR, value & 0xffffff)
    elif attrid == TUYA_VOLTAGE_ATTR:
        _LOGGER.warning("TUYA_VOLTAGE_ATTR (0x%04x) value: %d (0x%x)" % (attrid, value, value))
    else:
        super()._update_attribute(attrid, value)
        _LOGGER.warning("attrid: 0x%04x value: %d (0x%x)" % (attrid, value, value))

class TuyaPowerMeasurement(LocalDataCluster, ElectricalMeasurement): """Custom class for power, voltage and current measurement."""

cluster_id = ElectricalMeasurement.cluster_id

POWER_ID = 0x050b             #0x050B
VOLTAGE_ID = 0x0505
CURRENT_ID = 0x0508

AC_VOLTAGE_MULTIPLIER = 0x0600
AC_VOLTAGE_DIVISOR = 0x0601
AC_CURRENT_MULTIPLIER = 0x0602
AC_CURRENT_DIVISOR = 0x0603

_CONSTANT_ATTRIBUTES = {AC_CURRENT_MULTIPLIER: 1, AC_CURRENT_DIVISOR: 1000, AC_VOLTAGE_MULTIPLIER: 1, AC_VOLTAGE_DIVISOR: 10}

def voltage_reported(self, value):
    """Voltage reported."""
    self._update_attribute(self.VOLTAGE_ID, value)

def power_reported(self, value):
    """Power reported."""
    self._update_attribute(self.POWER_ID, value)

def current_reported(self, value):
    """Ampers reported."""
    self._update_attribute(self.CURRENT_ID, value)

class TuyaElectricalMeasurement(LocalDataCluster, Metering): """Custom class for total energy measurement."""

cluster_id = Metering.cluster_id
CURRENT_SUMM_DELIVERED_ID = 0x0000
UNIT_OF_MEASURE_ID = 0x0300
MULTIPLIER_ID = 0x0301
DIVISOR_ID = 0x0302
POWER_WATT_ENUM = 0x0000

"""Setting unit of measurement."""
_CONSTANT_ATTRIBUTES = {UNIT_OF_MEASURE_ID: POWER_WATT_ENUM, DIVISOR_ID: 100}

def energy_reported(self, value):
    """Summation Energy reported."""
    self._update_attribute(self.CURRENT_SUMM_DELIVERED_ID, value)

class TuyaPowerMeter(TuyaSwitch): """Tuya power meter device."""

signature = {
    # "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4098
    #                       maximum_buffer_size=82 maximum_incoming_transfer_size=82 server_mask=11264
    #                       maximum_outgoing_transfer_size=82 descriptor_capability_field=0>",
    # device_version=1
    # input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
    # output_clusters=[0x000a, 0x0019]
    MODELS_INFO: [
        ("_TZE200_byzdayie", "TS0601"),
        ("_TZE200_ewxhg6o9", "TS0601"),
        ("_TZE204_81yrt3lo", "TS0601"),
    ],
    ENDPOINTS: {
        # <SimpleDescriptor endpoint=1 profile=260 device_type=51
        # device_version=1
        # input_clusters=[0, 4, 5, 61184]
        # output_clusters=[10, 25]>
        1: {
            PROFILE_ID: zha.PROFILE_ID,
            DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
            INPUT_CLUSTERS: [
                Basic.cluster_id,
                Groups.cluster_id,
                Scenes.cluster_id,
                TuyaManufClusterAttributes.cluster_id,
            ],
            OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
        }
    },
}

replacement = {
    ENDPOINTS: {
        1: {
            PROFILE_ID: zha.PROFILE_ID,
            DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
            INPUT_CLUSTERS: [
                Basic.cluster_id,
                Groups.cluster_id,
                Scenes.cluster_id,
                TuyaManufClusterDinPower,
                TuyaPowerMeasurement,
                TuyaElectricalMeasurement,
            ],
            OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
        }
    }
}

class TuyaPowerMeter_GPP(TuyaSwitch): """Tuya power meter device."""

signature = {
    # "node_descriptor": "<NodeDescriptor byte1=1 byte2=64 mac_capability_flags=142 manufacturer_code=4417
    #                       maximum_buffer_size=66 maximum_incoming_transfer_size=66 server_mask=10752
    #                       maximum_outgoing_transfer_size=66 descriptor_capability_field=0>",
    # device_version=1
    # input_clusters=[0x0000, 0x0004, 0x0005, 0xef00]
    # output_clusters=[0x000a, 0x0019]
    MODELS_INFO: [
        ("_TZE200_lsanae15", "TS0601"),
        ("_TZE204_81yrt3lo", "TS0601"),
    ],
    ENDPOINTS: {
        # <SimpleDescriptor endpoint=1 profile=260 device_type=51
        # device_version=1
        # input_clusters=[0, 4, 5, 61184]
        # output_clusters=[10, 25]>
        1: {
            PROFILE_ID: zha.PROFILE_ID,
            DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
            INPUT_CLUSTERS: [
                Basic.cluster_id,
                Groups.cluster_id,
                Scenes.cluster_id,
                TuyaManufClusterAttributes.cluster_id,
            ],
            OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
        },
        242: {
            # <SimpleDescriptor endpoint=242 profile=41440 device_type=61
            # input_clusters=[]
            # output_clusters=[21]
            PROFILE_ID: 41440,
            DEVICE_TYPE: 97,
            INPUT_CLUSTERS: [],
            OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
        },
    },
}

replacement = {
    ENDPOINTS: {
        1: {
            PROFILE_ID: zha.PROFILE_ID,
            DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
            INPUT_CLUSTERS: [
                Basic.cluster_id,
                Groups.cluster_id,
                Scenes.cluster_id,
                TuyaManufClusterDinPower,
                TuyaPowerMeasurement,
                TuyaElectricalMeasurement,
            ],
            OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
        },
        242: {
            # <SimpleDescriptor endpoint=242 profile=41440 device_type=61
            # input_clusters=[]
            # output_clusters=[21]
            PROFILE_ID: 41440,
            DEVICE_TYPE: 97,
            INPUT_CLUSTERS: [],
            OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
        },
    }`
BiduleMac commented 1 year ago

Do you think you could send me the whole file at once? I've gone step by step, but it doesn't work. ;-)

Are file indentations mandatory (as in YAML)?

After trying several times, still nothing.

Once the file has been created according to your model, I don't get the "Power Factor" entity on the first startup, and nothing either on the second startup.

Srjosep commented 1 year ago

The folder must be pointed in configuration.raml, something like

zha: enable_quirks: true custom_quirks_path: /config/zha_quirks/

Pointing to your quirks folder. Can you see the quirk applied in the device info? image I read the clamp must be connected, in right position, and there must be power in the wire to get the sensors... I didn't tried with the clamp off, so, I am not sure if this is needed. I tried with Tuya app before, and only after getting all data working fine, deleted the device from tuya app and starting with ZHA.
Here is the file. I called it ts0601_powermeter to avoid duplicated names. ts0601_powermeter.zip

BiduleMac commented 1 year ago

Yes !! thanks for the file, it worked immediately. the first "Power factor" sensor actually appeared on the first boot, and the second "Summation delivered" after the second reboot.

for your information, the second "Summation delivered" sensor appeared with the clamp closed (currently at 0.0kWh), my blank assembly.

I'm going back to my temporary set-up to measure a significant current.
Many thanks for this great step forward .

But I'm going to ask you again, and maybe you won't be able to answer me, the model I have has 2 sensors, and I can only see one :-(

Do you have any idea how to activate the second sensor to help me in my search? I didn't go through TUYA, I don't have an independent gateway, and I didn't manage to associate it in Zigbee on the application.

thanks again, I'm desperate after 150 restarts.

Srjosep commented 1 year ago

Mine have two sensors plug too, for use with solar or wind generators. I use only one because I have no generators i+right now. This device have much more sensors, like voltage, actual consumption, etc... I am trying to get all working, but there is info (or I can't find it) about quirks creation, so I am blindfolding, just trying things....you can see all the sensors available and the entrypoints here https://github.com/Koenkk/zigbee2mqtt/issues/18419#issuecomment-1657066719 but I don't know how translate from z2mqtt to ZHA. Any progress I will post here, if any... any suggestion, progress, you make, please let me know...

BiduleMac commented 1 year ago

OK I'm looking yes, of course I'll publish here if I make any progress

maccmaic commented 1 year ago

ts0601_din_power_MatSee.zip Hi, i made this file using TuyaPowerMeter_GPP. Not work 100% but is near.

image
BiduleMac commented 1 year ago

👍 Great It works for me, but I only have one sensor on both, a track to activate the second?

Srjosep commented 1 year ago

You make my day, it works like charm... just have a doubt about the active power... a current of 2.4Ah at 235volts = 566 W... but indicate 4122 w... It seems there is something wrong... image

Srjosep commented 1 year ago

This is the screen capture of Tuya app. It seems to need some calibration too, (is possible to modify calibration factor in the app). Last number in active power must be decimal... and seems in this quirk "summation delivered" refers to reverse energy, not forward energy as TuyaPowerMeter_GPP do..... but you did a GREAT job. Thanks. BiduleMac could confirm this, I have only one clamp for forward energy because I have no solar generator yet. image

fernac03 commented 1 year ago

Great , is work for me. I have two sensors, how do I show the second one? Is the reverse for the network already working?

BiduleMac commented 1 year ago

Concerning the two sensors, I noticed with the latest version of @maccmaic that both sensors are present (in Manage Zigbee device) and the values updated, but I don't understand how to make them appear as entities. In fact, I'm trying to understand the structure of the file, but the display part escapes me ;-(.

fernac03 commented 1 year ago

from what I saw in the code only the attributes energy_deliver_reported and energy_deliver_reported are being reported channel B is commented

maccmaic commented 1 year ago

I have tried to change delivered/recived but the integration not working. Sorry, i dont know the architecture and is the first time programming in python. image

If someone know why?

For channel B, I tried to report the CURRENT_TIER1_DELIVERED_ID attribute of the TuyaElectricalMeasurement class but it didn't work either.

The bad thing is that when I modify things that should not affect the rest, it stops showing all the entities.

BiduleMac commented 1 year ago

in my searches on Github, I don't see any TS601 displaying 2 sensors ....

what's surprising is that the data from the 2 sensors do indeed show up in ZHA, you can see them vary in the "manage Zigbee device" menu, then "MatSeeManufClusterDinPower" and current & currentB with the values 0x000 and 0X001, and this is also true for power and current.

Capture d’écran 2023-09-07 à 17 51 01 Capture d’écran 2023-09-07 à 17 51 18

I can't figure out how to define the transition to entities.

Srjosep commented 1 year ago

Still my summation delivered is 0. Tried a lot of things but no result... do you get the right value for it? image

freesty82 commented 1 year ago

Hi everyone, I managed, with a bit of fiddling, to get the second clamp to work. I installed via HACS "zha_toolkit" and created an automation that every second calls the zha_toolkit.execute service which reads the second power and creates/updates a sensor.

Automation:

alias: aggiorno sensore
description: ""
trigger:
  - platform: time_pattern
    seconds: /1
condition: []
action:
  - service: zha_toolkit.execute
    data:
      command: attr_read
      ieee: xx:xx:xx:xx:xx:xx:xx:xx
     cluster: 0xef00
     attribute: 0x0269
      state_id: sensor.smartmeter_active_power2
      allow_create: true
mode: single

However, this sensor does not have "power" device_class and it is not possible to make a customization as the sensor is created after loading the HA customizations. So I created a template that creates a new sensor taking as an attribute the value of "sensor.smartmeter_active_power2" created earlier.

Template

template:
  - sensor:
      - name: "Active power Isola"
         unit_of_measurement: "W"
         device_class: power
         state_class: measurement
         state: "{{ states('sensor.smartmeter_active_power2')|float(0) / 10}}"
         availability: "{{ states('sensor.smartmeter_active_power2')|is_number }}"
         icon: mdi:transmission-tower-export

In this way I have an entity for the instantaneous consumption. For the total consumption I created a "Utility Meter" helper a template and a customization for this sensor to be able to modify the unit of measurement.

Customization:

sensor.consumo_isola3:
    friendly_name: Consumo energetico Isola
    last_reset: '1970-01-01T00:00:00+00:00'
    device_class: energy
    state_class: measurement
    unit_of_measurement: Wh

Template:

template:
  - sensor:
      - name: "Isola totale in kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.consumo_isola3')|float(0) / 1000 }}"
        availability: "{{ states('sensor.consumo_isola3')|is_number }}"
        icon: mdi:transmission-tower-export

This is the result:

screen_ha1

screenha2

Srjosep commented 1 year ago

I followed the wiring diagram included withe device, that is, "channel B" connections for load clamp. I use only one clamp because I have no solar generator, I only want to know the energy delivered. The position of the clamp is checked by the Tuya official app, to get "Forward" indication for load circuit, or "energy delivered". All works fine this way with tuya official app, readings are right. image

But with the clamp at this way, in home assistant, with this quirk, summation delivered value is always 0. So, I had to reverse the position of the clamp to get the summation delivered value working. BUT on the tuya official app this way show the clamp as reverse, and the active power is too high.. I think the "energy delivered" and "energy received" reverse in the quirk... is possible? It seems weird...are is this working fine for u? How are you connections? Anyway, I will check the readings with a multimeter, maybe the active power is right, and I only had to reverse the clamp... image

freesty82 commented 1 year ago

Hi Srjosep, i had the same problem, i just made some change in the quirk. This is the file i'm using ts0601_din_power_MatSee_mod.zip

Anyway, I also don't have the solar generator but I use the second clamp to monitor another load

Srjosep commented 1 year ago

Hi Srjosep, i had the same problem, i just made some change in the quirk. This is the file i'm using ts0601_din_power_MatSee_mod.zip

Anyway, I also don't have the solar generator but I use the second clamp to monitor another load

Working fine now, THANKS.

image

pepepere commented 1 year ago

Hi Srjosep, i had the same problem, i just made some change in the quirk. This is the file i'm using ts0601_din_power_MatSee_mod.zip

Anyway, I also don't have the solar generator but I use the second clamp to monitor another load

Hi, freesty82 Is your mod file running with the second clamp? You have generated a second endpoint, does that work for you? Thx!

freesty82 commented 1 year ago

Hi Srjosep, i had the same problem, i just made some change in the quirk. This is the file i'm using ts0601_din_power_MatSee_mod.zip Anyway, I also don't have the solar generator but I use the second clamp to monitor another load

Hi, freesty82 Is your mod file running with the second clamp? You have generated a second endpoint, does that work for you? Thx!

Hi, if you look at a couple of posts above I put a guide on how I solved it

here: https://github.com/zigpy/zha-device-handlers/issues/2549#issuecomment-1741142070

pepepere commented 1 year ago

Hi, if you look at a couple of posts above I put a guide on how I solved it

here: #2549 (comment)

Thanks, I didn't see that post was yours too. So there is no way to expose the entities, right?

freesty82 commented 1 year ago

Hi, if you look at a couple of posts above I put a guide on how I solved it here: #2549 (comment)

Thanks, I didn't see that post was yours too. So there is no way to expose the entities, right?

Not from tuya device itself , but with this solution you get a full usable energy entity (sensor.active_power_isola in my setup)

mickaelr3003 commented 1 year ago

hi everyone, freesty82, I am a new home assistant user, where do you put the files automation, template and customization ? thanks

KRLH2 commented 1 year ago

I have the same issue. Device info TS0601 by _TZE204_81yrt3lo I installed the Quirk: (ts0601_powermeter.TuyaPowerMeter_GPP) but the sensor only shows the power delivered. Please help me. Untitled image

pepepere commented 1 year ago

I have the same issue. Device info TS0601 by _TZE204_81yrt3lo I installed the Quirk: (ts0601_powermeter.TuyaPowerMeter_GPP) but the sensor only shows the power delivered. Please help me. ![Untitled]

For me, the best solution is migrate to zigbee2mqtt

freesty82 commented 1 year ago

I have the same issue. Device info TS0601 by _TZE204_81yrt3lo I installed the Quirk: (ts0601_powermeter.TuyaPowerMeter_GPP) but the sensor only shows the power delivered. Please help me. Untitled image

Hi, you can try my modified quirk posted here https://github.com/zigpy/zha-device-handlers/issues/2549#issuecomment-1741540474

freesty82 commented 1 year ago

hi everyone, freesty82, I am a new home assistant user, where do you put the files automation, template and customization ? thanks

Hi, Configuration: you can Include the customize.yaml file (with the line below) in your configuration.yaml (if it isn't already there) and you can put the customization there

customize: !include customize.yaml

Template: You can put the template directly in the configuration.yaml

Automation: you can create the automation From the UI: choose Settings which is located in the sidebar, then click on Automations & Scenes

KRLH2 commented 1 year ago

solved Thank you

fdrevet commented 11 months ago

Hi,

Thanks for your work, I managed to fetch both A and B power 👍

I also need to fetch the power direction for A and B to know when solar panels are producing more power than consumed power (ie. power B can be "negative")

Look like we need to use the IDs in "MatSee Power Meter Attributes" quicks's section :

MATSEE_DPID_POWER_DIRECTION_ID_A_ATTR = 0x0266 MATSEE_DPID_POWER_DIRECTION_ID_B_ATTR = 0x0268

Not working when using service 🧰 ZHA Toolkit: Read Attribute with 0x0266 and 0x0268 ids (it works with 0x0265 and 0x0269 to fetch power)

Any chance to get these values through the quirks or with ZHA Toolkit/automation ?

Regards

agnus777 commented 11 months ago

Hi,

any one discovered how to show info from the second clamp? Using the ts0601_din_power_MatSee_mod.zip I can only see the "A" clamp, data from "B" clampare not exposed.

image

jeverley commented 11 months ago

Hi all,

I've created my own quirk for the device which is able to expose sensors within Home Assistant for both clamps and correctly reflects power direction:

image

The above screenshot shows testing of the clamps on the same cable with one reversed (hence the negative value on the second power reading). Note that the power values differ due to reading inaccuracy of the device.

Please do test and let me know of any issues - I plan to upstream this once ready.

https://github.com/jeverley/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0601_energy_meter.py

Edit: I now also have attribute writes working so you should be able to configure your update_interval in seconds via the TuyaMatSeeManufCluster.

Edit 2: I've made a change of the remapped device type to METER_INTERFACE (used by smart meters), to ensure the Home Assistant sensor entity detection works reliably on first adding the device.

markwaters commented 11 months ago

Please do test and let me know of any issues - I plan to upstream this once ready.

Hey @jeverley , thanks for the work you are doing with this.

My Mains sensor value is negative. I see one of your power values is negative too. Is that normal ? (Sorry , I am new to all this.) Thanks.

2024-01-04-homeassistant-negative-power-value

jeverley commented 11 months ago

My Mains sensor value is negative. I see one of your power values is negative too. Is that normal ? (Sorry , I am new to all this.) Thanks.

A couple of things you'll want to check and confirm there:

Lastly please can you confirm if you're using the latest version of the current linked file: https://github.com/jeverley/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0601_energy_meter.py

I'd have expected to see voltage and frequency reported (unless you've disabled them).

agnus777 commented 11 months ago

Hi @jeverley,

thanks for the wonderful work done, now I can see both clamps, now I'm doing a test remotely, but everything seems to work as it should!

some questions:

thanks!!

Alessio

markwaters commented 11 months ago

My Mains sensor value is negative. I see one of your power values is negative too. Is that normal ? (Sorry , I am new to all this.) Thanks.

A couple of things you'll want to check and confirm there:

* first ensure that you have both clamps wired consistently (red should go into S1, black S2)

* since the clamps are directional, you should be able to flip the clamp direction around to reverse the reading it gives - there's an arrow inside the clamp that's visible when it is open that should help with helping you put it on the correct way round.

Lastly please can you confirm if you're using the latest version of the current linked file: https://github.com/jeverley/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0601_energy_meter.py

I'd have expected to see voltage and frequency reported (unless you've disabled them).

Thanks @jeverley , I have checked and repositioned the errant clamp and it is now showing a positive value , I had no idea there was a direction to the clamps. Also updated to the latest version of your file and am getting the extra entities now too. Thank you again. Mark.