Skip to content

Commit 7b3101e

Browse files
committed
Take into account whether the next price minimum has to be rechecked for the calculation of the expected power usage
1 parent d3474ea commit 7b3101e

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

source/inverter_charge_controller.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ def _do_iteration(self, current_energy_rate: EnergyRate) -> EnergyRate:
158158
self.log.info(f"The average power consumption is {average_power_consumption}")
159159

160160
minimum_of_soc_until_next_price_minimum = self._get_minimum_of_soc_until_next_price_minimum(
161-
next_price_minimum.timestamp, average_power_consumption, current_state_of_charge
161+
next_price_minimum.timestamp,
162+
average_power_consumption,
163+
current_state_of_charge,
164+
next_price_minimum.has_to_be_rechecked,
162165
)
163166
self.log.info(
164167
f"The expected minimum of state of charge until the next price minimum with the current state of charge is "
@@ -407,7 +410,11 @@ def _get_average_power_consumption(self) -> Power:
407410
return average_power_consumption
408411

409412
def _get_minimum_of_soc_until_next_price_minimum(
410-
self, next_price_minimum_timestamp: datetime, average_power_consumption: Power, current_soc: StateOfCharge
413+
self,
414+
next_price_minimum_timestamp: datetime,
415+
average_power_consumption: Power,
416+
current_soc: StateOfCharge,
417+
minimum_has_to_rechecked: bool,
411418
) -> StateOfCharge:
412419
cache_key = "minimum_of_soc_until_next_price_minimum"
413420
minimum_of_soc_until_next_price_minimum = self._get_value_from_cache_if_exists(cache_key)
@@ -416,7 +423,11 @@ def _get_minimum_of_soc_until_next_price_minimum(
416423

417424
minimum_of_soc_until_next_price_minimum, _ = (
418425
self.sun_forecast_handler.calculate_minimum_of_soc_and_power_generation_in_timeframe(
419-
TimeHandler.get_time(), next_price_minimum_timestamp, average_power_consumption, current_soc
426+
TimeHandler.get_time(),
427+
next_price_minimum_timestamp,
428+
average_power_consumption,
429+
current_soc,
430+
minimum_has_to_rechecked,
420431
)
421432
)
422433
self._set_cache_key(cache_key, minimum_of_soc_until_next_price_minimum)

source/sun_forecast_handler.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414

1515
class SunForecastHandler(LoggerMixin):
16+
POWER_USAGE_INCREASE_FACTOR = 1.25 # this factor is applied when the next price minimum has to be re-checked
17+
1618
def __init__(self):
1719
super().__init__()
1820

@@ -26,17 +28,20 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
2628
timeframe_end: datetime,
2729
average_power_usage: Power,
2830
starting_soc: StateOfCharge,
31+
minimum_has_to_rechecked: bool = False,
2932
) -> tuple[StateOfCharge, EnergyAmount]:
3033
"""
31-
Calculates the minimum state of charge (SOC) and total power generation within a specified timeframe,
32-
considering average power usage and initial SOC. This function uses solar data and iteratively computes power
33-
usage and generation for subintervals within the timeframe.
34+
Calculates the minimum state of charge (SOC) and total power generation within a specified timeframe.
35+
It considers average power usage, initial SOC and optionally adjusts for higher power usage in cases where the
36+
pricing for the next day is unavailable. This function uses solar data and iteratively computes power usage and
37+
generation for subintervals within the timeframe.
3438
3539
Args:
3640
timeframe_start: The starting timestamp of the timeframe.
3741
timeframe_end: The ending timestamp of the timeframe.
3842
average_power_usage: The average power consumption over the timeframe.
3943
starting_soc: The battery's state of charge at the beginning of the timeframe.
44+
minimum_has_to_rechecked (optional): Whether to increase the power usage by POWER_USAGE_INCREASE_FACTOR
4045
4146
Returns:
4247
A tuple containing:
@@ -47,6 +52,14 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
4752
"Calculating the estimated minimum of state of charge and power generation in the timeframe "
4853
f"{timeframe_start} to {timeframe_end}"
4954
)
55+
power_usage_increase_factor = 1.00
56+
if minimum_has_to_rechecked:
57+
power_usage_increase_factor = SunForecastHandler.POWER_USAGE_INCREASE_FACTOR
58+
self.log.info(
59+
"The upcoming price minimum has to be re-checked since it is at the end of a day and the price rates "
60+
"for tomorrow are unavailable --> The expected power usage is multiplied by "
61+
f"{SunForecastHandler.POWER_USAGE_INCREASE_FACTOR}"
62+
)
5063

5164
solar_data = self.retrieve_solar_data(timeframe_start, timeframe_end)
5265

@@ -70,7 +83,7 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
7083
current_timeframe_end = current_timeframe_start + current_timeframe_duration
7184

7285
power_usage_during_timeframe = self._calculate_energy_usage_in_timeframe(
73-
current_timeframe_start, current_timeframe_duration, average_power_usage
86+
current_timeframe_start, current_timeframe_duration, average_power_usage, power_usage_increase_factor
7487
)
7588
total_power_usage += power_usage_during_timeframe
7689
power_generation_during_timeframe = self._get_energy_produced_in_timeframe_from_solar_data(
@@ -253,7 +266,10 @@ def _need_to_retrieve_data(self, timeframe_start: datetime, timeframe_end: datet
253266

254267
@staticmethod
255268
def _calculate_energy_usage_in_timeframe(
256-
timeframe_start: datetime, timeframe_duration: timedelta, average_power_consumption: Power
269+
timeframe_start: datetime,
270+
timeframe_duration: timedelta,
271+
average_power_consumption: Power,
272+
power_usage_increase_factor: float = 1.00,
257273
) -> EnergyAmount:
258274
"""
259275
Calculates the energy usage within a specific timeframe considering day and night power usage factors.
@@ -282,7 +298,7 @@ def _calculate_energy_usage_in_timeframe(
282298
)
283299

284300
average_power_usage = EnergyAmount.from_watt_seconds(
285-
average_power_consumption.watts * timeframe_duration.total_seconds() * 2
301+
average_power_consumption.watts * timeframe_duration.total_seconds() * power_usage_increase_factor * 2
286302
)
287303
if day_start <= timeframe_start.time() < night_start:
288304
return average_power_usage * factor_energy_usage_during_the_day

0 commit comments

Comments
 (0)