From 16b31dc3a156d8593d8b0cd27af954c671082fe1 Mon Sep 17 00:00:00 2001 From: Justin Bunton <130115204+Bunton33@users.noreply.github.com> Date: Tue, 18 Nov 2025 14:20:20 -0500 Subject: [PATCH 1/3] Turn off Wi-Fi while playing song --- Integrations/ESPHome/Core.yaml | 59 ++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index b470080..97e1f78 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,5 +1,5 @@ substitutions: - version: "25.11.10.2" + version: "25.11.18.1" esp32: board: esp32-c6-devkitm-1 @@ -12,7 +12,7 @@ output: - platform: ledc pin: GPIO20 id: buzzer - max_power: 60% + max_power: 50% rtttl: id: rtttl_buzzer @@ -797,6 +797,11 @@ light: script: - id: play_song_1 then: + - lambda: |- + ESP_LOGW("WiFi", "Disabling WiFi for song playback"); + wifi::global_wifi_component->disable(); + - delay: 100ms + - light.turn_on: brightness: 80% id: rgb_light @@ -810,10 +815,21 @@ script: - delay: 30s - light.turn_off: rgb_light - light.turn_off: logo_light + + - lambda: |- + ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); + wifi::global_wifi_component->enable(); + - delay: 100ms + - script.execute: ShouldSleep - id: play_song_2 then: + - lambda: |- + ESP_LOGW("WiFi", "Disabling WiFi for song playback"); + wifi::global_wifi_component->disable(); + - delay: 100ms + - light.turn_on: brightness: 80% id: rgb_light @@ -827,10 +843,21 @@ script: - delay: 30s - light.turn_off: rgb_light - light.turn_off: logo_light + + - lambda: |- + ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); + wifi::global_wifi_component->enable(); + - delay: 100ms + - script.execute: ShouldSleep - id: play_song_3 then: + - lambda: |- + ESP_LOGW("WiFi", "Disabling WiFi for song playback"); + wifi::global_wifi_component->disable(); + - delay: 100ms + - light.turn_on: brightness: 80% id: rgb_light @@ -844,10 +871,21 @@ script: - delay: 30s - light.turn_off: rgb_light - light.turn_off: logo_light + + - lambda: |- + ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); + wifi::global_wifi_component->enable(); + - delay: 100ms + - script.execute: ShouldSleep - id: play_song_4 then: + - lambda: |- + ESP_LOGW("WiFi", "Disabling WiFi for song playback"); + wifi::global_wifi_component->disable(); + - delay: 100ms + - light.turn_on: brightness: 80% id: rgb_light @@ -861,10 +899,21 @@ script: - delay: 30s - light.turn_off: rgb_light - light.turn_off: logo_light + + - lambda: |- + ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); + wifi::global_wifi_component->enable(); + - delay: 100ms + - script.execute: ShouldSleep - id: play_song_x then: + - lambda: |- + ESP_LOGW("WiFi", "Disabling WiFi for Sandstorm playback"); + wifi::global_wifi_component->disable(); + - delay: 100ms + - light.turn_on: brightness: 80% id: rgb_light @@ -878,6 +927,12 @@ script: - delay: 30s - light.turn_off: rgb_light - light.turn_off: logo_light + + - lambda: |- + ESP_LOGW("WiFi", "Re-enabling WiFi after Sandstorm playback"); + wifi::global_wifi_component->enable(); + - delay: 100ms + - script.execute: ShouldSleep - id: testScript From 026087053756352f57ff498a50ab113dbccacf49 Mon Sep 17 00:00:00 2001 From: Justin Bunton <130115204+Bunton33@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:24:20 -0500 Subject: [PATCH 2/3] Add USB power toggle and battery limit --- Integrations/ESPHome/Core.yaml | 303 +++++++++++++++++++++++++++++---- 1 file changed, 270 insertions(+), 33 deletions(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 97e1f78..7a00814 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -80,6 +80,45 @@ switch: restore_mode: ALWAYS_ON setup_priority: 2000 internal: true + + # Power mode switch for battery vs USB-C/mains power + - platform: template + name: "USB Power Mode" + id: usb_power_mode + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF # Default to battery-safe mode (OFF) + icon: "mdi:power-plug" + device_class: switch + on_turn_on: + then: + - logger.log: + format: "USB Power Mode enabled - setting volume to 100%" + level: INFO + tag: "PowerMode" + - number.set: + id: volume_control + value: 100 + - logger.log: + format: "USB/High Power Mode ENABLED - Allowing full buzzer power (100%)" + level: INFO + tag: "PowerMode" + - logger.log: + format: "Volume limit removed - Make sure device is connected to USB-C/mains power" + level: WARN + tag: "PowerMode" + on_turn_off: + then: + - logger.log: + format: "Battery mode enabled - setting volume to 25%" + level: INFO + tag: "PowerMode" + - number.set: + id: volume_control + value: 25 + - logger.log: + format: "Battery Power Mode ENABLED - Limiting buzzer to 25 for battery safety" + level: INFO + tag: "PowerMode" button: - platform: factory_reset @@ -137,13 +176,55 @@ number: id: volume_control min_value: 0 max_value: 100 - initial_value: 100 + initial_value: 25 # Default to battery-safe 25% unit_of_measurement: "%" step: 1 optimistic: true restore_value: true + icon: "mdi:volume-high" on_value: - - lambda: id(rtttl_buzzer).set_gain(pow(x / 100.0f, 3)); + then: + - if: + condition: + # If USB power mode is OFF (battery mode), enforce 25% limit + and: + - switch.is_off: usb_power_mode + - lambda: 'return x > 25.0;' + then: + - logger.log: + format: "Battery mode active - limiting volume to 25%%" + level: WARN + tag: "Volume" + - number.set: + id: volume_control + value: 25 + - lambda: |- + // Apply cubic scaling with 25% limit for battery mode + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - if: + condition: + switch.is_on: usb_power_mode + then: + - logger.log: + format: "USB mode active - setting volume to %.0f%%" + args: ['x'] + level: INFO + tag: "Volume" + else: + - logger.log: + format: "Battery mode active - setting volume to %.0f%% (max 25%%)" + args: ['x'] + level: INFO + tag: "Volume" + - lambda: |- + // Apply cubic scaling for better volume control + float actual_volume = x; + // Enforce power mode limits + if (!id(usb_power_mode).state && actual_volume > 25.0) { + actual_volume = 25.0; + } + id(rtttl_buzzer).set_gain(pow(actual_volume / 100.0f, 3)); text_sensor: - platform: template @@ -797,11 +878,42 @@ light: script: - id: play_song_1 then: - - lambda: |- - ESP_LOGW("WiFi", "Disabling WiFi for song playback"); - wifi::global_wifi_component->disable(); + - logger.log: + format: "Disabling WiFi for song playback" + level: WARN + tag: "WiFi" + - wifi.disable: - delay: 100ms + # Apply volume based on power mode + - if: + condition: + switch.is_off: usb_power_mode + then: + # Battery mode - limit to 25% + - if: + condition: + lambda: 'return id(volume_control).state > 25.0;' + then: + - logger.log: + format: "Battery mode active - limiting buzzer volume to 25%%" + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + else: + # USB mode - use full volume setting + - logger.log: + format: "USB mode active - using volume setting: %.0f%%" + args: ['id(volume_control).state'] + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + - light.turn_on: brightness: 80% id: rgb_light @@ -816,20 +928,53 @@ script: - light.turn_off: rgb_light - light.turn_off: logo_light - - lambda: |- - ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); - wifi::global_wifi_component->enable(); + - logger.log: + format: "Re-enabling WiFi after song playback" + level: WARN + tag: "WiFi" + - wifi.enable: - delay: 100ms - script.execute: ShouldSleep - id: play_song_2 then: - - lambda: |- - ESP_LOGW("WiFi", "Disabling WiFi for song playback"); - wifi::global_wifi_component->disable(); + - logger.log: + format: "Disabling WiFi for song playback" + level: WARN + tag: "WiFi" + - wifi.disable: - delay: 100ms + # Apply volume based on power mode + - if: + condition: + switch.is_off: usb_power_mode + then: + # Battery mode - limit to 25% + - if: + condition: + lambda: 'return id(volume_control).state > 25.0;' + then: + - logger.log: + format: "Battery mode active - limiting buzzer volume to 25%%" + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + else: + # USB mode - use full volume setting + - logger.log: + format: "USB mode active - using volume setting: %.0f%%" + args: ['id(volume_control).state'] + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + - light.turn_on: brightness: 80% id: rgb_light @@ -844,20 +989,53 @@ script: - light.turn_off: rgb_light - light.turn_off: logo_light - - lambda: |- - ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); - wifi::global_wifi_component->enable(); + - logger.log: + format: "Re-enabling WiFi after song playback" + level: WARN + tag: "WiFi" + - wifi.enable: - delay: 100ms - script.execute: ShouldSleep - id: play_song_3 then: - - lambda: |- - ESP_LOGW("WiFi", "Disabling WiFi for song playback"); - wifi::global_wifi_component->disable(); + - logger.log: + format: "Disabling WiFi for song playback" + level: WARN + tag: "WiFi" + - wifi.disable: - delay: 100ms + # Apply volume based on power mode + - if: + condition: + switch.is_off: usb_power_mode + then: + # Battery mode - limit to 25% + - if: + condition: + lambda: 'return id(volume_control).state > 25.0;' + then: + - logger.log: + format: "Battery mode active - limiting buzzer volume to 25%%" + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + else: + # USB mode - use full volume setting + - logger.log: + format: "USB mode active - using volume setting: %.0f%%" + args: ['id(volume_control).state'] + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + - light.turn_on: brightness: 80% id: rgb_light @@ -872,19 +1050,52 @@ script: - light.turn_off: rgb_light - light.turn_off: logo_light - - lambda: |- - ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); - wifi::global_wifi_component->enable(); + - logger.log: + format: "Re-enabling WiFi after song playback" + level: WARN + tag: "WiFi" + - wifi.enable: - delay: 100ms - script.execute: ShouldSleep - id: play_song_4 then: - - lambda: |- - ESP_LOGW("WiFi", "Disabling WiFi for song playback"); - wifi::global_wifi_component->disable(); - - delay: 100ms + - logger.log: + format: "Disabling WiFi for song playback" + level: WARN + tag: "WiFi" + - wifi.disable: + - delay: 100ms + + # Apply volume based on power mode + - if: + condition: + switch.is_off: usb_power_mode + then: + # Battery mode - limit to 25% + - if: + condition: + lambda: 'return id(volume_control).state > 25.0;' + then: + - logger.log: + format: "Battery mode active - limiting buzzer volume to 25%%" + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + else: + # USB mode - use full volume setting + - logger.log: + format: "USB mode active - using volume setting: %.0f%%" + args: ['id(volume_control).state'] + level: INFO + tag: "PlaySong" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); - light.turn_on: brightness: 80% @@ -900,20 +1111,44 @@ script: - light.turn_off: rgb_light - light.turn_off: logo_light - - lambda: |- - ESP_LOGW("WiFi", "Re-enabling WiFi after song playback"); - wifi::global_wifi_component->enable(); + - logger.log: + format: "Re-enabling WiFi after song playback" + level: WARN + tag: "WiFi" + - wifi.enable: - delay: 100ms - script.execute: ShouldSleep - id: play_song_x then: - - lambda: |- - ESP_LOGW("WiFi", "Disabling WiFi for Sandstorm playback"); - wifi::global_wifi_component->disable(); + - logger.log: + format: "Disabling WiFi for Sandstorm playback" + level: WARN + tag: "WiFi" + - wifi.disable: - delay: 100ms + # Check battery level and apply volume limit + - if: + condition: + and: + - sensor.in_range: + id: batt_pct + below: 50.0 + - lambda: 'return id(volume_control).state > 25.0;' + then: + - logger.log: + format: "Low battery (%.1f%%) - limiting buzzer volume to 25%%" + args: ['id(batt_pct).state'] + level: WARN + tag: "Battery" + - lambda: |- + id(rtttl_buzzer).set_gain(pow(25.0 / 100.0f, 3)); + else: + - lambda: |- + id(rtttl_buzzer).set_gain(pow(id(volume_control).state / 100.0f, 3)); + - light.turn_on: brightness: 80% id: rgb_light @@ -928,9 +1163,11 @@ script: - light.turn_off: rgb_light - light.turn_off: logo_light - - lambda: |- - ESP_LOGW("WiFi", "Re-enabling WiFi after Sandstorm playback"); - wifi::global_wifi_component->enable(); + - logger.log: + format: "Re-enabling WiFi after Sandstorm playback" + level: WARN + tag: "WiFi" + - wifi.enable: - delay: 100ms - script.execute: ShouldSleep From db04fb30951a12d48c637e173f814c014e828270 Mon Sep 17 00:00:00 2001 From: Justin Bunton <130115204+Bunton33@users.noreply.github.com> Date: Wed, 19 Nov 2025 17:22:09 -0500 Subject: [PATCH 3/3] Version Update --- Integrations/ESPHome/Core.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Integrations/ESPHome/Core.yaml b/Integrations/ESPHome/Core.yaml index 7a00814..8ce01ec 100644 --- a/Integrations/ESPHome/Core.yaml +++ b/Integrations/ESPHome/Core.yaml @@ -1,5 +1,5 @@ substitutions: - version: "25.11.18.1" + version: "25.11.19.1" esp32: board: esp32-c6-devkitm-1