Skip to content

Add per-charger energy statistics feed for Energy Dashboard - #416

Open
rhammen wants to merge 1 commit into
custom-components:masterfrom
rhammen:feature/energy-statistics-standalone
Open

Add per-charger energy statistics feed for Energy Dashboard#416
rhammen wants to merge 1 commit into
custom-components:masterfrom
rhammen:feature/energy-statistics-standalone

Conversation

@rhammen

@rhammen rhammen commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Implements feature #300.

The live Energy Meter sensor is polling-delayed, so energy lands in the wrong hour on the Energy Dashboard (see #300, also #162). This adds a separate long-term-statistics feed per charger, backfilled from Zaptec's archived charge sessions and imported hourly, so historical consumption is attributed to the correct hour.

  • New ZaptecStatisticsCoordinator (statistics.py) imports /api/sessions/archived into HA external statistics as zaptec:energy_<id>, shown in the Energy Dashboard device picker as " Energy".
  • Recorder is an after_dependency: if the recorder is disabled the integration still loads, only this feed is skipped.
  • Requires the Owner role (the endpoint is Owner-only); a 403 degrades just this feed with a warning, not the whole integration.
  • Backfills up to 730 days on first run, then imports hourly.

Because it is built from completed sessions, the most recent hour or two can lag — it's for accurate historical graphs, not real-time (the live sensor still covers that).

Tests cover the bucketing logic and the archived-sessions request. Full harness-based coordinator tests will follow once the test-framework migration (#414) lands.

This was written with AI assistance; I have personally reviewed the code. I've also tried to trim the docstrings/comments down in line with maintainer preference — happy to cut further if any still read as too verbose.

The live Energy Meter sensor is polling-delayed, so energy lands in the
wrong hour on the Energy Dashboard (custom-components#300, also custom-components#162). This adds a separate
long-term-statistics feed per charger, backfilled from Zaptec's archived
charge sessions and imported hourly, so historical consumption is
attributed to the correct hour.

- ZaptecStatisticsCoordinator imports /api/sessions/archived into HA
  external statistics as zaptec:energy_<id>, shown in the Energy Dashboard
  device picker as "<charger> Energy".
- Recorder is an after_dependency; if it is disabled the integration still
  loads and only this feed is skipped.
- Requires the Owner role (the endpoint is Owner-only); a 403 degrades just
  this feed with a warning, not the whole integration.
- Backfills up to 730 days on first run, then imports hourly.

Because it is built from completed sessions, the most recent hour or two can
lag - it is for accurate historical graphs, not real-time monitoring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant