Skip to content

HEM: log realized export kWh per slot in execution_log #420

@albinati

Description

@albinati

The new Plan and Home tabs in #418 surface yesterday's export totals from `/attribution/day` and `/energy/report`, but per-slot realized export kWh isn't logged anywhere. `/api/v1/execution/today` carries consumption per slot but no export counterpart.

This means we can't:

  • Overlay realized export kWh on the "Yesterday + actuals" rates chart (we have rates and import kWh; export kWh is the missing piece).
  • Compute precise per-slot export earnings (we currently estimate `yesterday total kWh × current export rate`, flagged as estimate in the UI).

What's needed

  1. Add `export_kwh` column to `execution_log` table (migration).
  2. Compute it in the heartbeat:
    • When `grid_kw < 0` for the slot duration, integrate to kWh and store.
    • Source: Fox grid power measurements (same source as the existing `consumption_kwh`).
  3. Expose in `/api/v1/execution/today` response.
  4. Plumb through the type in ExecutionSlot (already declared in the UI types as `export_kwh?`, currently always undefined).
  5. (Optional) Backfill historical export_kwh from existing `pv_realtime_history` rows if available, otherwise leave NULL.

Why now

UI rebuild (#418) exposed the gap. Without this, the rates view on Plan can show today/tomorrow/yesterday import + export rates side-by-side but only realized import — half the story.

Workaround until shipped: UI shows totals from `/attribution/day` (daily aggregate) and flags estimates as estimates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions