Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # info https://smarthomecircle.com/How-to-setup-on-device-wake-word-for-voice-assistant-home-assistant
- #pinout microfon:
- # ESP -> INMP441 mikrofon
- # gpio2 SCK
- # gpio3 WS
- # gpio4 SD
- # 3.3v Vdd
- # GND GND + L/R
- #pinout ws2812 RGB LEDring
- # ESP -> ws2812
- # gpio13 DI
- # 5v 5v
- # GND GND
- substitutions:
- name: "smallroomassist"
- friendly_name: SmallroomAssist
- esp_board: "esp32-s3-devkitc-1"
- device_description: "esp32s3"
- # Phases of the Voice Assistant
- # IDLE: The voice assistant is ready to be triggered by a wake-word
- voice_assist_idle_phase_id: '1'
- # LISTENING: The voice assistant is ready to listen to a voice command (after being triggered by the wake word)
- voice_assist_listening_phase_id: '2'
- # THINKING: The voice assistant is currently processing the command
- voice_assist_thinking_phase_id: '3'
- # REPLYING: The voice assistant is replying to the command
- voice_assist_replying_phase_id: '4'
- # NOT_READY: The voice assistant is not ready
- voice_assist_not_ready_phase_id: '10'
- # ERROR: The voice assistant encountered an error
- voice_assist_error_phase_id: '11'
- # MUTED: The voice assistant is muted and will not reply to a wake-word
- voice_assist_muted_phase_id: '12'
- #Micro
- #micro_wake_word_model: hey_jarvis
- external_components:
- - source:
- type: git
- url: https://github.com/gnumpi/esphome_audio
- ref: main
- #type: local
- #path: /Users/siekmann/Privat/Projects/espHome/esphome_audio/esphome/components
- components: [ adf_pipeline, i2s_audio ]
- esphome:
- name: ${name}
- comment: ${device_description}
- friendly_name: ${friendly_name}
- min_version: 2024.6.0
- name_add_mac_suffix: false
- platformio_options:
- build_flags: -DBOARD_HAS_PSRAM
- board_build.flash_mode: dio
- board_upload.maximum_size: 16777216
- on_boot:
- priority: 600
- then:
- # Run the script to refresh the LED status
- # If after 30 seconds, the device is still initializing (It did not yet connect to Home Assistant), turn off the init_in_progress variable and run the script to refresh the LED status
- - delay: 30s
- - if:
- condition:
- lambda: return id(init_in_progress);
- then:
- - lambda: id(init_in_progress) = false;
- esp32:
- board: ${esp_board}
- variant: ESP32S3
- flash_size: 16MB
- framework:
- type: esp-idf
- sdkconfig_options:
- # need to set a s3 compatible board for the adf-sdk to compile
- # board specific code is not used though
- CONFIG_ESP32_S3_BOX_BOARD: "y"
- CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM: "16"
- CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM: "512"
- CONFIG_TCPIP_RECVMBOX_SIZE: "512"
- CONFIG_TCP_SND_BUF_DEFAULT: "65535"
- CONFIG_TCP_WND_DEFAULT: "512000"
- CONFIG_TCP_RECVMBOX_SIZE: "512"
- # Enable logging
- logger:
- globals:
- # Global initialisation variable. Initialized to true and set to false once everything is connected. Only used to have a smooth "plugging" experience
- - id: init_in_progress
- type: bool
- restore_value: no
- initial_value: 'true'
- # Global variable tracking the phase of the voice assistant (defined above). Initialized to not_ready
- - id: voice_assistant_phase
- type: int
- restore_value: no
- initial_value: ${voice_assist_not_ready_phase_id}
- psram:
- mode: octal
- speed: 80MHz
- wifi:
- enable_rrm: true
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- fast_connect: true
- # Optional manual IP
- # manual_ip:
- # static_ip: 10.10.10.109
- # gateway: 10.10.10.1
- # subnet: 255.255.255.0
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Smalroomassist Fallback Hotspot"
- password: "9ulKpPRzf55I"
- # Enable Home Assistant API
- api:
- encryption:
- key: "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
- # services:
- # - service: play_audio
- # variables:
- # audio_url: string
- # then:
- # - homeassistant.service:
- # service: media_player.play_media
- # data:
- # entity_id: media_player.csaladi_szoba
- # media_content_id: !lambda 'return audio_url;'
- # media_content_type: "music"
- # Allow Over-The-Air updates
- ota:
- - platform: esphome
- password: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
- # Allow provisioning Wi-Fi via serial
- improv_serial:
- #----------------------
- adf_pipeline:
- - platform: i2s_audio
- type: audio_out
- id: adf_i2s_out
- i2s_audio_id: i2s_speaker
- i2s_dout_pin: GPIO9
- - platform: i2s_audio #microfon
- type: audio_in
- id: adf_i2s_in
- i2s_audio_id: i2s_in
- i2s_din_pin: GPIO4
- pdm: false
- channel: left
- sample_rate: 16000
- bits_per_sample: 32bit
- # Audio and Voice Assistant Config
- i2s_audio:
- - id: i2s_in
- i2s_lrclk_pin: GPIO3 #WS
- i2s_bclk_pin: GPIO2 #SCK
- - id: i2s_speaker
- i2s_lrclk_pin: GPIO6 #LRC
- i2s_bclk_pin: GPIO7 #BLCK
- microphone:
- - platform: adf_pipeline
- id: adf_microphone
- keep_pipeline_alive: true
- pipeline:
- - adf_i2s_in
- - self
- #media_player:
- # - platform: adf_pipeline
- # id: adf_media_player
- # name: media_player
- # keep_pipeline_alive: true
- # internal: false
- # pipeline:
- # - self
- # - resampler
- # - adf_i2s_out
- #micro_wake_word:
- # models:
- # - model: ${micro_wake_word_model} #"https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/v2/experiments/choo_choo_homie.json"
- # - model: "https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/hey_jarvis.json"
- micro_wake_word:
- models:
- - model: "https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/hey_jarvis.json"
- on_wake_word_detected:
- # - media_player.stop:
- - light.turn_on:
- id: led_ring
- blue: 0%
- red: 0%
- green: 100%
- brightness: 75%
- effect: pulse
- - voice_assistant.start:
- voice_assistant:
- microphone: adf_microphone
- ####media_player: adf_media_player
- use_wake_word: false
- #vad_threshold: 3
- #noise_suppression_level: 1
- auto_gain: 31dBFS
- #volume_multiplier: 15.0
- on_tts_start:
- - homeassistant.service:
- service: media_player.volume_set
- data:
- entity_id: media_player.csaladi_szoba # Replace with your media player entity_id
- volume_level: '0.4' # Lower volume to 20%
- - homeassistant.service:
- # service: tts.cloud_say
- # data:
- # media_player_entity_id: media_player.csaladi_szoba
- # # entity_id: media_player.csaladi_szoba #media_player.announcements
- # data_template:
- # message: !lambda 'return x;' #"{{ my_stt }}"
- # variables:
- # my_stt: return x;
- service: tts.speak
- data:
- # cache: true
- message: !lambda 'return x;'
- media_player_entity_id: media_player.csaladi_szoba
- entity_id: tts.google_cloud
- language: hu-HU
- - light.turn_on:
- id: led_ring
- blue: 0%
- red: 0%
- green: 100%
- brightness: 75%
- effect: pulse
- # on_tts_end:
- # - homeassistant.service:
- # service: media_player.play_media
- # data:
- # entity_id: media_player.csaladi_szoba
- # media_content_type: music
- # data_template:
- # media_content_id: "{{ my_stt }}"#"{{ my_url }}"
- # variables:
- # my_url: return x;
- # - homeassistant.service:
- ## service: tts.speak
- # data:
- # media_player_entity_id: media_player.csaladi_szoba #replace this with your media player entity id
- # message: !lambda 'return x;'
- # entity_id: tts.google_cloud #replace this with your piper tts entity id.
- on_client_connected:
- - lambda: id(init_in_progress) = false;
- - if:
- condition:
- switch.is_on: use_wake_word
- then:
- - micro_wake_word.start:
- - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
- - script.execute: reset_led
- else:
- - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
- on_client_disconnected:
- - lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
- - voice_assistant.stop
- - micro_wake_word.stop
- - light.turn_on:
- id: led_ring
- blue: 0%
- red: 100%
- green: 100%
- brightness: 50%
- effect: connecting
- on_listening:
- - light.turn_on:
- id: led_ring
- blue: 100%
- red: 0%
- green: 0%
- brightness: 25%
- effect: wakeword
- on_end:
- then:
- - light.turn_off:
- id: led_ring
- - voice_assistant.stop
- #- wait_until:
- # not:
- # media_player.is_playing:
- - script.execute: reset_led
- - if:
- condition:
- switch.is_on: use_wake_word
- then:
- - micro_wake_word.start:
- on_error:
- - light.turn_on:
- id: led_ring
- blue: 0%
- red: 100%
- green: 0%
- brightness: 100%
- effect: none
- - delay: 1s
- - script.execute: reset_led
- - script.wait: reset_led
- - lambda: |-
- if (code == "wake-provider-missing" || code == "wake-engine-missing") {
- id(use_wake_word).turn_off();
- }
- - if:
- condition:
- switch.is_on: use_wake_word
- then:
- - micro_wake_word.start:
- - script.execute: reset_led
- script:
- - id: reset_led
- then:
- - if:
- condition:
- switch.is_on: use_wake_word
- then:
- - light.turn_on:
- id: led_ring
- blue: 100%
- red: 0%
- green: 0%
- brightness: 25%
- effect: none
- else:
- - light.turn_off: led_ring
- button:
- - platform: restart
- id: restart_btn
- name: "${friendly_name} REBOOT"
- switch:
- - platform: template
- name: Enable Voice Assistant
- id: use_wake_word
- optimistic: true
- restore_mode: RESTORE_DEFAULT_ON
- icon: mdi:assistant
- # When the switch is turned on (on Home Assistant):
- # Start the voice assistant component
- # Set the correct phase and run the script to refresh the LED status
- on_turn_on:
- - logger.log: "switch on"
- - if:
- condition:
- lambda: return !id(init_in_progress);
- then:
- - logger.log: "condition 1"
- - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
- - voice_assistant.stop
- - delay: 1s
- - if:
- condition:
- not:
- - voice_assistant.is_running
- then:
- - logger.log: "Starting MWW"
- #- voice_assistant.start_continuous
- - micro_wake_word.start:
- - script.execute: reset_led
- on_turn_off:
- - if:
- condition:
- lambda: return !id(init_in_progress);
- then:
- - voice_assistant.stop
- - micro_wake_word.stop
- - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
- - script.execute: reset_led
- - platform: template
- name: Pipeline
- id: pipeline_switch
- optimistic: true
- restore_mode: RESTORE_DEFAULT_OFF
- # on_turn_off:
- #- media_player.stop
- light:
- - platform: esp32_rmt_led_strip
- id: led_ring
- name: "${friendly_name} Front LED"
- #pin: GPIO48 #on board led 1pc led
- pin: GPIO13 #on board led 1pc led
- num_leds: 12 #1
- rmt_channel: 0 #1
- rgb_order: GRB
- chipset: ws2812
- default_transition_length: 0s
- effects:
- - pulse:
- name: "Pulse"
- transition_length: 0.5s
- update_interval: 0.5s
- - addressable_twinkle:
- name: "Working"
- twinkle_probability: 5%
- progress_interval: 4ms
- - addressable_color_wipe:
- name: "Wakeword"
- colors:
- - red: 0%
- green: 50%
- blue: 0%
- num_leds: 12
- add_led_interval: 20ms
- reverse: false
- - addressable_color_wipe:
- name: "Connecting"
- colors:
- - red: 60%
- green: 60%
- blue: 60%
- num_leds: 1
- - red: 60%
- green: 60%
- blue: 0%
- num_leds: 1
- add_led_interval: 100ms
- reverse: true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement