Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Patch2 from main #384

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/black.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Ensure you are on the correct branch
git checkout -B $GITHUB_HEAD_REF || git checkout -b new-branch-name

# Stage and commit changes
git add .
if git diff --cached --quiet; then
echo "No formatting changes to commit."
exit 0
fi
git commit -m "Auto-format code with Black and isort"
git push origin HEAD

# Push changes
git push origin $GITHUB_HEAD_REF



validate-version:
name: Validate Version
Expand Down
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 v4.0.7
# PV Opt: Home Assistant Solar/Battery Optimiser v4.0.8


Solar / Battery Charging Optimisation for Home Assistant. This appDaemon application attempts to optimise charging and discharging of a home solar/battery system to minimise cost electricity cost on a daily basis using freely available solar forecast data from SolCast. This is particularly beneficial for Octopus Agile but is also benefeficial for other time-of-use tariffs such as Octopus Flux or simple Economy 7.
Expand Down
39 changes: 18 additions & 21 deletions apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from numpy import nan


VERSION = "4.0.8-Beta-5"
VERSION = "4.0.8"

UNITS = {
"current": "A",
Expand Down Expand Up @@ -2531,12 +2531,11 @@ def optimise(self):

# end times are start times from one row down (deals with partial first slots)
y["end"] = y["start"]
y["end"] = y["end"].shift(-1)
y["end"] = y["end"].shift(-1)

# Set last end time to be 30 mins greater than last start time.

(y.at[y.index[-1],"end"]) = (y.at[y.index[-1],"start"]) + pd.Timedelta (30, "minutes")
# Set last end time to be 30 mins greater than last start time.

(y.at[y.index[-1], "end"]) = (y.at[y.index[-1], "start"]) + pd.Timedelta(30, "minutes")

# self.log("")
# self.log("Y is........")
Expand Down Expand Up @@ -4287,23 +4286,22 @@ def hass2df(self, entity_id, days=2, log=False, freq=None):

def write_and_poll_time(self, entity_id, time: str | pd.Timestamp, verbose=False):

#self.log("write and poll time entered.")
#var_type = type(time)
#self.log(f"'time' = {time}")
#self.log(f"type of 'time' = {var_type}")
# self.log("write and poll time entered.")
# var_type = type(time)
# self.log(f"'time' = {time}")
# self.log(f"type of 'time' = {var_type}")
changed = False
written = False
if isinstance(time, pd.Timestamp):
time = time.strftime('%X') # HH:MM:SS is needed as get_state_retry returns SS.
#self.log("write and poll time - time detected. Trimming time to hours and minutes")
time = time.strftime("%X") # HH:MM:SS is needed as get_state_retry returns SS.
# self.log("write and poll time - time detected. Trimming time to hours and minutes")
state = self.get_state_retry(entity_id=entity_id)
#self.log(f"Write_and_poll_time: time = {time}, old_time = {state}")

# self.log(f"Write_and_poll_time: time = {time}, old_time = {state}")

if state != time:
changed = True
#self.log(f"Write_and_poll_time: Changed = true")

# self.log(f"Write_and_poll_time: Changed = true")

try:
self.call_service("time/set_value", entity_id=entity_id, time=time)
Expand All @@ -4312,22 +4310,22 @@ def write_and_poll_time(self, entity_id, time: str | pd.Timestamp, verbose=False
retries = 0
while not written and retries < WRITE_POLL_RETRIES:

# SVB debugging
#self.log("Write_and_poll_time: Entered while loop")
# SVB debugging
# self.log("Write_and_poll_time: Entered while loop")

retries += 1
time.sleep(WRITE_POLL_SLEEP)
new_state = self.get_state_retry(entity_id=entity_id)
written = new_state == time

# SVB debugging
#self.log(f"Write_and_poll_time: while loop, new_time = {new_state}")
# self.log(f"Write_and_poll_time: while loop, new_time = {new_state}")

except:
written = False

# commented out, as causes an error (new state not defined) if routine above fails, negating the use of "try/except"
#if verbose:
# if verbose:
# str_log = f"Entity: {entity_id:30s} Time: {time} Old State: {state} "
# str_log += f"New state: {new_state}"
# self.log(str_log)
Expand Down Expand Up @@ -4373,7 +4371,6 @@ def write_and_poll_value(self, entity_id, value: int | float, tolerance=0.0, ver

return (changed, written)


def set_select(self, item, state):
if state is not None:
entity_id = self.config[f"id_{item}"]
Expand Down
4 changes: 2 additions & 2 deletions apps/pv_opt/pvpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def to_df(self, start=None, end=None, **kwargs):
if event_start <= end or event_end > start and event_value > 0:
event_start = max(event_start, start)
event_end = min(event_end - pd.Timedelta(30, "minutes"), end)
df["unit"].loc[event_start:event_end] += event_value
df.loc[event_start:event_end, "unit"] += event_value

return df

Expand Down Expand Up @@ -895,7 +895,7 @@ def optimised_force(

def _search_window(self, df: pd.DataFrame, available: pd.Series, max_slot):
# Need to check why this .iloc[:-1] is here....
x = df.loc[: max_slot - pd.Timedelta("30min")].copy().iloc[:-1]
x = df.loc[: max_slot - pd.Timedelta("30min")].copy()
if len(x) > 0:
x = x[available.loc[: max_slot - pd.Timedelta("30min")]]
x["countback"] = (x["soc_end"] >= 97).sum() - (x["soc_end"] >= 97).cumsum()
Expand Down
Loading