diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/inverter-bot | 3 | ||||
-rw-r--r-- | src/monitor.py | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/inverter-bot b/src/inverter-bot index 6cbb645..defc712 100755 --- a/src/inverter-bot +++ b/src/inverter-bot @@ -62,6 +62,7 @@ _strings = { 'chrg_evt_current_changed': 'ℹ️ AC charging current set to %d A.', 'chrg_evt_not_charging': 'ℹ️ AC connected but not charging.', 'chrg_evt_na_solar': '⛔️AC connected, but battery won\'t be charged due to active solar power line.', + 'chrg_evt_mostly_charged': '✅ The battery is mostly charged now. The generator can be turned off.', 'battery_level_changed': 'Battery level: <b>%s</b> (<b>%0.1f V</b> under <b>%d W</b> load)', 'error_message': '<b>Error:</b> %s.' } @@ -392,6 +393,8 @@ def monitor_charging_event_handler(event: ChargingEvent, **kwargs) -> None: args.append(kwargs['current']) elif event == ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR: key = 'na_solar' + elif event == ChargingEvent.AC_MOSTLY_CHARGED: + key = 'mostly_charged' else: logger.error('unknown charging event:', event) return diff --git a/src/monitor.py b/src/monitor.py index 398d76b..5fc2391 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -22,6 +22,7 @@ class ChargingEvent(Enum): AC_CHARGING_STARTED = auto() AC_DISCONNECTED = auto() AC_CURRENT_CHANGED = auto() + AC_MOSTLY_CHARGED = auto() AC_CHARGING_FINISHED = auto() @@ -65,6 +66,7 @@ class InverterMonitor(Thread): interrupted: bool battery_state: BatteryState charging_state: ChargingState + mostly_charged: bool def __init__(self, ac_current_range: Union[List, Tuple] = ()): super().__init__() @@ -86,6 +88,7 @@ class InverterMonitor(Thread): self.active_current = None self.battery_state = BatteryState.NORMAL self.charging_state = ChargingState.NOT_CHARGING + self.mostly_charged = False # other stuff self.interrupted = False @@ -163,6 +166,10 @@ class InverterMonitor(Thread): self.charging_event_handler(ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR) _logger.info('solar power connected during charging, entering AC_BUT_SOLAR state') + if self.mostly_charged and v > 53 and pd != BatteryPowerDirection.CHARGING: + self.ac_charging_stop(ChargingState.AC_DONE) + return + state = ChargingState.AC_OK if pd == BatteryPowerDirection.CHARGING else ChargingState.AC_WAITING if state != self.charging_state: self.charging_state = state @@ -175,7 +182,7 @@ class InverterMonitor(Thread): if self.active_current >= 30: upper_bound = 56.9 elif self.active_current == 20: - upper_bound = 56.6 + upper_bound = 56.7 else: upper_bound = 54 @@ -220,6 +227,7 @@ class InverterMonitor(Thread): if self.currents: self.currents = [] + self.mostly_charged = False self.active_current = None def ac_charging_next_current(self): @@ -232,6 +240,10 @@ class InverterMonitor(Thread): self.ac_charging_stop(ChargingState.AC_DONE) return + if current <= 10 and not self.mostly_charged: + self.mostly_charged = True + self.charging_event_handler(ChargingEvent.AC_MOSTLY_CHARGED) + try: response = inverter.exec('set-max-ac-charging-current', (0, current)) if response['result'] != 'ok': |