From 0f1a6d187870a481854bc29be4b1a6d52e7c9334 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Fri, 6 Nov 2026 09:56:51 +0100 Subject: [PATCH] Freeze display time during partial-buffer updates --- esphome/energymonitor.yaml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/esphome/energymonitor.yaml b/esphome/energymonitor.yaml index c8539ad..6a3a676 100644 --- a/esphome/energymonitor.yaml +++ b/esphome/energymonitor.yaml @@ -142,6 +142,10 @@ font: - "\U000F092D" # mdi:wifi-strength-off globals: + - id: display_time + type: esphome::ESPTime + restore_value: false + initial_value: 'esphome::ESPTime{}' - id: page_index type: int restore_value: true @@ -313,6 +317,9 @@ sensor: name: 'WireGuard Latest Handshake' interval: + - interval: 1s + then: + - script.execute: refresh_display - interval: 10s then: - lambda: |- @@ -330,10 +337,15 @@ interval: if (id(internet_history_count) < 361) id(internet_history_count)++; script: + - id: refresh_display + then: + # The partial-buffer driver draws multiple strips; freeze time for the entire frame. + - lambda: id(display_time) = id(sntp_time).now(); + - component.update: tft - id: show_previous_page then: - lambda: id(page_index) = (id(page_index) + 4 - 1) % 4; - - component.update: tft + - script.execute: refresh_display - id: toggle_page_mode then: - lambda: |- @@ -346,11 +358,11 @@ script: } else if (id(page_index) == 3) { id(internet_view) = (id(internet_view) + 1) % 3; } - - component.update: tft + - script.execute: refresh_display - id: show_next_page then: - lambda: id(page_index) = (id(page_index) + 1) % 4; - - component.update: tft + - script.execute: refresh_display button: - platform: template @@ -419,13 +431,14 @@ display: dc_pin: GPIO27 reset_pin: GPIO33 invert_colors: true - update_interval: 1s + update_interval: never lambda: |- + const auto now = id(display_time); it.fill(Color::BLACK); - if (id(sntp_time).now().is_valid()) { + if (now.is_valid()) { it.strftime(234, 10, id(font_small), Color::WHITE, TextAlign::TOP_RIGHT, - "%H:%M", id(sntp_time).now()); + "%H:%M", now); } else { it.printf(234, 10, id(font_small), Color::WHITE, TextAlign::TOP_RIGHT, "--:--"); } @@ -643,7 +656,6 @@ display: } if (id(page_index) == 2) { - const auto now = id(sntp_time).now(); const Color accent(143, 190, 223); const Color gold(255, 170, 40); const Color muted(55, 65, 80);