From f5de971dda6f5cfdd3d0dfdb3e2a26edd0956689 Mon Sep 17 00:00:00 2001 From: radu Date: Thu, 3 Dec 2026 17:09:44 +0700 Subject: [PATCH] scr2 --- services/screen.yaml | 63 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/services/screen.yaml b/services/screen.yaml index 32eabfa..1d5d71a 100644 --- a/services/screen.yaml +++ b/services/screen.yaml @@ -2,7 +2,9 @@ # Use together with board/ws146.yaml and services/voice.yaml. # # Shows the voice assistant state (coloured ring + status text) and the last -# command / reply. Adds a "Screen" switch that turns the backlight on and off. +# command / reply. The screen stays dark until the wake word is heard, stays on +# while HA thinks and replies, and turns off 5 s after the conversation ends. +# The "Screen" switch enables or disables this; when off the screen never lights. # # The voice_assistant triggers below are APPENDED to the ones in # services/voice.yaml (ESPHome concatenates lists when merging packages). @@ -51,7 +53,7 @@ light: name: Screen Backlight internal: true output: backlight_pwm - restore_mode: ALWAYS_OFF # the Screen switch sets it at boot + restore_mode: ALWAYS_OFF # lit only by screen_wake during a conversation default_transition_length: 300ms switch: @@ -62,9 +64,18 @@ switch: optimistic: true restore_mode: RESTORE_DEFAULT_ON on_turn_on: - - lvgl.resume: - - light.turn_on: backlight + # Enabled: light up now if a conversation is in progress, else stay dark. + - if: + condition: + lambda: 'return id(screen_state) >= 1 && id(screen_state) <= 3;' + then: + - script.execute: screen_wake + else: + - script.execute: + id: screen_sleep + delay_ms: 0 on_turn_off: + - script.stop: screen_sleep - light.turn_off: backlight - lvgl.pause: @@ -170,6 +181,33 @@ script: id: transcript_label text: "" + # Light the screen for a conversation (only if the Screen switch is on). + # Also arms a 60 s fallback so it can never stay lit if on_end is missed. + - id: screen_wake + mode: restart + then: + - if: + condition: + switch.is_on: screen_switch + then: + - lvgl.resume: + - light.turn_on: backlight + - script.execute: + id: screen_sleep + delay_ms: 60000 + + # Turn the screen off after delay_ms; a new call restarts the countdown. + - id: screen_sleep + mode: restart + parameters: + + delay_ms: int + then: + - delay: !lambda return delay_ms; + - light.turn_off: backlight + - delay: 300ms # let the fade finish before freezing the UI + - lvgl.pause: + # ------------------------------------------- hooks into services/voice.yaml -- voice_assistant: on_listening: @@ -178,6 +216,7 @@ voice_assistant: - script.execute: id: screen_set_transcript text: "" + - script.execute: screen_wake on_stt_vad_end: - lambda: id(screen_state) = 2; - script.execute: screen_refresh @@ -192,19 +231,31 @@ voice_assistant: - lambda: id(screen_state) = 3; - script.execute: screen_refresh - script.execute: - id: screen_set_transcript + id: screen_set_transc + + + ript text: !lambda return x; on_end: - lambda: id(screen_state) = 0; - script.execute: screen_refresh + - script.execute: + id: screen_sleep + delay_ms: 5000 on_error: - lambda: |- if (message.find("duplicate_wake_up_detected") == std::string::npos) id(screen_state) = 4; - script.execute: screen_refresh + - script.execute: + id: screen_sleep + delay_ms: 5000 on_client_connected: - lambda: id(screen_state) = 0; - script.execute: screen_refresh on_client_disconnected: - lambda: id(screen_state) = 5; - - script.execute: screen_refresh \ No newline at end of file + - script.execute: screen_refresh + - script.execute: + id: screen_sleep + delay_ms: 0 \ No newline at end of file