Skip to content
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
39 changes: 20 additions & 19 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import yaml

THIS_VERSION = "v7.14.26"
THIS_VERSION = "v7.14.27"
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z"
TIME_FORMAT_OCTOPUS = "%Y-%m-%d %H:%M:%S%z"
Expand Down Expand Up @@ -4721,7 +4721,7 @@ def rate_replicate(self, rates, rate_io={}, is_import=True, is_gas=False):
and (minute_mod in self.future_energy_rates_export)
):
prev_rate = rate_offset
rate_offset = rate_offset - self.future_energy_rates_export[minute_mod] + self.future_energy_rates_export[minute]
rate_offset = max(rate_offset - self.future_energy_rates_export[minute_mod] + self.future_energy_rates_export[minute], 0)
elif is_import:
rate_offset = rate_offset + self.metric_future_rate_offset_import
elif (not is_import) and (not is_gas):
Expand Down Expand Up @@ -7709,10 +7709,6 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
best_price, best_price_discharge, lowest_price_charge, self.charge_limit_best
)
)
charge_windows = []
discharge_windows = []
charge_socs = []
discharge_socs = []
for start_at_low in [False, True]:
if start_at_low:
price_set.reverse()
Expand All @@ -7729,13 +7725,11 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
# Store price set with window
self.charge_window_best[window_n]["set"] = price

# Skip those outside threshold
# For start at high only tune down excess high slots
if (not start_at_low) and (price > best_price) and (self.charge_limit_best[window_n] != self.soc_max):
if self.debug_enable:
self.log("Skip start at high window {} best limit {}".format(window_n, (self.charge_limit_best[window_n])))
continue
if start_at_low and price <= best_price:
continue

if self.calculate_best_charge:
if not printed_set:
Expand All @@ -7757,8 +7751,6 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
end_record=self.end_record,
)
self.charge_limit_best[window_n] = best_soc
charge_windows.append(self.charge_window_best[window_n])
charge_socs.append(self.calc_percent_limit(best_soc))

if 0:
# Find all adjacent windows in price range
Expand Down Expand Up @@ -7818,7 +7810,8 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
self.discharge_window_best[window_n]["set"] = price

# Do highest price first
if start_at_low:
# Second pass to tune down any excess exports only
if start_at_low and ((price > best_price) or (self.discharge_limits_best[window_n] == 100.0)):
continue

if self.calculate_best_discharge:
Expand Down Expand Up @@ -7858,8 +7851,7 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
)
self.discharge_limits_best[window_n] = best_soc
self.discharge_window_best[window_n]["start"] = best_start
discharge_windows.append(self.discharge_window_best[window_n])
discharge_socs.append(best_soc)

if self.debug_enable:
self.log(
"Best discharge limit window {} time {} - {} cost {} discharge_limit {} (adjusted) min {} @ {} (margin added {} and min {}) with metric {} cost {}".format(
Expand All @@ -7877,17 +7869,26 @@ def optimise_all_windows(self, load_minutes_step, load_minutes_step10, pv_foreca
)
)

# Log new set of charge and discharge windows
if charge_windows:
# Log set of charge and discharge windows
if self.calculate_best_charge:
self.log(
"Best charge windows in price group {} best_metric {} best_cost {} metric_keep {} windows {}".format(
price, self.dp2(best_metric), self.dp2(best_cost), self.dp2(best_keep), self.window_as_text(charge_windows, charge_socs, ignore_min=True)
price,
self.dp2(best_metric),
self.dp2(best_cost),
self.dp2(best_keep),
self.window_as_text(self.charge_window_best, self.charge_limit_best, ignore_min=True),
)
)
if discharge_windows:

if self.calculate_best_discharge:
self.log(
"Best discharge windows in price group {} best_metric {} best_cost {} metric_keep {} windows {}".format(
price, self.dp2(best_metric), self.dp2(best_cost), self.dp2(best_keep), self.window_as_text(discharge_windows[::-1], discharge_socs[::-1], ignore_max=True)
price,
self.dp2(best_metric),
self.dp2(best_cost),
self.dp2(best_keep),
self.window_as_text(self.discharge_window_best, self.discharge_limits_best, ignore_max=True),
)
)

Expand Down