Fix spurious energy resets on ZEN20/ZEN25 power strips#57
Open
electricessence wants to merge 3 commits intojtp10181:mainfrom
Open
Fix spurious energy resets on ZEN20/ZEN25 power strips#57electricessence wants to merge 3 commits intojtp10181:mainfrom
electricessence wants to merge 3 commits intojtp10181:mainfrom
Conversation
Added energy tracking features, including base correction for device resets and monotonic energy value calculation. Implemented reset functionality for energy tracking across parent and child devices.
…s-energy-tracking Implement energy tracking and reset functionality
Author
|
@jtp10181 I'm currently testing this fix on my Hubitat now. |
There was a problem hiding this comment.
Pull request overview
Adds monotonic energy (kWh) reporting for Zooz ZEN20/ZEN25 multi-channel plug/strip devices by tracking and compensating for device-reported energy counter resets using per-device data values (parent + child endpoints).
Changes:
- Add energy tracking via
energyBase+energyLastReportedstored in device data values to absorb negative deltas. - Update energy event emission to publish corrected (monotonic) energy values for parent and child endpoints.
- Clear energy tracking data for parent and all children when Reset Stats is invoked.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
@jtp10181 I've been testing this for days. It's working great. Only affects energy totals and works perfectly with child devices. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ZEN20 (and ZEN25) periodically resets its energy (kWh) counters to zero without user action — sometimes as often as once a day. This affects the parent device and all child endpoints (5 plugs, 2 USB). Because the reset only affects the energy value and not the duration, it's clearly a device firmware issue rather than a legitimate reset. With 4+ power strips (24+ devices), correcting this downstream is not feasible.
Solution
Added monotonic energy tracking that absorbs spurious resets. The reported
energyattribute is now alwaysenergyBase + deviceReportedValue, whereenergyBaseis the cumulative sum of negative deltas from the device.energyBaseenergyvalue continues to climb as expectedenergyBasefor the parent and all children, so user-initiated resets work normallyImplementation
Two small helper functions that operate on any device object (parent or child):
trackEnergy(dev, value)— reads/writesenergyBaseandenergyLastReportedviagetDataValue/updateDataValue, returns the corrected energy valueresetEnergyTracking(dev)— removes both data values from the deviceUsing
updateDataValue/getDataValue(instead ofstate) because:state.clear()— no backup/restore needed inclearVariablesEdge case: If a stale MeterReport is in-flight when Reset Stats is clicked, it could briefly re-establish a
energyLastReportedthat triggers false drop detection on the next real report. This window is extremely narrow (report intervals are 30-60+ seconds) and self-corrects by clicking Reset Stats again.