Skip to content

Commit

Permalink
Added future import/export calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarlor committed Feb 15, 2023
1 parent c1a7eb9 commit 9310218
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions custom_components/foxess_em/battery/battery_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def raw_data(self):

def state_at_eco_start(self) -> float:
"""Battery state at start of eco period"""
return round(self._model.state_at_eco_start(), 2)
return round(self._schedule_info()["battery"], 2)

def dawn_charge_needs(self) -> float:
"""Dawn charge needs"""
Expand All @@ -136,7 +136,7 @@ def charge_total(self) -> float:
return self._schedule_info()["total"]

def min_soc(self) -> float:
"""Total kWh required to charge"""
"""Total kWh needed in the battery"""
return self._schedule_info()["min_soc"]

def clear_schedule(self, *args) -> None:
Expand Down
16 changes: 8 additions & 8 deletions custom_components/foxess_em/battery/battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def _charge_totals(
(model["period_start"] > eco_end_time)
& (model["period_start"] < next_eco_start)
]
# metadata - import/export
grid_import = self._model[(self._model["grid"] < 0)].grid.sum()
grid_export = self._model[(self._model["grid"] > 0)].grid.sum()

# sum forecast and house load
forecast_sum = peak.pv_estimate.sum()
load_sum = peak.load.sum()
Expand Down Expand Up @@ -176,17 +180,13 @@ def _charge_totals(
"day": day_charge,
"total": total,
"min_soc": min_soc,
"import": grid_import,
"export": grid_export,
},
)

return total, min_soc

def state_at_eco_start(self) -> float:
"""State at eco end"""
eco_time = self._peak_utils.next_eco_start()
eco_time -= timedelta(minutes=1)
return self._model[self._model["period_start"] == eco_time].battery.iloc[0]

def next_dawn_time(self) -> datetime:
"""Calculate dawn time"""
now = datetime.now().astimezone()
Expand Down Expand Up @@ -336,8 +336,8 @@ def _dawn_time(self, model: pd.DataFrame, date: datetime) -> datetime:

def _dawn_charge_needs(self, dawn_load: float) -> float:
"""Dawn charge needs"""
return round(dawn_load + self._dawn_buffer, 2)
return round(max([0, dawn_load + self._dawn_buffer]), 2)

def _day_charge_needs(self, forecast: float, house_load: float) -> float:
"""Day charge needs"""
return round((house_load + self._day_buffer) - forecast, 2)
return round(max([0, (house_load + self._day_buffer) - forecast]), 2)
6 changes: 3 additions & 3 deletions custom_components/foxess_em/battery/battery_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
icon="mdi:flash",
should_poll=False,
state_attributes={
"Dawn Min SoC:": "dawn_charge_needs",
"Day Min SoC:": "day_charge_needs",
"Min SoC %:": "charge_to_perc",
"Dawn Charge:": "dawn_charge_needs",
"Day Charge:": "day_charge_needs",
"Target SoC %:": "charge_to_perc",
},
),
"next_dawn_time": SensorDescription(
Expand Down
4 changes: 3 additions & 1 deletion custom_components/foxess_em/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async def async_get_events(
summary += f"Start Capacity: {str(round(values['battery'], 2))} / "
summary += f"Forecast: {str(round(values['forecast'], 2))} / "
summary += f"Load: {str(round(values['load'], 2))} / "
summary += f"Min SoC: {str(round(values['min_soc'], 2))}"
summary += f"Min SoC: {str(round(values['min_soc'], 2))} /"
summary += f"Import: {str(round(values['import'], 2))} / "
summary += f"Export: {str(round(values['export'], 2))} / "
calendar_events.append(
CalendarEvent(
key, values["eco_end"], f"FoxESS Charge: {charge}", summary
Expand Down

0 comments on commit 9310218

Please sign in to comment.