Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix grid to battery calculation in absence of solar production #5

Merged
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
9 changes: 8 additions & 1 deletion src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,14 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
}
solar.state.toBattery = battery.state.toBattery! - (grid.state.toBattery || 0);
} else if (!solar.has && battery.has) {
// In the absence of solar production, the battery is the only energy producer
// besides the grid, so whatever was given to the grid must come from
// the battery
battery.state.toGrid = grid.state.toGrid ?? 0;

// In the absence of solar production, what was consumed by the battery
// must come from the grid, since there are no other energy producers.
grid.state.toBattery = (battery.state.toBattery ?? 0);
}

// Update State Values of Solar to Grid
Expand Down Expand Up @@ -855,7 +862,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
const totalIndividualConsumption = coerceNumber(individual1.state, 0) + coerceNumber(individual2.state, 0);

// Calculate Sum of All Sources to get Total Home Consumption
const totalHomeConsumption = Math.max(grid.state.fromGrid + (solar.state.toHome ?? 0) + (battery.state.toHome ?? 0), 0);
const totalHomeConsumption = Math.max(grid.state.fromGrid - (grid.state.toBattery ?? 0) + (solar.state.toHome ?? 0) + (battery.state.toHome ?? 0), 0);

// Calculate Circumference of Semi-Circles
let homeBatteryCircumference = 0;
Expand Down
Loading