Skip to content

Commit

Permalink
sunsynk edits
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Apr 4, 2024
1 parent f9e6ceb commit 261f60d
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -1744,24 +1745,26 @@ 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,
end=self.charge_end_datetime,
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,
end=self.charge_end_datetime,
power=self.charge_power,
target_soc=self.charge_target_soc,
)
self.inverter.control_charge(enable=False)

elif (
(time_to_slot_start <= 0)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 261f60d

Please sign in to comment.