From ba7474953a2a3d63ab713a6a93f6da6f8de424b1 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sat, 2 Dec 2023 21:38:45 +0000 Subject: [PATCH] Bugfix wrap of charge/discharge window times (#407) * Fix wrap condition on charge & discharge window --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- apps/predbat/predbat.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index f1bf80f6..ec48abb3 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -16,7 +16,7 @@ import appdaemon.plugins.hass.hassapi as hass import adbase as ad -THIS_VERSION = "v7.13.21" +THIS_VERSION = "v7.13.22" TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z" TIME_FORMAT_OCTOPUS = "%Y-%m-%d %H:%M:%S%z" @@ -8041,6 +8041,11 @@ def execute_plan(self): ) minutes_start = inverter.charge_start_time_minutes + # Avoid having too long a period to configure as registers only support 24-hours + if (minutes_start < self.minutes_now) and ((minutes_end - minutes_start) >= 24 * 60): + minutes_start = int(self.minutes_now / 30) * 30 + self.log("Move on charge window start time to avoid wrap - new start {}".format(self.time_abs_str(minutes_start))) + # Check if end is within 24 hours of now and end is in the future if (minutes_end - self.minutes_now) < 24 * 60 and minutes_end > self.minutes_now: charge_start_time = self.midnight_utc + timedelta(minutes=minutes_start) @@ -8127,6 +8132,11 @@ def execute_plan(self): ) minutes_start = inverter.discharge_start_time_minutes + # Avoid having too long a period to configure as registers only support 24-hours + if (minutes_start < self.minutes_now) and ((minutes_end - minutes_start) >= 24 * 60): + minutes_start = int(self.minutes_now / 30) * 30 + self.log("Move on discharge window start time to avoid wrap - new start {}".format(self.time_abs_str(minutes_start))) + discharge_start_time = self.midnight_utc + timedelta(minutes=minutes_start) discharge_end_time = self.midnight_utc + timedelta(minutes=(minutes_end + 1)) # Add in 1 minute margin to allow Predbat to restore ECO mode discharge_soc = (self.discharge_limits_best[0] * self.soc_max) / 100.0