From 261f60d485e49b8333a1aad761158e3d6862ab22 Mon Sep 17 00:00:00 2001 From: fboundy Date: Thu, 4 Apr 2024 19:15:42 +0100 Subject: [PATCH] sunsynk edits --- apps/pv_opt/pv_opt.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/apps/pv_opt/pv_opt.py b/apps/pv_opt/pv_opt.py index dca0592..e3c5025 100644 --- a/apps/pv_opt/pv_opt.py +++ b/apps/pv_opt/pv_opt.py @@ -1296,6 +1296,7 @@ def _expose_configs(self, over_write=True): for item in DEFAULT_CONFIG if (item not in [self.change_items[entity] for entity in self.change_items]) and ("id_" not in item) + and ("json_" not in item) and ("alt_" not in item) and ("auto" not in item) and "domain" in DEFAULT_CONFIG[item] @@ -1744,6 +1745,8 @@ def optimise(self): self.log("No charge/discharge windows planned.") if self.charge_power > 0: + self.inverter.control_discharge(enable=False) + self.inverter.control_charge( enable=True, start=self.charge_start_datetime, @@ -1751,9 +1754,10 @@ def optimise(self): power=self.charge_power, target_soc=self.charge_target_soc, ) - self.inverter.control_discharge(enable=False) elif self.charge_power < 0: + self.inverter.control_charge(enable=False) + self.inverter.control_discharge( enable=True, start=self.charge_start_datetime, @@ -1761,7 +1765,6 @@ def optimise(self): power=self.charge_power, target_soc=self.charge_target_soc, ) - self.inverter.control_charge(enable=False) elif ( (time_to_slot_start <= 0) @@ -1793,6 +1796,11 @@ def optimise(self): else: start = None + if status["discharge"]["active"]: + self.inverter.control_discharge( + enable=False, + ) + self.inverter.control_charge( enable=True, start=start, @@ -1801,17 +1809,17 @@ def optimise(self): target_soc=self.charge_target_soc, ) - if status["discharge"]["active"]: - self.inverter.control_discharge( - enable=False, - ) - elif self.charge_power < 0: if not status["discharge"]["active"]: start = pd.Timestamp.now(tz=self.tz) else: start = None + if status["charge"]["active"]: + self.inverter.control_charge( + enable=False, + ) + self.inverter.control_discharge( enable=True, start=start, @@ -1820,11 +1828,6 @@ def optimise(self): target_soc=self.charge_target_soc, ) - if status["charge"]["active"]: - self.inverter.control_charge( - enable=False, - ) - else: if self.charge_power > 0: direction = "charge" @@ -1850,6 +1853,7 @@ def optimise(self): self.log(str_log) self.inverter.control_charge(enable=False) did_something = True + elif status["charge"]["start"] != status["charge"]["end"]: str_log += " but charge start and end times are different." self.log(str_log) @@ -1861,6 +1865,7 @@ def optimise(self): self.log(str_log) self.inverter.control_discharge(enable=False) did_something = True + elif status["discharge"]["start"] != status["discharge"]["end"]: str_log += " but charge start and end times are different." self.log(str_log) @@ -1901,9 +1906,9 @@ def optimise(self): if did_something: if self.get_config("update_cycle_seconds") is not None: i = int(self.get_config("update_cycle_seconds") * 1.2) - self.log(f"Waiting for Modbus Read cycle: {i} seconds") + self.log(f"Waiting for inverter Read cycle: {i} seconds") while i > 0: - self._status(f"Waiting for Modbus Read cycle: {i}") + self._status(f"Waiting for inverter Read cycle: {i}") time.sleep(1) i -= 1 @@ -2639,10 +2644,10 @@ def _list_entities(self, domains=["select", "number", "sensor"]): x = " - " for attribute in DOMAIN_ATTRIBUTES[domain]: x = f"{x} {attribute}: {states[entity_id]['attributes'][attribute]} " - self.log(x) + self.rlog(x) elif domain == "select": for option in states[entity_id]["attributes"]["options"]: - self.log(f"{option:>83s}") + self.rlog(f"{option:>83s}") self.log("") def hass2df(self, entity_id, days=2, log=False, freq=None):