-
Notifications
You must be signed in to change notification settings - Fork 693
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 #2961
base: dev
Are you sure you want to change the base?
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 87.90% 85.92% -1.99%
==========================================
Files 300 301 +1
Lines 9222 9775 +553
==========================================
+ Hits 8107 8399 +292
- Misses 1115 1376 +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 sure thing. I used the following quirks file: https://github.com/jeverley/zha-device-handlers/blob/ts0601_energy_meter/zhaquirks/tuya/ts0601_energy_meter.py downloaded in the wee hours of this morning. Setup procedure:
Got no Sensors only the Configuration and Diagnostic panels.
Success!! At this point it was under my desk with the clamps not connected to anything.
After a moment I got the below: Fantastic work so far @jeverley ! A few observations.
My ZHA diagnostic file attached: Let me know if yo need anything else tested. |
Thanks very much @Vladdy65, please could you give the version in branch https://github.com/jeverley/zha-device-handlers/tree/ts0601_energy_meter_devices a try? File linked directly: That one has my more recent changes including the different configurable summation methods and support for similar device models. |
The terminology is refering to the load (aka your house). When you are using electricity it is being "delivered" to your house, when you are producing it is being "received" from your house. |
The link gives me a 404 error. Could you confirm again correct file path please. |
@reef-actor
I tried but struggled to make sentences using 'House' as the subject with the terms the other way round.
So I asked our friendly AI (Copilot) about it, this is the conversation 🤔: You Subject: |
A better reference might be the zigbee standard (Page 217) 😜 |
@reef-actor I stand humbled by my ignorance. 😔 |
@jeverley No change on first adding the device: Seems like some weird stuff is going on now I'm afraid. |
If you go into Manage Device, please could you read the values of the attributes:
From the TuyaEnergyMeterManufCluster? |
What I have is:
|
Thanks @Vladdy65, do you definitely have the arrow inside the clamps facing in the direction of delivered power, and the red cables of the clamps connected to their corresponding S1 terminal on the module? |
@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 |
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