Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,29 @@ export class PowerFlowCardPlus extends LitElement {
}
}
solar.state.toHome = 0;
} else if (solar.state.toHome !== null && solar.state.toHome > 0) {
grid.state.toBattery = 0;

} else if (battery.state.toBattery && battery.state.toBattery > 0) {
grid.state.toBattery = battery.state.toBattery;
// Allocate PV to the battery first; only the remainder can be Grid → Battery.
const pvTotal = Math.max(solar.state.total ?? 0, 0);
const battCharge = Math.max(battery.state.toBattery ?? 0, 0);
const gridExport = Math.max(grid.state.toGrid ?? 0, 0); // 0 if you don't have export

// PV → Battery portion (capped by battery charge)
const pvToBattery = Math.min(pvTotal, battCharge);

// Residual charge must come from the grid
grid.state.toBattery = Math.max(battCharge - pvToBattery, 0);

// PV left for Home after reserving PV→Battery (and any export)
solar.state.toHome = Math.max(pvTotal - pvToBattery - gridExport, 0);

// Explicit PV→Battery for rendering
solar.state.toBattery = pvToBattery;
}
grid.state.toBattery =
(grid.state.toBattery ?? 0) > largestGridBatteryTolerance ? grid.state.toBattery : 0;


grid.state.toBattery = (grid.state.toBattery ?? 0) > largestGridBatteryTolerance ? grid.state.toBattery : 0;

if (battery.has) {
Expand Down