Skip to content

Commit

Permalink
Clipping fixes (#1166)
Browse files Browse the repository at this point in the history
* Clipping fixes

Over calculated load and pv divergence, tweaked down

#1152

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

---------

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 Jun 2, 2024
1 parent c9f770a commit b132f7e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg
battery_draw = max(-charge_rate_now_curve * step, battery_draw - above_limit)

# Account for inverter limit, clip battery draw if possible to avoid going over
diff_tmp = load_yesterday - (battery_draw + pv_dc + pv_ac)
if self.inverter_hybrid and diff_tmp < 0 and abs(diff_tmp) > (self.inverter_limit * step):
above_limit = abs(diff_tmp + self.inverter_limit * step)
battery_draw = max(-charge_rate_now_curve * step, battery_draw - above_limit)
Expand All @@ -1888,7 +1889,10 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg
pv_ac -= extra_pv
pv_dc += extra_pv

battery_state = "f-"
if battery_draw < 0:
battery_state = "f/"
else:
battery_state = "f-"

# Once force discharge starts the four hour rule is disabled
four_hour_rule = False
Expand Down Expand Up @@ -6175,7 +6179,7 @@ def get_load_divergence(self, minutes_now, load_minutes):
load_count = 0
load_min = 99999
load_max = 0
look_over = 60 * 4
look_over = 60 * 8

for minute in range(0, look_over, PREDICT_STEP):
load, load_raw = self.get_filtered_load_minute(load_minutes, minute, historical=True, step=PREDICT_STEP)
Expand All @@ -6195,8 +6199,8 @@ def get_load_divergence(self, minutes_now, load_minutes):
load_diff_total += load_diff

load_std_dev = math.sqrt(load_diff_total / load_count)
load_divergence = load_std_dev / load_mean
load_divergence = min(load_divergence, 2.0)
load_divergence = load_std_dev / load_mean / 2.0
load_divergence = min(load_divergence, 1.0)
self.log(
"Load divergence over {} hours mean {} W, min {} W, max {} W, std dev {} W, divergence {}%".format(
look_over / 60.0, self.dp2(load_mean), self.dp2(load_min), self.dp2(load_max), self.dp2(load_std_dev), self.dp2(load_divergence * 100.0)
Expand All @@ -6220,7 +6224,7 @@ def get_cloud_factor(self, minutes_now, pv_data, pv_data10):
pv_factor = None
if pv_total > 0 and (pv_total > pv_total10):
pv_diff = pv_total - pv_total10
pv_factor = self.dp2(pv_diff / pv_total)
pv_factor = self.dp2(pv_diff / pv_total) / 2.0
pv_factor = min(pv_factor, 1.0)

if self.metric_cloud_enable:
Expand Down

0 comments on commit b132f7e

Please sign in to comment.