-
Notifications
You must be signed in to change notification settings - Fork 882
ts0601_energy_meter quirk for Tuya power meter devices (v1 quirk) #2961
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
Conversation
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?
Amendments from details in zigpy#2650 & zigpy#2870 (however that approach uses attributes directly rather than datapoints).
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2961 +/- ##
==========================================
- Coverage 90.52% 88.66% -1.87%
==========================================
Files 324 325 +1
Lines 10631 11185 +554
==========================================
+ Hits 9624 9917 +293
- Misses 1007 1268 +261 ☔ View full report in Codecov by Sentry. |
sure, tell me what I should do. Your "quirk" looks more complete, my "quirk" is a one-off (and "my first quirk".. ).
Things I like in "mine":
|
Appreciate the feedback @jmuf , I've started to incorporate some changes based on your thoughts. Changes so far:
Outstanding:
|
Hey thanks for this quirk! I have the _TZE204_81yrt3lo but with only one clamp - some how I managed to order it with only one clamp - lol. My question is that there doesn't appear to be a difference between the power and instantaneous demand so why are both needed? I set mine up on the A and did have to flip my clamp to not get negative watts. |
Testing showed some assumptions to be incorrect, consumption_minus_production still needs some work
@jeverley double checked the wiring. Also made sure I had the LIVE cables (brown in UK). |
Appreciate the thoroughness, if you flip the orientation of the clamps does the flow direction change? |
I have a different meter model with a single clamp (CT-2101A) that is labelled as "S1.Black, S2.Red", does your manual say the other way round? I have tried looking up how these clamps work and I am not sure they would do anything at all if they were the wrong way round, but I thought I would mention it. |
No mention of it in my manual. |
Hmm that's odd, I'd have expected a flow reversal in that scenario - are you able to read the app_version attribute value from the Basic cluster? I can add some debug lines in the quirk to write out the raw reported data point values, possible your device is behaving differently to my own. |
Its back... |
Thanks for the answer @reef-actor for #2420 (comment) |
I have applied this. |
|
I'm afraid this quirk is specially made for PV distributors with consumption on one side and production on the other. Unfortunately, I have not yet been able to find a good quirk to measure the consumption of the 2 individual devices with the TS0601 _TZE204_81yrt3lo |
I'm working on adding _TZE284_81yrt3lo and plan to base my work on branch from you @jeverley. Zigbee2Mqtt folks seem to got it working based on
Di you plan to get this one merged upstream anytime soon, or would it make more sense for me to base it on the QuickBuilder? My Setup
|
I'd started to lay the groundwork for a quirk builder based implementation over the weekend using the tuya quirk builder component (https://github.com/zigpy/zha-device-handlers/blob/dev/tuya.md), I'll push these local changes to a new branch this afternoon. I think we can simplify a lot of what's in my existing v1 quirk, particularly to get a first release of it mainlined. |
Work in progress on the v2 quirk can be found here, should have something testable locally by tomorrow - note this will definitely produce errors right now. |
Great @jeverley! I only was able to get channel A to work, with no modifications, just adding the device information. |
The code in the v2 repo should now expose the device using the new quirk format. I currently can see values from both clamps in my testing, and you can select different virtual channel calculations (A plus B, A minus B, B minus A). There's still some work needed on the power flow handling, but you're welcome to give it a try. |
I'll be progressing this under the new v2 quirk PR #3824 |
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:
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.
Addresses device support requests:
2 bidirectional clamps:
1 bidirectional clamp:
1 clamp:
@jmuf I've just spotted that in parallel you've also been working on #2870 for _TZE200_rks0sgb7, shall we pool ideas?
Additional information
Associated with merged pre-requisite ZHA metering and electrical measurement changes:
Checklist
pre-commit
checks pass / the code has been formatted using Black