Skip to content

Fix spurious energy resets on ZEN20/ZEN25 power strips#57

Open
electricessence wants to merge 3 commits intojtp10181:mainfrom
Electrified-Home:main
Open

Fix spurious energy resets on ZEN20/ZEN25 power strips#57
electricessence wants to merge 3 commits intojtp10181:mainfrom
Electrified-Home:main

Conversation

@electricessence
Copy link

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 energy attribute is now always energyBase + deviceReportedValue, where energyBase is the cumulative sum of negative deltas from the device.

  • When the device-reported energy drops (e.g., 5.2 → 0), the lost amount is added to energyBase
  • The emitted energy value continues to climb as expected
  • Clicking Reset Stats clears energyBase for the parent and all children, so user-initiated resets work normally

Implementation

Two small helper functions that operate on any device object (parent or child):

  • trackEnergy(dev, value) — reads/writes energyBase and energyLastReported via getDataValue/updateDataValue, returns the corrected energy value
  • resetEnergyTracking(dev) — removes both data values from the device

Using updateDataValue/getDataValue (instead of state) because:

  • Works uniformly on parent and child devices from the parent driver
  • Survives state.clear() — no backup/restore needed in clearVariables
  • Values visible in the "Data" section of each device page for debugging

Edge case: If a stale MeterReport is in-flight when Reset Stats is clicked, it could briefly re-establish a energyLastReported that 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.

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
Copilot AI review requested due to automatic review settings February 10, 2026 16:08
@electricessence
Copy link
Author

@jtp10181 I'm currently testing this fix on my Hubitat now.
It will take a day or two to see if the issue is fixed.
I'll report back in a couple days.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + energyLastReported stored 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.

@electricessence
Copy link
Author

@jtp10181 I've been testing this for days. It's working great. Only affects energy totals and works perfectly with child devices.
LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants