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

ts0601_energy_meter quirk for Tuya power meter devices (v2 quirk) #3824

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

jeverley
Copy link
Contributor

@jeverley jeverley commented Feb 2, 2025

Proposed change

Adds support for Tuya Energy Meter devices.

Reimplementation of my original PR #2961 using the v2 Tuya quirk builder.

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 energy direction will report signed values for their ZCL mapped attributes in accordance with the Zigbee cluster spec (instantaneous demand, active power and reactive power specifically).

To keep the change size manageable this initial PR will not calculate additional power metrics that are not reported by the device (reactive power etc), I can explore re-introducing this if users are keen for the functionality.

Device configuration entities

  • Virtual channel: choose the calculation on multi clamp devices for calculating the virtual value.
    • Total
    • A minus B
    • B minus A
  • Calibration: adjust reported values by a percentage (_TZE204_81yrt3lo).
  • Energy direction delay mitigation: this controls whether the quirk will compensate for delayed direction data point reporting (_TZE204_81yrt3lo).
    • Automatic (enabled based on device and firmware version)
    • Disabled (values reported immediately)
    • Enabled (value updates are delayed until the next direction is reported).

Supports 1 clamp devices:

Supports 2 clamp devices:

Supports 3 clamp devices:

Additional information

Checklist

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

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 19 lines in your changes missing coverage. Please review.

Project coverage is 90.91%. Comparing base (ab4e4f5) to head (a6a0eda).
Report is 14 commits behind head on dev.

Files with missing lines Patch % Lines
zhaquirks/tuya/ts0601_energy_meter.py 90.90% 19 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #3824    +/-   ##
========================================
  Coverage   90.91%   90.91%            
========================================
  Files         324      326     +2     
  Lines       10562    10775   +213     
========================================
+ Hits         9602     9796   +194     
- Misses        960      979    +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jeverley jeverley force-pushed the ts0601_energy_meter_v2_quirk branch 3 times, most recently from 9eae2ea to 724d721 Compare February 3, 2025 21:18
@jeverley jeverley force-pushed the ts0601_energy_meter_v2_quirk branch from 119c33f to 9838136 Compare February 3, 2025 22:51
@jeverley jeverley force-pushed the ts0601_energy_meter_v2_quirk branch from 9838136 to a6a0eda Compare February 3, 2025 22:56
@jeverley jeverley marked this pull request as ready for review February 3, 2025 23:32
@jeverley
Copy link
Contributor Author

jeverley commented Feb 3, 2025

This should be ready for testing once #3643 is merged.

@TheJulianJES TheJulianJES added Tuya Request/PR regarding a Tuya device needs review This PR should be reviewed soon, as it generally looks good. needs reviewer answer An answer from a reviewer is needed (e.g. why a PR isn't acceptable in the current state). labels Feb 4, 2025
Energy direction handler improvements

Apply pre-commit auto fixes
@jeverley jeverley force-pushed the ts0601_energy_meter_v2_quirk branch from 55847c0 to b566139 Compare February 4, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review This PR should be reviewed soon, as it generally looks good. needs reviewer answer An answer from a reviewer is needed (e.g. why a PR isn't acceptable in the current state). Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants