summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/inverter-bot14
-rw-r--r--src/monitor.py11
2 files changed, 13 insertions, 12 deletions
diff --git a/src/inverter-bot b/src/inverter-bot
index cb50b65..7f5e5db 100755
--- a/src/inverter-bot
+++ b/src/inverter-bot
@@ -63,7 +63,7 @@ _strings = {
'chrg_evt_disconnected': 'AC line disconnected.',
'chrg_evt_current_changed': 'AC charging current set to <b>%dA</b>.',
'chrg_evt_na_solar': 'AC line detected, but battery charging is unavailable due to active solar power line.',
- 'battery_state_changed': 'Battery voltage state changed to <b>%s</b> (%0.1f V)'
+ 'battery_level_changed': 'Battery level: <b>%s</b> (<b>%0.1f V</b> under <b>%d W</b> load)'
}
logger = logging.getLogger(__name__)
@@ -395,18 +395,18 @@ def monitor_charging_event_handler(event: ChargingEvent, **kwargs) -> None:
notify_all(_(f'chrg_evt_{key}', *args))
-def monitor_battery_event_handler(state: BatteryState, v: float) -> None:
+def monitor_battery_event_handler(state: BatteryState, v: float, load_watts: int) -> None:
if state == BatteryState.NORMAL:
- label = 'normal'
- elif state == BatteryState.WARNING:
- label = 'warning'
+ label = '✅ Normal'
+ elif state == BatteryState.LOW:
+ label = '⚠️ Low'
elif state == BatteryState.CRITICAL:
- label = 'critical'
+ label = '‼️ Critical'
else:
logger.error('unknown battery state:', state)
return
- notify_all(_('battery_state_changed', label, v))
+ notify_all(_('battery_level_changed', label, v, load_watts))
if __name__ == '__main__':
diff --git a/src/monitor.py b/src/monitor.py
index 6f6d5a4..e87b2f8 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -28,7 +28,7 @@ class ChargingState(Enum):
class BatteryState(Enum):
NORMAL = auto()
- WARNING = auto()
+ LOW = auto()
CRITICAL = auto()
@@ -81,13 +81,14 @@ class InverterMonitor(Thread):
ac = gs['grid_voltage']['value'] > 0 or gs['grid_freq']['value'] > 0
solar = gs['pv1_input_power']['value'] > 0
v = float(gs['battery_voltage']['value'])
+ load_watts = int(gs['ac_output_active_power']['value'])
_logger.debug(f'got status: ac={ac}, solar={solar}, v={v}')
self.ac_charging_program(ac, solar, v)
if not ac:
- self.low_voltage_program(v)
+ self.low_voltage_program(v, load_watts)
elif self.battery_state != BatteryState.NORMAL:
self.battery_state = BatteryState.NORMAL
@@ -181,17 +182,17 @@ class InverterMonitor(Thread):
except InverterError as e:
_logger.exception(e)
- def low_voltage_program(self, v: float):
+ def low_voltage_program(self, v: float, load_watts: int):
if v < 45:
state = BatteryState.CRITICAL
elif v < 47:
- state = BatteryState.WARNING
+ state = BatteryState.LOW
else:
state = BatteryState.NORMAL
if state != self.battery_state:
self.battery_state = state
- self.battery_event_handler(state, v=v)
+ self.battery_event_handler(state, v, load_watts)
def set_charging_event_handler(self, handler: Callable):
self.charging_event_handler = handler