zha-device-handlers icon indicating copy to clipboard operation
zha-device-handlers copied to clipboard

ts0601_energy_meter quirk for Tuya power meter devices

Open jeverley opened this issue 1 year ago • 29 comments

Proposed change

Adds support for Tuya Energy Meter devices in 1 and 2 clamp configurations.

Uses zigbee2Mqtt https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/tuya.ts as reference for device datapoints (with amendments from community testing in the respective device support issues).

Meter devices providing power direction will report signed values for their supported attributes in accordance with the Zigbee cluster spec (instantaneous demand, active power and reactive power specifically).

Provides control over metering sensor configuration:

  • The quirk allows the user to control the endpoint 3 power calculation on 2 clamp devices using the "channel_configuration" attribute value (calculated as either a+b or a-b).
    • a+b should be used when measuring total consumption from two power sources.
    • a-b should be used to derive a second power value from input power and consumption i.e. clamp A on grid input, clamp B measuring power into the consumer unit.

Some devices report an a+b total natively, however in testing this value is often incorrect due to delay in detecting power direction change on the device.

In the real world when measuring both grid and production an a + b < 0 value would be atypical. This is mitigated using the power_flow_preempt filter on device readings, this is optionally is enabled by setting 'power_flow_preempt' to True.

The quirk aims to make adding new devices simpler by utilising device specific dp_to_attribute mappings which feed into common core reporting clusters.

image

Addresses device support requests:

2 bidirectional clamps:

  • https://github.com/zigpy/zha-device-handlers/issues/2549 (_TZE204_81yrt3lo)
  • https://github.com/zigpy/zha-device-handlers/issues/2650 (_TZE200_rks0sgb7)

1 bidirectional clamp:

  • https://github.com/zigpy/zha-device-handlers/issues/2420 (_TZE204_ac0fhfiq)

1 clamp:

  • https://github.com/zigpy/zha-device-handlers/issues/1973 (_TZE204_cjbofhxw)

@jmuf I've just spotted that in parallel you've also been working on https://github.com/zigpy/zha-device-handlers/pull/2870 for _TZE200_rks0sgb7, shall we pool ideas?

Additional information

Associated with merged pre-requisite ZHA metering and electrical measurement changes:

  • https://github.com/home-assistant/core/pull/107641
  • https://github.com/home-assistant/core/pull/107576
  • https://github.com/home-assistant/core/pull/109126

Checklist

  • [ ] The changes are tested and work correctly
  • [x] pre-commit checks pass / the code has been formatted using Black
  • [ ] Tests have been added to verify that the new code works

jeverley avatar Feb 01 '24 08:02 jeverley