Skip to content

Commit

Permalink
Fixes related to export planning
Browse files Browse the repository at this point in the history
  • Loading branch information
springfall2008 authored Dec 13, 2024
1 parent 207822d commit a444186
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions apps/predbat/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ def update_target_values(self):
self.export_window_best[window_n]["target"] = self.export_limits_best[window_n]
for window_n in range(len(self.charge_limit_best)):
self.charge_window_best[window_n]["target"] = self.charge_limit_best[window_n]

def tweak_plan(self, end_record, best_metric, metric_keep):
"""
Tweak existing plan only
Expand Down Expand Up @@ -1866,7 +1866,7 @@ def optimise_all_windows(self, best_metric, metric_keep, debug_mode=False):
record_charge_windows = max(self.max_charge_windows(self.end_record + self.minutes_now, self.charge_window_best), 1)
record_export_windows = max(self.max_charge_windows(self.end_record + self.minutes_now, self.export_window_best), 1)
window_sorted, window_index, price_set, price_links = self.sort_window_by_price_combined(self.charge_window_best[:record_charge_windows], self.export_window_best[:record_export_windows])

best_soc = self.soc_max
best_cost = best_metric
best_keep = metric_keep
Expand Down
30 changes: 13 additions & 17 deletions apps/predbat/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,9 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi
if export_window_n >= 0:
discharge_min = max(self.soc_max * export_limits[export_window_n] / 100.0, self.reserve, self.best_soc_min)

if not self.set_export_freeze_only and (export_window_n >= 0) and export_limits[export_window_n] < 100.0 and (soc - step * self.battery_rate_max_discharge_scaled) < discharge_min:
# Export runs out of battery - give penalty for this case, we might not stop it in time
metric_keep += step * self.battery_rate_max_discharge_scaled * rate_import.get(minute_absolute, 0) * 0.5

if not self.set_export_freeze_only and (export_window_n >= 0) and export_limits[export_window_n] < 100.0 and (soc - step * self.battery_rate_max_discharge_scaled) >= discharge_min:
if not self.set_export_freeze_only and (export_window_n >= 0) and export_limits[export_window_n] < 99.0 and (soc - step * self.battery_rate_max_discharge_scaled) >= discharge_min:
# Discharge enable
discharge_rate_now = self.battery_rate_max_discharge # Assume discharge becomes enabled here
discharge_rate_now = self.battery_rate_max_discharge # Assume discharge becomes enabled here
discharge_rate_now_curve = get_discharge_rate_curve(soc, discharge_rate_now, self.soc_max, self.battery_rate_max_discharge, self.battery_discharge_power_curve, self.battery_rate_min) * self.battery_rate_max_scaling_discharge

battery_draw = min(discharge_rate_now_curve * step, battery_to_min)
Expand Down Expand Up @@ -649,19 +645,19 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi
if save in ["best", "best10", "test"]:
# Only tune charge rate on final plan not every simulation
charge_rate_now = find_charge_rate(
minute_absolute,
soc,
charge_window[charge_window_n],
charge_limit_n,
self.battery_rate_max_charge,
self.soc_max,
self.battery_charge_power_curve,
self.set_charge_low_power,
minute_absolute,
soc,
charge_window[charge_window_n],
charge_limit_n,
self.battery_rate_max_charge,
self.soc_max,
self.battery_charge_power_curve,
self.set_charge_low_power,
self.charge_low_power_margin,
self.battery_rate_min,
self.battery_rate_max_scaling,
self.battery_loss,
None,
None
)
else:
charge_rate_now = self.battery_rate_max_charge # Assume charge becomes enabled here
Expand Down Expand Up @@ -815,8 +811,8 @@ def run_prediction(self, charge_limit, charge_window, export_window, export_limi
if soc < self.best_soc_keep and battery_draw > 0:
# Apply keep as a percentage of the time in the future so it gets stronger over an 4 hour period
# Weight to 50% chance of the scenario
# keep_diff = max(get_diff(0, 0, pv_now, load_yesterday, inverter_loss), battery_draw)
# if keep_diff > 0:
#keep_diff = max(get_diff(0, 0, pv_now, load_yesterday, inverter_loss), battery_draw)
#if keep_diff > 0:
metric_keep += rate_import[minute_absolute] * battery_draw * keep_minute_scaling
if diff > 0:
# Import
Expand Down

0 comments on commit a444186

Please sign in to comment.