From d6ddd4478726d0d3a899652e677ed44702c899e4 Mon Sep 17 00:00:00 2001 From: Joshua King Date: Tue, 17 Feb 2026 07:07:34 -0500 Subject: [PATCH] battery logic update --- esphome/ha-remote-1.yaml | 2 +- esphome/ha-remote/ha-remote-1.base.yaml | 59 ++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/esphome/ha-remote-1.yaml b/esphome/ha-remote-1.yaml index 09db3dc..406471d 100644 --- a/esphome/ha-remote-1.yaml +++ b/esphome/ha-remote-1.yaml @@ -19,7 +19,7 @@ esp32: type: esp-idf logger: - level: INFO + level: WARN api: encryption: diff --git a/esphome/ha-remote/ha-remote-1.base.yaml b/esphome/ha-remote/ha-remote-1.base.yaml index 2e9c2d6..925e1fa 100644 --- a/esphome/ha-remote/ha-remote-1.base.yaml +++ b/esphome/ha-remote/ha-remote-1.base.yaml @@ -7,7 +7,6 @@ i2c: sda: 8 scl: 9 frequency: 100kHz - scan: true # CH422G I/O expander (Waveshare uses it for LCD reset/backlight/touch reset) ch422g: @@ -51,6 +50,14 @@ globals: type: uint32_t restore_value: no initial_value: '0' + - id: last_battery_level_pct + type: float + restore_value: no + initial_value: '-1.0' + - id: battery_charging_inferred + type: bool + restore_value: no + initial_value: 'false' interval: - interval: 1s @@ -152,3 +159,53 @@ sensor: device_class: battery state_class: measurement accuracy_decimals: 0 + on_value: + then: + - lambda: |- + const float pct = x; + const bool valid = pct >= 0.0f && pct <= 100.0f; + + // Infer charging from SOC trend when no dedicated charge-detect pin exists. + if (valid) { + if (id(last_battery_level_pct) >= 0.0f) { + if (pct > id(last_battery_level_pct) + 0.2f) { + id(battery_charging_inferred) = true; + } else if (pct < id(last_battery_level_pct) - 0.2f) { + id(battery_charging_inferred) = false; + } + } + id(last_battery_level_pct) = pct; + } + + const char *icon = "\U000F0091"; // mdi:battery-unknown + if (!valid) { + icon = "\U000F0091"; // mdi:battery-unknown + } else if (pct >= 99.0f) { + icon = "\U000F0079"; // mdi:battery (full) + } else if (id(battery_charging_inferred)) { + if (pct < 40.0f) { + icon = "\U000F12A4"; // mdi:battery-charging-low + } else if (pct < 80.0f) { + icon = "\U000F12A5"; // mdi:battery-charging-medium + } else { + icon = "\U000F12A6"; // mdi:battery-charging-high + } + } else { + if (pct < 15.0f) { + icon = "\U000F10CD"; // mdi:battery-alert-variant-outline + } else if (pct < 40.0f) { + icon = "\U000F12A1"; // mdi:battery-low + } else if (pct < 80.0f) { + icon = "\U000F12A2"; // mdi:battery-medium + } else { + icon = "\U000F12A3"; // mdi:battery-high + } + } + + lv_label_set_text(id(nav_battery_icon_home), icon); + lv_label_set_text(id(nav_battery_icon_living_room), icon); + lv_label_set_text(id(nav_battery_icon_kitchen), icon); + lv_label_set_text(id(nav_battery_icon_upstairs), icon); + lv_label_set_text(id(nav_battery_icon_office), icon); + lv_label_set_text(id(nav_battery_icon_garage), icon); + lv_label_set_text(id(nav_battery_icon_outside), icon);