From 4f6616202dbebdef06083d706afca4045d7a1aad Mon Sep 17 00:00:00 2001 From: JoshuaDodds Date: Sun, 3 Nov 2024 11:01:27 +0100 Subject: [PATCH] [ skip ci ] reduce max state of charge needed in the winter months --- lib/energy_broker.py | 2 -- lib/helpers/__init__.py | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/energy_broker.py b/lib/energy_broker.py index 6af1f98..561e147 100644 --- a/lib/energy_broker.py +++ b/lib/energy_broker.py @@ -27,8 +27,6 @@ def schedule_tasks(): scheduler.every().hour.at(":00").do(manage_sale_of_stored_energy_to_the_grid) # Grid Charging Scheduled Tasks - # scheduler.every().day.at("13:10").do(publish_mqtt_trigger) # when next day prices are published each day - # scheduler.every().day.at("13:30").do(set_charging_schedule, caller="TaskScheduler()", silent=True) scheduler.every().day.at("09:30").do(set_charging_schedule, caller="TaskScheduler()", silent=True) scheduler.every().day.at("00:10").do(set_charging_schedule, caller="TaskScheduler()", silent=True) diff --git a/lib/helpers/__init__.py b/lib/helpers/__init__.py index fdda88a..533e1a0 100644 --- a/lib/helpers/__init__.py +++ b/lib/helpers/__init__.py @@ -129,14 +129,29 @@ def get_seasonally_adjusted_max_charge_slots(batt_soc: float, pv_production_rema to the batt_soc. """ + winter_months = [9, 10, 11, 12, 1, 2, 3] + if pv_production_remaining: - # convert ov_forecasted from kWh to a percentage assuming battery capacity of 40kWh + # convert pv_forecasted from kWh to a percentage assuming battery capacity of 40kWh pv_production_remaining = round((pv_production_remaining / 40) * 100, 2) current_month = datetime.now().month - if current_month in [9, 10, 11, 12, 1, 2, 3]: - return max(0, calculate_max_charge_slots_needed(batt_soc + pv_production_remaining)) + # Set the maximum target state of charge to 75% if in the specified months + if current_month in winter_months: + max_target_soc = 75.0 + else: + max_target_soc = 100.0 + + # Calculate the combined state of charge including PV production + combined_soc = batt_soc + pv_production_remaining + + # Ensure we do not exceed the max target SOC + if combined_soc > max_target_soc: + combined_soc = max_target_soc + + if current_month in winter_months: + return max(0, calculate_max_charge_slots_needed(combined_soc)) return 0