Skip to content

Commit

Permalink
Charge hold and multi inverter with reserve limit issue (#1811)
Browse files Browse the repository at this point in the history
* Charge hold and multi inverter with reserve limit issue

* [pre-commit.ci lite] apply automatic fixes

* Bump version

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Dec 28, 2024
1 parent 33c848b commit de66c1c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
5 changes: 4 additions & 1 deletion apps/predbat/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def execute_plan(self):
if check.soc_kw < inverter.reserve:
can_freeze_charge = False
break
if not check.inv_has_timed_pause and (check.reserve_max < check.soc_percent):
can_freeze_charge = False
break
if (self.charge_limit_best[0] == self.reserve) and self.soc_kw >= self.reserve and can_freeze_charge:
if self.set_soc_enable and ((self.set_reserve_enable and self.set_reserve_hold and inverter.reserve_max >= inverter.soc_percent) or inverter.inv_has_timed_pause):
inverter.disable_charge_window()
Expand Down Expand Up @@ -166,7 +169,7 @@ def execute_plan(self):
if check.soc_percent < self.charge_limit_percent_best[0]:
can_hold_charge = False
break
if not check.inv_has_timed_pause and check.reserve_max < check.soc_percent:
if not check.inv_has_timed_pause and (check.reserve_max < check.soc_percent):
can_hold_charge = False
break
if self.set_soc_enable and can_hold_charge and self.soc_percent >= self.charge_limit_percent_best[0]:
Expand Down
2 changes: 1 addition & 1 deletion apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import asyncio
import json

THIS_VERSION = "v8.8.17"
THIS_VERSION = "v8.8.18"

# fmt: off
PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "gecloud.py","utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "predheat.py", "futurerate.py", "octopus.py", "solcast.py","execute.py", "plan.py", "fetch.py", "output.py", "userinterface.py"]
Expand Down
58 changes: 50 additions & 8 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ def run_execute_test(
update_plan=False,
reserve=1,
soc_kw_array=None,
reserve_max=100,
):
print("Run scenario {}".format(name))
failed = False
Expand Down Expand Up @@ -1735,6 +1736,7 @@ def run_execute_test(
inverter.reserve_current = reserve_percent
inverter.reserve_percent_current = reserve_percent
inverter.reserve = reserve_kwh
inverter.reserve_max = reserve_max

my_predbat.fetch_inverter_data(create=False)

Expand Down Expand Up @@ -1929,14 +1931,15 @@ def run_single_debug(test_name, my_predbat, debug_file, expected_file=None):
)

# 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))
if not expected_file:
for item in my_predbat.CONFIG_ITEMS:
name = item["name"]
value = item.get("value", None)
default = item.get("default", None)
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
Expand Down Expand Up @@ -2544,6 +2547,45 @@ def run_execute_tests(my_predbat):
if failed:
return failed

failed |= run_execute_test(
my_predbat,
"charge_hold_reserve_max1",
charge_window_best=charge_window_best,
charge_limit_best=charge_limit_best2,
assert_charge_time_enable=True,
set_charge_window=True,
set_export_window=True,
assert_status="Charging",
soc_kw=9,
assert_charge_start_time_minutes=-1,
assert_charge_end_time_minutes=my_predbat.minutes_now + 60,
assert_discharge_rate=1000,
assert_pause_discharge=False,
assert_soc_target=50,
reserve_max=50,
has_timed_pause=False,
)
failed |= run_execute_test(
my_predbat,
"charge_hold_reserve_max2",
charge_window_best=charge_window_best,
charge_limit_best=charge_limit_best2,
assert_charge_time_enable=True,
set_charge_window=True,
set_export_window=True,
assert_status="Charging",
soc_kw=9,
assert_charge_start_time_minutes=-1,
assert_charge_end_time_minutes=my_predbat.minutes_now + 60,
assert_discharge_rate=1000,
assert_pause_discharge=False,
assert_soc_target_array=[60, 40],
assert_immediate_soc_target=50,
reserve_max=90,
has_timed_pause=False,
soc_kw_array=[5, 4],
)

# Charge/discharge with rate
for inverter in my_predbat.inverters:
inverter.inv_charge_discharge_with_rate = True
Expand Down

0 comments on commit de66c1c

Please sign in to comment.