Skip to content

Commit

Permalink
Tweaks for inverter limits/clipping (#1078)
Browse files Browse the repository at this point in the history
* Tweaks for inverter limits/clipping

* [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 May 11, 2024
1 parent 8ea3157 commit cb17998
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,9 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg
battery_draw = 0
charge_rate_now_curve = get_charge_rate_curve(self, soc, charge_rate_now)
discharge_rate_now_curve = get_discharge_rate_curve(self, soc, discharge_rate_now)
battery_to_min = max(soc - self.reserve, 0) * self.battery_loss_discharge * self.inverter_loss
battery_to_max = max(self.soc_max - soc, 0) * self.battery_loss * self.inverter_loss

if (
not self.set_discharge_freeze_only
and (discharge_window_n >= 0)
Expand All @@ -1835,16 +1838,19 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg

# It's assumed if SOC hits the expected reserve then it's terminated
reserve_expected = max((self.soc_max * discharge_limits[discharge_window_n]) / 100.0, self.reserve)
battery_draw = discharge_rate_now_curve * step
if (soc - reserve_expected) < battery_draw:
battery_draw = max(soc - reserve_expected, 0)
battery_draw = min(discharge_rate_now_curve * step, battery_to_min)

# Account for export limit, clip battery draw if possible to avoid going over
diff_tmp = load_yesterday - (battery_draw + pv_dc + pv_ac)
if diff_tmp < 0 and abs(diff_tmp) > (self.export_limit * step):
above_limit = abs(diff_tmp + self.export_limit * step)
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
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)

# If the battery is charging then solar will be used to charge as a priority
# So move more of the PV into PV DC
if battery_draw < 0 and pv_dc < abs(battery_draw):
Expand Down Expand Up @@ -1884,32 +1890,32 @@ def run_prediction(self, charge_limit, charge_window, discharge_window, discharg

# Remove inverter loss as it will be added back in again when calculating the SOC change
charge_rate_now_curve /= self.inverter_loss
battery_draw = -max(min(charge_rate_now_curve * step, charge_limit_n - soc), 0)
battery_draw = -max(min(charge_rate_now_curve * step, charge_limit_n - soc), 0, -battery_to_max)
battery_state = "f+"
first_charge = min(first_charge, minute)
else:
# ECO Mode
if load_yesterday - pv_ac - pv_dc > 0:
battery_draw = min(load_yesterday - pv_ac - pv_dc, discharge_rate_now_curve * step, self.inverter_limit * step - pv_ac)
battery_draw = min(load_yesterday - pv_ac - pv_dc, discharge_rate_now_curve * step, self.inverter_limit * step - pv_ac, battery_to_min)
battery_state = "e-"
else:
battery_draw = max(load_yesterday - pv_ac - pv_dc, -charge_rate_now_curve * step)
battery_draw = max(load_yesterday - pv_ac - pv_dc, -charge_rate_now_curve * step, -battery_to_max)
if battery_draw < 0:
battery_state = "e+"
else:
battery_state = "e~"

# Account for inverter limit, clip battery draw if possible to avoid going over
if self.inverter_hybrid:
total_inverted = pv_ac + pv_dc + battery_draw
total_inverted = pv_ac + max(pv_dc + battery_draw, 0)
else:
total_inverted = pv_ac + pv_dc + abs(battery_draw)

if total_inverted > self.inverter_limit * step:
reduce_by = total_inverted - (self.inverter_limit * step)
if battery_draw < 0:
pv_ac -= reduce_by
if pv_ac < 0:
if not self.inverter_hybrid and pv_ac < 0:
pv_dc = max(pv_dc + pv_ac, 0)
pv_ac = 0
else:
Expand Down

0 comments on commit cb17998

Please sign in to comment.