13
13
14
14
15
15
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
+
16
18
def __init__ (self ):
17
19
super ().__init__ ()
18
20
@@ -26,17 +28,20 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
26
28
timeframe_end : datetime ,
27
29
average_power_usage : Power ,
28
30
starting_soc : StateOfCharge ,
31
+ minimum_has_to_rechecked : bool = False ,
29
32
) -> tuple [StateOfCharge , EnergyAmount ]:
30
33
"""
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.
34
38
35
39
Args:
36
40
timeframe_start: The starting timestamp of the timeframe.
37
41
timeframe_end: The ending timestamp of the timeframe.
38
42
average_power_usage: The average power consumption over the timeframe.
39
43
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
40
45
41
46
Returns:
42
47
A tuple containing:
@@ -47,6 +52,14 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
47
52
"Calculating the estimated minimum of state of charge and power generation in the timeframe "
48
53
f"{ timeframe_start } to { timeframe_end } "
49
54
)
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
+ )
50
63
51
64
solar_data = self .retrieve_solar_data (timeframe_start , timeframe_end )
52
65
@@ -70,7 +83,7 @@ def calculate_minimum_of_soc_and_power_generation_in_timeframe(
70
83
current_timeframe_end = current_timeframe_start + current_timeframe_duration
71
84
72
85
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
74
87
)
75
88
total_power_usage += power_usage_during_timeframe
76
89
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
253
266
254
267
@staticmethod
255
268
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 ,
257
273
) -> EnergyAmount :
258
274
"""
259
275
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(
282
298
)
283
299
284
300
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
286
302
)
287
303
if day_start <= timeframe_start .time () < night_start :
288
304
return average_power_usage * factor_energy_usage_during_the_day
0 commit comments