From 99007cda7639e6b1f67895f56598d595802965c1 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 6 Jan 2025 09:12:47 +0100 Subject: [PATCH] Updated Voice Assistant sattelites --- esphome/m5stack-atom-echo.yaml | 273 +++++++++++++++++++++++++----- esphome/raspiaudio-muse-luxe.yaml | 37 ++-- 2 files changed, 254 insertions(+), 56 deletions(-) diff --git a/esphome/m5stack-atom-echo.yaml b/esphome/m5stack-atom-echo.yaml index 79e5021..b796fe3 100644 --- a/esphome/m5stack-atom-echo.yaml +++ b/esphome/m5stack-atom-echo.yaml @@ -7,14 +7,14 @@ esphome: friendly_name: ${friendly_name} name_add_mac_suffix: False project: - name: m5stack.atom-echo - version: "1.0" - min_version: 2023.5.0 + name: m5stack.atom-echo-voice-assistant + version: "24.7.24" + min_version: 2024.9.0 esp32: board: m5stack-atom framework: - type: arduino + type: esp-idf # Enable Home Assistant API api: @@ -22,10 +22,26 @@ api: key: !secret apikey ota: - platform: esphome - password: !secret ota + - platform: esphome + password: !secret ota + id: ota_esphome + - platform: http_request + id: ota_http_request + +update: + - platform: http_request + id: update_http_request + name: Firmware + source: https://firmware.esphome.io/voice-assistant/m5stack-atom-echo/manifest.json + +http_request: wifi: + on_connect: + - delay: 5s # Gives time for improv results to be transmitted + - ble.disable: + on_disconnect: + - ble.enable: ssid: Voltage-legacy password: !secret voltage_legacy_psk use_address: ${name}.home @@ -36,18 +52,30 @@ wifi: ssid: "Raspiaudio Fallback Hotspot" password: !secret fallback_psk +improv_serial: + +esp32_improv: + authorizer: none + logger: dashboard_import: - package_import_url: github://esphome/media-players/m5stack-atom-echo.yaml@main + package_import_url: github://esphome/firmware/voice-assistant/m5stack-atom-echo.adopted.yaml@main captive_portal: -improv_serial: +button: + - platform: safe_mode + id: button_safe_mode + name: Safe Mode Boot + - platform: factory_reset + id: factory_reset_btn + name: Factory reset i2s_audio: - i2s_lrclk_pin: GPIO33 - i2s_bclk_pin: GPIO19 + - id: i2s_audio_bus + i2s_lrclk_pin: GPIO33 + i2s_bclk_pin: GPIO19 microphone: - platform: i2s_audio @@ -56,45 +84,103 @@ microphone: adc_type: external pdm: true +speaker: + - platform: i2s_audio + id: echo_speaker + i2s_dout_pin: GPIO22 + dac_type: external + channel: mono + voice_assistant: + id: va microphone: echo_microphone - on_start: + speaker: echo_speaker + noise_suppression_level: 2 + auto_gain: 31dBFS + volume_multiplier: 2.0 + vad_threshold: 3 + on_listening: - light.turn_on: id: led blue: 100% red: 0% green: 0% - effect: none + effect: "Slow Pulse" + on_stt_vad_end: + - light.turn_on: + id: led + blue: 100% + red: 0% + green: 0% + effect: "Fast Pulse" on_tts_start: - light.turn_on: id: led - blue: 0% + blue: 100% red: 0% - green: 100% + green: 0% + brightness: 100% effect: none - on_tts_end: - - media_player.play_media: !lambda return x; - - light.turn_on: - id: led - blue: 0% - red: 0% - green: 100% - effect: pulse on_end: - - delay: 1s + - delay: 100ms - wait_until: not: - media_player.is_playing: media_out - - light.turn_off: led + speaker.is_playing: + - script.execute: reset_led on_error: - light.turn_on: id: led - blue: 0% red: 100% green: 0% + blue: 0% + brightness: 100% effect: none - delay: 1s + - script.execute: reset_led + on_client_connected: + - if: + condition: + switch.is_on: use_wake_word + then: + - voice_assistant.start_continuous: + - script.execute: reset_led + on_client_disconnected: + - if: + condition: + switch.is_on: use_wake_word + then: + - voice_assistant.stop: + - light.turn_off: led + on_timer_finished: + - voice_assistant.stop: + - switch.turn_on: timer_ringing + - wait_until: + not: + microphone.is_capturing: + - light.turn_on: + id: led + red: 0% + green: 100% + blue: 0% + brightness: 100% + effect: "Fast Pulse" + - while: + condition: + switch.is_on: timer_ringing + then: + - lambda: id(echo_speaker).play(id(timer_finished_wave_file), sizeof(id(timer_finished_wave_file))); + - delay: 1s + - wait_until: + not: + speaker.is_playing: - light.turn_off: led + - switch.turn_off: timer_ringing + - if: + condition: + switch.is_on: use_wake_word + then: + - voice_assistant.start_continuous: + - script.execute: reset_led binary_sensor: - platform: gpio @@ -102,35 +188,48 @@ binary_sensor: number: GPIO39 inverted: true name: Button + disabled_by_default: true + entity_category: diagnostic id: echo_button on_multi_click: - timing: - - ON FOR AT MOST 350ms - - OFF FOR AT LEAST 10ms + - ON for at least 50ms + - OFF for at least 50ms then: - - media_player.toggle: media_out + - if: + condition: + switch.is_on: timer_ringing + then: + - switch.turn_off: timer_ringing + else: + - if: + condition: + switch.is_off: use_wake_word + then: + - if: + condition: voice_assistant.is_running + then: + - voice_assistant.stop: + - script.execute: reset_led + else: + - voice_assistant.start: + else: + - voice_assistant.stop + - delay: 1s + - script.execute: reset_led + - script.wait: reset_led + - voice_assistant.start_continuous: - timing: - - ON FOR AT LEAST 350ms + - ON for at least 10s then: - - voice_assistant.start: - - timing: - - ON FOR AT LEAST 350ms - - OFF FOR AT LEAST 10ms - then: - - voice_assistant.stop: - -media_player: - - platform: i2s_audio - id: media_out - name: None - dac_type: external - i2s_dout_pin: GPIO22 - mode: mono + - button.press: factory_reset_btn light: - platform: esp32_rmt_led_strip id: led name: None + disabled_by_default: true + entity_category: config pin: GPIO27 default_transition_length: 0s chipset: SK6812 @@ -139,5 +238,89 @@ light: rmt_channel: 0 effects: - pulse: + name: "Slow Pulse" transition_length: 250ms - update_interval: 250ms \ No newline at end of file + update_interval: 250ms + min_brightness: 50% + max_brightness: 100% + - pulse: + name: "Fast Pulse" + transition_length: 100ms + update_interval: 100ms + min_brightness: 50% + max_brightness: 100% + +script: + - id: reset_led + then: + - if: + condition: + - switch.is_on: use_wake_word + - switch.is_on: use_listen_light + then: + - light.turn_on: + id: led + red: 100% + green: 89% + blue: 71% + brightness: 60% + effect: none + else: + - light.turn_off: led + +switch: + - platform: template + name: Use wake word + id: use_wake_word + optimistic: true + restore_mode: RESTORE_DEFAULT_ON + entity_category: config + on_turn_on: + - lambda: id(va).set_use_wake_word(true); + - if: + condition: + not: + - voice_assistant.is_running + then: + - voice_assistant.start_continuous + - script.execute: reset_led + on_turn_off: + - voice_assistant.stop + - lambda: id(va).set_use_wake_word(false); + - script.execute: reset_led + - platform: template + name: Use listen light + id: use_listen_light + optimistic: true + restore_mode: RESTORE_DEFAULT_ON + entity_category: config + on_turn_on: + - script.execute: reset_led + on_turn_off: + - script.execute: reset_led + - platform: template + id: timer_ringing + optimistic: true + internal: true + restore_mode: ALWAYS_OFF + on_turn_on: + - delay: 15min + - switch.turn_off: timer_ringing + +external_components: + - source: github://pr#5230 + components: + - esp_adf + refresh: 0s + - source: + type: git + url: https://github.com/jesserockz/esphome-components + ref: main + components: [file] + refresh: 0s + +esp_adf: + +file: + - id: timer_finished_wave_file + file: https://github.com/esphome/firmware/raw/main/voice-assistant/sounds/timer_finished.wav diff --git a/esphome/raspiaudio-muse-luxe.yaml b/esphome/raspiaudio-muse-luxe.yaml index 423e2b2..b7dc36c 100644 --- a/esphome/raspiaudio-muse-luxe.yaml +++ b/esphome/raspiaudio-muse-luxe.yaml @@ -8,8 +8,9 @@ api: key: !secret apikey ota: - platform: esphome - password: !secret ota + - platform: esphome + id: ota_esphome + password: !secret ota wifi: ssid: Voltage-legacy @@ -29,7 +30,7 @@ esphome: project: name: raspiaudio.muse-luxe version: "1.0" - min_version: 2023.5.0 + min_version: 2024.6.0 on_boot: then: - media_player.volume_set: @@ -44,25 +45,25 @@ esp32: logger: i2c: - sda: GPIO18 - scl: GPIO23 + - id: i2c_bus + sda: GPIO18 + scl: GPIO23 dashboard_import: package_import_url: github://esphome/media-players/raspiaudio-muse-luxe.yaml@main captive_portal: -improv_serial: - external_components: - - source: github://pr#3552 # DAC support https://github.com/esphome/esphome/pull/3552 + - source: github://pr#3552 # DAC support https://github.com/esphome/esphome/pull/3552 components: [es8388] refresh: 0s es8388: i2s_audio: - - i2s_lrclk_pin: GPIO25 + - id: i2s_audio_bus + i2s_lrclk_pin: GPIO25 i2s_bclk_pin: GPIO5 media_player: @@ -125,6 +126,7 @@ voice_assistant: sensor: - platform: adc + id: battery_sensor pin: GPIO33 name: Battery icon: "mdi:battery-outline" @@ -137,12 +139,13 @@ sensor: attenuation: 11db raw: true filters: - - multiply: 0.00173913 # 2300 -> 4, for attenuation 11db, based on Olivier's code + - multiply: 0.00173913 # 2300 -> 4, for attenuation 11db, based on Olivier's code - exponential_moving_average: alpha: 0.2 send_every: 2 - delta: 0.002 + binary_sensor: - platform: gpio pin: @@ -152,6 +155,7 @@ binary_sensor: input: true pullup: true name: Volume Up + id: volume_up on_click: - media_player.volume_up: luxe_out - platform: gpio @@ -162,6 +166,7 @@ binary_sensor: input: true pullup: true name: Volume Down + id: volume_down on_click: - media_player.volume_down: luxe_out - platform: gpio @@ -172,6 +177,7 @@ binary_sensor: input: true pullup: true name: Action + id: action_button on_multi_click: - timing: - ON FOR AT MOST 350ms @@ -200,4 +206,13 @@ light: effects: - pulse: transition_length: 250ms - update_interval: 250ms \ No newline at end of file + update_interval: 250ms + +button: + - platform: safe_mode + id: button_safe_mode + name: Safe Mode Boot + + - platform: factory_reset + id: factory_reset_btn + name: Factory reset