This commit is contained in:
Joshua King
2026-02-16 20:06:03 -05:00
parent ed7deb6cb8
commit f6f2b71851
2 changed files with 86 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ psram:
speed: 80MHz
i2c:
id: i2c_main
sda: 8
scl: 9
@@ -48,6 +49,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
@@ -129,3 +138,73 @@ font:
# Note: On ESP32-S3-Touch-LCD-7, GPIO14 is used by the RGB display bus,
# so it cannot be reused as ADC for battery telemetry in this display mode.
# --- Battery fuel gauge (MAX17043) ---
sensor:
- platform: max17043
id: max17043_battery
i2c_id: i2c_main
update_interval: 30s
battery_voltage:
name: "Remote Battery Voltage"
id: remote_battery_voltage
entity_category: diagnostic
device_class: voltage
state_class: measurement
accuracy_decimals: 3
battery_level:
name: "Remote Battery Level"
id: remote_battery_level
entity_category: diagnostic
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);

View File

@@ -259,6 +259,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_home
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -668,6 +669,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_living_room
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -951,6 +953,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_kitchen
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -1276,6 +1279,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_upstairs
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -1727,6 +1731,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_office
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -2094,6 +2099,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_garage
align: center
text_font: mdi_icons
text_color: 0xC4C6CF
@@ -2503,6 +2509,7 @@ lvgl:
styles: md3_chip
widgets:
- label:
id: nav_battery_icon_outside
align: center
text_font: mdi_icons
text_color: 0xC4C6CF