Skip to content

Commit 340230a

Browse files
Bug fix where best charge percentage wasn't always selected
1 parent c9c38cb commit 340230a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

predbat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,13 @@ def optimise_charge_limit(self, window_n, record_charge_windows, charge_window,
978978
metric += metric_diff
979979

980980
self.debug_enable = was_debug
981-
if self.debug_enable:
981+
if self.debug_enable or 1:
982982
self.log("Tried soc {} for window {} gives import battery {} house {} export {} min_soc {} cost {} metric {} metricmid {} metric10 {}".format
983983
(try_soc, window_n, self.dp2(import_kwh_battery), self.dp2(import_kwh_house), self.dp2(export_kwh), self.dp2(soc_min), self.dp2(cost), self.dp2(metric), self.dp2(metricmid), self.dp2(metric10)))
984984

985985
# Only select the lower SOC if it makes a notable improvement has defined by min_improvement (divided in M windows)
986986
# and it doesn't fall below the soc_keep threshold
987-
if ((metric + (self.metric_min_improvement / record_charge_windows) < best_metric)) and (soc_min >= self.best_soc_keep):
987+
if (metric + (self.metric_min_improvement / record_charge_windows)) <= best_metric and (soc_min >= self.best_soc_keep):
988988
best_metric = metric
989989
best_soc = try_soc
990990
best_cost = cost
@@ -1229,7 +1229,7 @@ def update_pred(self):
12291229
for window_n in range(0, record_charge_windows):
12301230
best_soc, best_metric, best_cost = self.optimise_charge_limit(window_n, record_charge_windows, self.charge_window_best, self.charge_limit_best, load_minutes, pv_forecast_minute, pv_forecast_minute10)
12311231

1232-
if self.debug_enable:
1232+
if self.debug_enable or 1:
12331233
self.log("Best charge limit window {} (adjusted) soc calculated at {} (margin added {} and min {}) with metric {} cost {}".format(window_n, self.dp2(best_soc), self.best_soc_margin, self.best_soc_min, self.dp2(best_metric), self.dp2(best_cost)))
12341234
self.charge_limit_best[window_n] = best_soc
12351235

0 commit comments

Comments
 (0)