Skip to content

Commit 44b0324

Browse files
Fixes to charging window calculation to account for being in the window
1 parent a3e8c9a commit 44b0324

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

apps.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pred_bat:
4545
pv_scaling: 1.0
4646

4747
# Weighting given to the 10% PV scenario, comment out or put to 0.0 to disable this
48-
# A value of 0.2 assumes that 1:5 times we get the 10% scenario and hence to count this in the metric benefit/cost
49-
pv_metric10_weight: 0.2
48+
# A value of 0.1 assumes that 1:10 times we get the 10% scenario and hence to count this in the metric benefit/cost
49+
pv_metric10_weight: 0.1
5050

5151
# Number of hours forward to forecast
5252
forecast_hours: 48
@@ -69,7 +69,8 @@ pred_bat:
6969

7070
# Metric min improvement sets the minimum cost improvement that it's worth lowering the battery SOC % for
7171
# If it's 0 then this is disabled. I use around 5p as it's not worth trying to save less than that and risk a flat battery if the forecast is wrong
72-
metric_min_improvement: 2
72+
# If you use pv_metric10_weight then you probably don't need to enable this as the 10% forecast does the same thing better
73+
metric_min_improvement: 0
7374

7475
# Energy rates
7576
# Please set one of these three, if multiple are set then Octopus is used first, second rates_import/rates_export and latestly basic metric
@@ -117,7 +118,7 @@ pred_bat:
117118

118119
# When enabled the next charge window will be automatically configured based on the incoming rates
119120
# Only works if the charging time window has been enabled and import rates are configured with the rates_import or using Octopus import
120-
# Set window minutes defines how many minutes before the charge window we should program it
121+
# Set window minutes defines how many minutes before the charge window we should program it (do not set above 30 if you are using Agile or similar)
121122
set_charge_window: True
122123
set_window_notify: True
123124
set_window_minutes: 30

predbat.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def optimise_charge_limit(self, window_n, record_charge_windows, charge_window,
878878
metric += metric_diff
879879

880880
self.debug_enable = was_debug
881-
if self.debug_enable:
881+
if self.debug_enable or 1:
882882
self.log("Tried soc {} for window {} gives import battery {} house {} export {} min_soc {} cost {} metric {} metricmid {} metric10 {}".format
883883
(try_soc, window_n, self.dp2(import_kwh_battery), self.dp2(import_kwh_house), self.dp2(export_kwh), self.dp2(soc_min), self.dp2(cost), self.dp2(metric), self.dp2(metricmid), self.dp2(metric10)))
884884

@@ -1021,15 +1021,21 @@ def update_pred(self):
10211021
charge_start_time = datetime.strptime(self.get_state(self.args['charge_start_time']), "%H:%M:%S")
10221022
charge_end_time = datetime.strptime(self.get_state(self.args['charge_end_time']), "%H:%M:%S")
10231023

1024+
10241025
# Compute charge window minutes start/end just for the next charge window
10251026
self.charge_start_time_minutes = charge_start_time.hour * 60 + charge_start_time.minute
10261027
self.charge_end_time_minutes = charge_end_time.hour * 60 + charge_end_time.minute
1028+
10271029
if self.charge_end_time_minutes < self.charge_start_time_minutes:
1028-
self.charge_end_time_minutes += 60 * 24
1030+
# As windows wrap, if end is in the future then move start back, otherwise forward
1031+
if self.charge_end_time_minutes > self.minutes_now:
1032+
self.charge_start_time_minutes -= 60 * 24
1033+
else:
1034+
self.charge_end_time_minutes += 60 * 24
10291035

10301036
# Construct charge window from the GivTCP settings
10311037
self.charge_window = []
1032-
minute = self.charge_start_time_minutes
1038+
minute = max(0, self.charge_start_time_minutes) # Max is here is start could be before midnight now
10331039
minute_end = self.charge_end_time_minutes
10341040

10351041
while minute < self.forecast_minutes:

0 commit comments

Comments
 (0)