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
719 stars 663 forks source link

[Device Support Request] for TZ3000_xkap8wtb TS000F #2447

Closed erkr closed 11 months ago

erkr commented 1 year ago

Problem description

I have a zigbee 3.0 wall switch with power monitoring. Switching and power readout work fine. The current readout is a factor 1000 to high though. Not sure if the usage readout is correct. Will report on that later.

Solution description

I guess a quirk can translate the reading to the right value. I hope someone can help to create a custom quirk I can use to test/modify till it is correct.

Screenshots/Video

Screenshots/Video This is the switch readout with a 40 watt bulb: image The current should be around 0.2A

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=4107, 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": "0x0100", "input_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x000a", "0x0702", "0x0b04", "0x1000", "0x1888", "0xe000" ], "output_clusters": [ "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "_TZ3000_xkap8wtb", "model": "TS000F", "class": "zigpy.device.Device" } ```

Diagnostic information

Diagnostic information ```json { "home_assistant": { "installation_type": "Home Assistant OS", "version": "2023.6.3", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.11.4", "docker": true, "arch": "aarch64", "timezone": "Europe/Amsterdam", "os_name": "Linux", "os_version": "6.1.21-v8", "supervisor": "2023.06.4", "host_os": "Home Assistant OS 10.3", "docker_version": "23.0.6", "chassis": "embedded", "run_as_root": true }, "custom_components": { "hacs": { "version": "1.32.1", "requirements": [ "aiogithubapi>=22.10.1" ] }, "pyscript": { "version": "1.4.0", "requirements": [ "croniter==1.3.8", "watchdog==2.2.1" ] }, "smartthinq_sensors": { "version": "0.31.8", "requirements": [ "pycountry>=20.7.3", "xmltodict>=0.12.0", "charset_normalizer>=2.0.0" ] }, "zha_toolkit": { "version": "v0.8.40", "requirements": [ "packaging>=20.8", "pytz" ] } }, "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.100", "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": 39735, "manufacturer": "_TZ3000_xkap8wtb", "model": "TS000F", "name": "_TZ3000_xkap8wtb TS000F", "quirk_applied": false, "quirk_class": "zigpy.device.Device", "manufacturer_code": 4107, "power_source": "Mains", "lqi": 252, "rssi": -83, "last_seen": "2023-06-29T16:14:02", "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=4107, 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": "0x0100", "input_clusters": [ "0x0000", "0x0003", "0x0004", "0x0005", "0x0006", "0x000a", "0x0702", "0x0b04", "0x1000", "0x1888", "0xe000" ], "output_clusters": [ "0x0019" ] }, "242": { "profile_id": "0xa1e0", "device_type": "0x0061", "input_clusters": [], "output_clusters": [ "0x0021" ] } }, "manufacturer": "_TZ3000_xkap8wtb", "model": "TS000F" }, "active_coordinator": false, "entities": [ { "entity_id": "button.tz3000_xkap8wtb_ts000f_identify", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "light.tz3000_xkap8wtb_ts000f_light", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "select.tz3000_xkap8wtb_ts000f_start_up_behavior", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "sensor.tz3000_xkap8wtb_ts000f_rms_current", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "sensor.tz3000_xkap8wtb_ts000f_rms_voltage", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "sensor.tz3000_xkap8wtb_ts000f_power_factor", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "sensor.tz3000_xkap8wtb_ts000f_active_power", "name": "_TZ3000_xkap8wtb TS000F" }, { "entity_id": "sensor.tz3000_xkap8wtb_ts000f_summation_delivered", "name": "_TZ3000_xkap8wtb TS000F" } ], "neighbors": [], "routes": [], "endpoint_names": [ { "name": "ON_OFF_LIGHT" }, { "name": "unknown 97 device_type of 0xa1e0 profile id" } ], "user_given_name": null, "device_reg_id": "536aa74e6ba17e02f792f32a1ef62dbc", "area_id": null, "cluster_details": { "1": { "device_type": { "name": "ON_OFF_LIGHT", "id": 256 }, "profile_id": 260, "in_clusters": { "0x0000": { "endpoint_attribute": "basic", "attributes": { "0x0004": { "attribute_name": "manufacturer", "value": "_TZ3000_xkap8wtb" }, "0x0005": { "attribute_name": "model", "value": "TS000F" } }, "unsupported_attributes": {} }, "0x0003": { "endpoint_attribute": "identify", "attributes": {}, "unsupported_attributes": {} }, "0x0004": { "endpoint_attribute": "groups", "attributes": {}, "unsupported_attributes": {} }, "0x0005": { "endpoint_attribute": "scenes", "attributes": {}, "unsupported_attributes": {} }, "0x0006": { "endpoint_attribute": "on_off", "attributes": { "0x0000": { "attribute_name": "on_off", "value": 0 }, "0x4001": { "attribute_name": "on_time", "value": 0 }, "0x4002": { "attribute_name": "off_wait_time", "value": 0 }, "0x4003": { "attribute_name": "start_up_on_off", "value": 1 } }, "unsupported_attributes": {} }, "0x000a": { "endpoint_attribute": "time", "attributes": {}, "unsupported_attributes": {} }, "0xe000": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} }, "0x0702": { "endpoint_attribute": "smartenergy_metering", "attributes": { "0x0000": { "attribute_name": "current_summ_delivered", "value": 0 }, "0x0200": { "attribute_name": "status", "value": 0 }, "0x0300": { "attribute_name": "unit_of_measure", "value": 0 }, "0x0301": { "attribute_name": "multiplier", "value": 0 }, "0x0302": { "attribute_name": "divisor", "value": 0 }, "0x0303": { "attribute_name": "summation_formatting", "value": 0 }, "0x0306": { "attribute_name": "metering_device_type", "value": 0 } }, "unsupported_attributes": { "0x0400": { "attribute_name": "instantaneous_demand" }, "0x0100": { "attribute_name": "current_tier1_summ_delivered" }, "0x0102": { "attribute_name": "current_tier2_summ_delivered" }, "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" }, "0x0304": { "attribute_name": "demand_formatting" } } }, "0x0b04": { "endpoint_attribute": "electrical_measurement", "attributes": { "0x0505": { "attribute_name": "rms_voltage", "value": 231 }, "0x0508": { "attribute_name": "rms_current", "value": 66 }, "0x050b": { "attribute_name": "active_power", "value": 0 }, "0x0600": { "attribute_name": "ac_voltage_multiplier", "value": 1 }, "0x0601": { "attribute_name": "ac_voltage_divisor", "value": 1 }, "0x0602": { "attribute_name": "ac_current_multiplier", "value": 1 }, "0x0603": { "attribute_name": "ac_current_divisor", "value": 1 }, "0x0604": { "attribute_name": "ac_power_multiplier", "value": 1 }, "0x0605": { "attribute_name": "ac_power_divisor", "value": 1 } }, "unsupported_attributes": { "0x0300": { "attribute_name": "ac_frequency" }, "0x050d": { "attribute_name": "active_power_max" }, "0x050f": { "attribute_name": "apparent_power" }, "0x0302": { "attribute_name": "ac_frequency_max" }, "0x0401": { "attribute_name": "ac_frequency_divisor" }, "0x0400": { "attribute_name": "ac_frequency_multiplier" }, "0x0000": { "attribute_name": "measurement_type" }, "0x0507": { "attribute_name": "rms_voltage_max" }, "0x0403": { "attribute_name": "power_divisor" }, "0x0402": { "attribute_name": "power_multiplier" }, "0x050a": { "attribute_name": "rms_current_max" } } }, "0x1000": { "endpoint_attribute": "lightlink", "attributes": {}, "unsupported_attributes": {} }, "0x1888": { "endpoint_attribute": null, "attributes": {}, "unsupported_attributes": {} } }, "out_clusters": { "0x0019": { "endpoint_attribute": "ota", "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 Na

Custom quirk

Custom quirk Na

W

Additional information

No response

erkr commented 1 year ago

Update: the total usage (kWh) readout is a factor 100 to high. Current by a factor 1000. Power factor unknown. No idea if it is actually supported. The type could be switch instead of light (detail). image

erkr commented 1 year ago

Update: I managed to make a custom quirk myself. The first time, so not sure it is according to all the rules: Fixes:

This gist contains the latest version of my custom quirk: https://gist.github.com/erkr/5d4addf1b4c8e18d68d2adb154c6be93

Maybe one of the active contributors ( @TheJulianJES @dmulcahey ) can have a look to decide if my quirk can be adopted into the official tuya list?! For me, it works. Some open ends:

Best Eric

TheJulianJES commented 11 months ago

Yep, quirk looks mostly good to me. Power factor entity shouldn't be created, as it's not supported, but it's a minor issue in ZHA for all power monitoring devices at the moment (and nothing that can/should be fixed in a quirk).

Z2M additionally exposes switch type for this device and that is still missing here

That seems to be attribute 0xD030 on cluster 0xE001. Try including TuyaZBExternalSwitchTypeCluster in the replacement and use the "Manage Zigbee device" dialog to check if writing that attribute (on that cluster) works. (The device likely just doesn't advertise having that cluster for some reason.)

erkr commented 11 months ago

Thanks for reviewing my first custom quirk. Good feedback 🙏

The option to change the device type in configuration.yaml is new to me. Will use that to remove my custom quirk without breaking my statistics 😊

I will try to add TuyaZBExternalSwitchTypeCluster and report back if that works later this week👌

Best Eric

erkr commented 11 months ago

@TheJulianJES I added TuyaZBExternalSwitchTypeCluster and tried to write 1 into attribute 0xD030. Although that command doesn't give an error (green checkmark in the button), reading it back reports `none'. Guess it is not working and removed the cluster.

PS: Will my device also be part of 2023.10.x? (as it is not a TS0011 plug)?!

arsenyspb commented 11 months ago

@erkr hola, and thank you for supporting the community and your ZHA contributions! I tried your custom quirk (...because I'm "lucky" to have same TZ3000_xkap8wtb as a pilot for in-line power meters I want to install for few circuits) but it either didn't pick up or mine didn't work. I still see ridiculous number of A in current and RMS is out of whack. Likely I didn't do something simple.

Anyways, do you plan doing a Pull Request to zigpy:dev similar to e.g. this one? If not, I can take over from you and tinker with it...

Once again, huge thanks for your support! Looking forward to see your quirk working in main branch!

erkr commented 11 months ago

@arsenyspb Thanks for trying my custom quirk. Those ridiculous values sound like the quirk is not really used (I guess you checked that) I won't deliver the quirk to dev, as I lack the experience how to do that. So if you take that over from me would be great! Please take the remark from Julian into account with respect to changing the device type (I changed it into a switch, Julian prefered to keep the original light type) I hope it works for you as well!! Success. Eric

arsenyspb commented 11 months ago

@erkr @TheJulianJES OK I think I've got it working, finally see sane numbers... As a reminder one needs to also delete wrong metrics' history (see here):

apk add sqlite
cd /config/
sqlite3 home-assistant_v2.db

now

sqlite> select * from states where metadata_id = (select metadata_id from states_meta where entity_id = 'sensor.<your_sensor_name_here>_summation_delivered');
sqlite> select * from states where metadata_id = (select metadata_id from states_meta where entity_id = 'sensor.<your_sensor_name_here>_rms_current');

This outputs the mad readings for power and Amps. Next, clean them up:

sqlite> delete from states where metadata_id = (select metadata_id from states_meta where entity_id = 'sensor.<your_sensor_name_here>_summation_delivered');
sqlite> delete from states where metadata_id = (select metadata_id from states_meta where entity_id = 'sensor.<your_sensor_name_here>_rms_current');

Profit.

arsenyspb commented 11 months ago

@erkr Once again kudos to your contribution, I've tweaked few things and battled the linter, - waiting for LGTM on pull/2613 , but please go ahead and see the final local quirk for cross-check, copy the code from here.

erkr commented 11 months ago

@arsenyspb Great, thanks for organising a delivery. I think when the review remarks are processed it's ready to rock and roll 🤓

erkr commented 11 months ago

Nice it works for you as well😊

erkr commented 10 months ago

@arsenyspb It reached the 2023.10.4 release. Removed my custom version and it works great with the released one. Thx.

klibro commented 4 weeks ago

I'm a bit confused, because from what I understand this fix made it into the 2023.10.4 release. However, I'm on 2024.8.0 and I have the same exact same symptoms with the Ts000f, namely current off by 1000 and energy used off by 100. Has this regressed or is there something I need to do to activate the fix?

erkr commented 4 weeks ago

@klibro Delete the device, restart HA and re-pairing can help. It should be using this quirk (device info -> zigbee info):

zhaquirks.tuya.ts000f_switch.Tuya_1G_Wall_Switch_Metering

No regression seen

klibro commented 4 weeks ago

Yes, I realise that the quirk is part of the distribution and should be being picked up. The reported model is definitely TS000F, and that should be enough to trigger the quirk, shouldn't it? Other quirks for other ZHA devices I have are being picked up. I'm also successfully applying a custom quirk. I have tried copying the distribution quirk and putting it into my custom quirk directory, but still this is not being picked up after a restart. I have just installed two TS000F devices, so although I can believe one might have glitched, for two not to work seems like it is a deeper issue. Is there some way to troubleshoot why quirks don't get applied?

klibro commented 4 weeks ago

I figured this out. The quirk in the release specifies a signature with endpoints 1 and 242, but upon inspecting my device, I found that it was only reporting a signature with the "1" endpoint. So the signature wasn't matching and hence the quirk wasn't being applied. I copied the release quirk into my custom quirks directory and removed the 242 endpoint from the signature and also from the replacement (is that right?) and all seems to be working as expected now.