Skip to content

Commit

Permalink
Enable forced discharging
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish Findlay committed Oct 3, 2022
1 parent 22730a7 commit c207027
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions custom_components/battery_sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
DISCHARGING_RATE,
GRID_EXPORT_SIM,
GRID_IMPORT_SIM,
ATTR_MONEY_SAVED
ATTR_MONEY_SAVED,
FORCE_DISCHARGE
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -142,12 +143,13 @@ def __init__(
self._last_import_cumulative_reading = 1.0
self._switches = {
OVERIDE_CHARGING: False,
PAUSE_BATTERY: False
PAUSE_BATTERY: False,
FORCE_DISCHARGE: False
}
self._sensors = {
ATTR_ENERGY_SAVED: 0.0,
ATTR_ENERGY_BATTERY_OUT: 0.0,
ATTR_ENERGY_BATTERY_IN: 0.0,
ATTR_ENERGY_BATTERY_IN: 0.0,
CHARGING_RATE: 0.0,
DISCHARGING_RATE: 0.0,
GRID_EXPORT_SIM: 0.0,
Expand Down Expand Up @@ -321,6 +323,15 @@ def updateBattery(self, import_amount, export_amount):
self._charging = True
if self._tariff_sensor_id is not None:
net_money_saved = -1*amount_to_charge*float(self._hass.states.get(self._tariff_sensor_id).state)
elif self._switches[FORCE_DISCHARGE]:
_LOGGER.debug("Battery (%s) forced discharging.", self._name)
amount_to_charge = 0.0
amount_to_discharge = min(max_discharge, available_capacity_to_discharge)
net_export = max(amount_to_discharge - import_amount, 0) + export_amount
net_import = max(import_amount - amount_to_discharge, 0)
self._charging = False
if self._tariff_sensor_id is not None:
net_money_saved = -1*amount_to_charge*float(self._hass.states.get(self._tariff_sensor_id).state)
else:
_LOGGER.debug("Battery (%s) normal mode.", self._name)
amount_to_charge = min(export_amount, max_charge, available_capacity_to_charge)
Expand Down

0 comments on commit c207027

Please sign in to comment.