Skip to content

Commit

Permalink
Forecast plan hours default should be 24 hours, but was 48 due to bug (
Browse files Browse the repository at this point in the history
…#1810)

* Minor fixes

* Fixes

* Fix bug

* Update config.py
  • Loading branch information
springfall2008 authored Dec 28, 2024
1 parent 94e44cd commit 33c848b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/predbat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@
"max": 40,
"step": 0.1,
"unit": "c",
"default": 20,
"enable": "predheat_enable",
},
]
Expand Down
2 changes: 1 addition & 1 deletion apps/predbat/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ def fetch_config_options(self):

self.forecast_days = int((forecast_hours + 23) / 24)
self.forecast_minutes = forecast_hours * 60
self.forecast_plan_hours = max(min(self.get_arg("forecast_plan_hours", 96), forecast_hours), 8)
self.forecast_plan_hours = max(min(self.get_arg("forecast_plan_hours"), forecast_hours), 8)
self.inverter_clock_skew_start = self.get_arg("inverter_clock_skew_start", 0)
self.inverter_clock_skew_end = self.get_arg("inverter_clock_skew_end", 0)
self.inverter_clock_skew_discharge_start = self.get_arg("inverter_clock_skew_discharge_start", 0)
Expand Down
2 changes: 1 addition & 1 deletion apps/predbat/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def record_length(self, charge_window, charge_limit, best_price):
if end_record < self.minutes_now:
end_record = charge_window[max_windows]["end"]

self.log("Calculated end_record as {}".format(self.time_abs_str(end_record)))
self.log("Calculated end_record as {} based on best_price {} next_charge_start {} max_windows {}".format(self.time_abs_str(end_record), best_price, self.time_abs_str(next_charge_start), max_windows))
return end_record - self.minutes_now

def max_charge_windows(self, end_record_abs, charge_window):
Expand Down
22 changes: 20 additions & 2 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,12 @@ def run_execute_test(

def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
print("**** Running debug test {} ****\n".format(debug_file))
re_do_rates = False
reset_load_model = False
if not expected_file:
re_do_rates = True
reset_load_model = True
else:
reset_load_model = False
re_do_rates = False
load_override = 1.0
my_predbat.load_user_config()
failed = False
Expand Down Expand Up @@ -1923,6 +1927,17 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
metric, import_kwh_battery, import_kwh_house, export_kwh, soc_min, soc, soc_min_minute, battery_cycle, metric_keep, final_iboost, final_carbon_g = my_predbat.run_prediction(
my_predbat.charge_limit_best, my_predbat.charge_window_best, my_predbat.export_window_best, my_predbat.export_limits_best, False, end_record=my_predbat.end_record, save="best"
)

# Show setting changes
for item in my_predbat.CONFIG_ITEMS:
name = item["name"]
value = item["value"]
default = item["default"]
enable = item.get("enable", None)
enabled = my_predbat.user_config_item_enabled(item)
if enabled and value != default:
print("- {} = {} (default {}) - enable {}".format(name, value, default, enable))

# Save plan
# Pre-optimise all plan
my_predbat.charge_limit_percent_best = calc_percent_limit(my_predbat.charge_limit_best, my_predbat.soc_max)
Expand Down Expand Up @@ -1965,6 +1980,9 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
filename = test_name + ".actual.json"
open(filename, "w").write(actual_json)
print("Wrote plan json to {}".format(filename))

my_predbat.create_debug_yaml(write_file=True)

return failed


Expand Down

0 comments on commit 33c848b

Please sign in to comment.