From 3dd3fce71667ebc79410d3e2c15f52e0d6a43189 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:00:50 +0000 Subject: [PATCH 1/2] Fix issue with charge rate being reset when it shouldn't be in low power mode Maybe related to: https://github.com/springfall2008/batpred/issues/650 --- apps/predbat/predbat.py | 45 ++++++++++------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 712f278dd..0c2680e42 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -4857,7 +4857,11 @@ def find_charge_window(self, rates, minute, threshold_rate, find_high): # If combine is disabled, for import slots make them all N minutes so we can select some not all rate_low_end = minute break - if (rate_low_start in self.manual_all_times or minute in self.manual_all_times) and (rate_low_start >= 0) and ((minute - rate_low_start) >= 30): + if ( + (rate_low_start in self.manual_all_times or minute in self.manual_all_times) + and (rate_low_start >= 0) + and ((minute - rate_low_start) >= 30) + ): # Manual slot rate_low_end = minute break @@ -6777,14 +6781,7 @@ def optimise_charge_limit_price( # Simulate with medium PV metricmid, import_kwh_battery, import_kwh_house, export_kwh, soc_min, soc, soc_min_minute, battery_cycle, metric_keep, final_iboost = self.run_prediction( - try_charge_limit, - charge_window, - discharge_window, - try_discharge, - load_minutes_step, - pv_forecast_minute_step, - end_record=end_record, - step=step, + try_charge_limit, charge_window, discharge_window, try_discharge, load_minutes_step, pv_forecast_minute_step, end_record=end_record, step=step, ) # Debug re-enable if it was on @@ -7513,13 +7510,7 @@ def discard_unused_charge_slots(self, charge_limit_best, charge_window_best, res end = window["end"] limit = charge_limit_best[window_n] - if ( - new_window_best - and (start == new_window_best[-1]["end"]) - and (limit == new_limit_best[-1]) - and (start not in self.manual_all_times) - and (new_window_best[-1]["start"] not in self.manual_all_times) - ): + if new_window_best and (start == new_window_best[-1]["end"]) and (limit == new_limit_best[-1]) and (start not in self.manual_all_times) and (new_window_best[-1]["start"] not in self.manual_all_times): new_window_best[-1]["end"] = end if self.debug_enable: self.log( @@ -7726,13 +7717,7 @@ def discard_unused_discharge_slots(self, discharge_limits_best, discharge_window for window_n in range(0, len(discharge_limits_best)): if discharge_limits_best[window_n] < 100.0: # Also merge contiguous enabled windows - if ( - new_best - and (discharge_window_best[window_n]["start"] == new_best[-1]["end"]) - and (discharge_limits_best[window_n] == new_enable[-1]) - and (discharge_window_best[window_n]["start"] not in self.manual_all_times) - and (new_best[-1]["start"] not in self.manual_all_times) - ): + if new_best and (discharge_window_best[window_n]["start"] == new_best[-1]["end"]) and (discharge_limits_best[window_n] == new_enable[-1]) and (discharge_window_best[window_n]["start"] not in self.manual_all_times) and (new_best[-1]["start"] not in self.manual_all_times): new_best[-1]["end"] = discharge_window_best[window_n]["end"] if self.debug_enable: self.log("Combine discharge slot {} with previous - percent {} slot {}".format(window_n, new_enable[-1], new_best[-1])) @@ -7928,11 +7913,7 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca if self.calculate_best_charge and (window_start not in self.manual_all_times): if not printed_set: - self.log( - "Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format( - price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost) - ) - ) + self.log("Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format(price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost))) printed_set = True average = self.charge_window_best[window_n]["average"] @@ -7998,11 +7979,7 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca continue if not printed_set: - self.log( - "Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format( - price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost) - ) - ) + self.log("Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format(price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost))) printed_set = True best_soc, best_start, best_metric, best_cost, soc_min, soc_min_minute, best_keep = self.optimise_discharge( @@ -9101,7 +9078,7 @@ def execute_plan(self): inverter.adjust_force_discharge(False) resetReserve = True - if self.set_discharge_freeze: + if self.set_discharge_freeze and not isCharging: # In discharge freeze mode we disable charging during discharge slots, so turn it back on otherwise inverter.adjust_charge_rate(inverter.battery_rate_max_charge * 60 * 1000) elif self.set_discharge_window: From f364492e517648518a5d0c39995fe0979beae380 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:02:25 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- apps/predbat/predbat.py | 43 +++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 0c2680e42..4bc392868 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -4857,11 +4857,7 @@ def find_charge_window(self, rates, minute, threshold_rate, find_high): # If combine is disabled, for import slots make them all N minutes so we can select some not all rate_low_end = minute break - if ( - (rate_low_start in self.manual_all_times or minute in self.manual_all_times) - and (rate_low_start >= 0) - and ((minute - rate_low_start) >= 30) - ): + if (rate_low_start in self.manual_all_times or minute in self.manual_all_times) and (rate_low_start >= 0) and ((minute - rate_low_start) >= 30): # Manual slot rate_low_end = minute break @@ -6781,7 +6777,14 @@ def optimise_charge_limit_price( # Simulate with medium PV metricmid, import_kwh_battery, import_kwh_house, export_kwh, soc_min, soc, soc_min_minute, battery_cycle, metric_keep, final_iboost = self.run_prediction( - try_charge_limit, charge_window, discharge_window, try_discharge, load_minutes_step, pv_forecast_minute_step, end_record=end_record, step=step, + try_charge_limit, + charge_window, + discharge_window, + try_discharge, + load_minutes_step, + pv_forecast_minute_step, + end_record=end_record, + step=step, ) # Debug re-enable if it was on @@ -7510,7 +7513,13 @@ def discard_unused_charge_slots(self, charge_limit_best, charge_window_best, res end = window["end"] limit = charge_limit_best[window_n] - if new_window_best and (start == new_window_best[-1]["end"]) and (limit == new_limit_best[-1]) and (start not in self.manual_all_times) and (new_window_best[-1]["start"] not in self.manual_all_times): + if ( + new_window_best + and (start == new_window_best[-1]["end"]) + and (limit == new_limit_best[-1]) + and (start not in self.manual_all_times) + and (new_window_best[-1]["start"] not in self.manual_all_times) + ): new_window_best[-1]["end"] = end if self.debug_enable: self.log( @@ -7717,7 +7726,13 @@ def discard_unused_discharge_slots(self, discharge_limits_best, discharge_window for window_n in range(0, len(discharge_limits_best)): if discharge_limits_best[window_n] < 100.0: # Also merge contiguous enabled windows - if new_best and (discharge_window_best[window_n]["start"] == new_best[-1]["end"]) and (discharge_limits_best[window_n] == new_enable[-1]) and (discharge_window_best[window_n]["start"] not in self.manual_all_times) and (new_best[-1]["start"] not in self.manual_all_times): + if ( + new_best + and (discharge_window_best[window_n]["start"] == new_best[-1]["end"]) + and (discharge_limits_best[window_n] == new_enable[-1]) + and (discharge_window_best[window_n]["start"] not in self.manual_all_times) + and (new_best[-1]["start"] not in self.manual_all_times) + ): new_best[-1]["end"] = discharge_window_best[window_n]["end"] if self.debug_enable: self.log("Combine discharge slot {} with previous - percent {} slot {}".format(window_n, new_enable[-1], new_best[-1])) @@ -7913,7 +7928,11 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca if self.calculate_best_charge and (window_start not in self.manual_all_times): if not printed_set: - self.log("Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format(price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost))) + self.log( + "Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format( + price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost) + ) + ) printed_set = True average = self.charge_window_best[window_n]["average"] @@ -7979,7 +7998,11 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca continue if not printed_set: - self.log("Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format(price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost))) + self.log( + "Optimise price set {} start_at_low {} best_price {} best_metric {} best_cost {}".format( + price, start_at_low, best_price, self.dp2(best_metric), self.dp2(best_cost) + ) + ) printed_set = True best_soc, best_start, best_metric, best_cost, soc_min, soc_min_minute, best_keep = self.optimise_discharge(