Skip to content

Commit

Permalink
Merge pull request #320 from fboundy/patch2
Browse files Browse the repository at this point in the history
Improve Optimiser Efficiency
  • Loading branch information
fboundy authored Dec 13, 2024
2 parents f6b95f5 + 3b9bc46 commit d06d818
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PV Opt: Home Assistant Solar/Battery Optimiser v3.18.4
# PV Opt: Home Assistant Solar/Battery Optimiser v3.18.5

<h2>This documentation needs updating!</h2>

Expand Down
2 changes: 1 addition & 1 deletion apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from numpy import nan
import re

VERSION = "3.18.4"
VERSION = "3.18.5"


OCTOPUS_PRODUCT_URL = r"https://api.octopus.energy/v1/products/"
Expand Down
42 changes: 13 additions & 29 deletions apps/pv_opt/pvpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,32 +718,6 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg

slots = []

# if self.host.agile:
# --------------------------------------------------------------------------------------------
# Plunge Pricing
# --------------------------------------------------------------------------------------------
# if log:
# self.log("")
# self.log("Agile Plunge Pricing")
# self.log("--------------------")
# self.log("")
# # self.log((f">>>{static_flows.columns}"))

# plunge_threshold = self.host.get_config("plunge_threshold_p_kwh")
# plunge = (self.inverter.charger_power - static_flows[kwargs["solar"]])[df["import"] < plunge_threshold]
# if log:
# self.log(f">>>{plunge.to_string()}")

# slots = [(p, max(plunge.loc[p], 0)) for p in plunge.index.to_list()]
# df = pd.concat(
# [prices, consumption, self.flows(initial_soc, static_flows, slots=slots, **kwargs)],
# axis=1,
# )
# plunge_cost = round(contract.net_cost(df).sum(), 1)
# if log:
# self.log(f"Plunge cost: {plunge_cost}")
# base_cost = plunge_cost

# --------------------------------------------------------------------------------------------
# Charging 1st Pass
# --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -794,6 +768,7 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg

# potential windows end at the max_slot
x = df.loc[:max_slot].copy()
x = x[available.loc[:max_slot]]

# count back to find the slots where soc_end < 100
x["countback"] = (x["soc_end"] >= 97).sum() - (x["soc_end"] >= 97).cumsum()
Expand All @@ -806,7 +781,7 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg
x = x[x["soc_end"] <= 97]

search_window = x.index
str_log = f"{max_slot.tz_convert(self.tz).strftime(TIME_FORMAT)}: {round_trip_energy_required:5.2f} kWh at {max_import_cost:6.2f}p. "
str_log = f"{i:3d} {available.sum():3d} {max_slot.tz_convert(self.tz).strftime(TIME_FORMAT)}: {round_trip_energy_required:5.2f} kWh at {max_import_cost:6.2f}p. "
if len(search_window) > 0:
# str_log += f"Window: [{search_window[0].strftime(TIME_FORMAT)}-{search_window[-1].strftime(TIME_FORMAT)}] "
pass
Expand Down Expand Up @@ -852,13 +827,22 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg
min_power = min(
slot_power_required, slot_charger_power_available, slot_available_capacity
)
remaining_slot_capacity = slot_charger_power_available - min_power

if remaining_slot_capacity < 10:
available[slot] = False

if log and self.host.debug:
str_log_x = (
f">>> Slot: {slot.strftime(TIME_FORMAT)} Factor: {factor:0.3f} Forced: {x['forced'].loc[slot]:6.0f}W "
f">>> {i:3d} Slot: {slot.strftime(TIME_FORMAT)} Factor: {factor:0.3f} Forced: {x['forced'].loc[slot]:6.0f}W "
+ f"End SOC: {x['soc_end'].loc[slot]:4.1f}% SPR: {slot_power_required:6.0f}W "
+ f"SCPA: {slot_charger_power_available:6.0f}W SAC: {slot_available_capacity:6.0f}W Min Power: {min_power:6.0f}W"
+ f"SCPA: {slot_charger_power_available:6.0f}W SAC: {slot_available_capacity:6.0f}W Min Power: {min_power:6.0f}W "
+ f"RSC: {remaining_slot_capacity:6.0f}W"
)
if not available[slot]:
str_log_x += " <== FULL"
self.log(str_log_x)

slots.append(
(
slot,
Expand Down

0 comments on commit d06d818

Please sign in to comment.