globals: # 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: "2" - id: stt_vad_started type: bool restore_value: no initial_value: "false" i2s_audio: id: i2s_audio_bus i2s_lrclk_pin: GPIO${WS} #WS i2s_bclk_pin: GPIO${SCK} #sck microphone: - platform: i2s_audio id: echo_microphone i2s_din_pin: GPIO${SD} #SD adc_type: external i2s_audio_id: i2s_audio_bus #pdm: False channel: right sample_rate: 16000 bits_per_sample: 16bit #i2s_mode: primary correct_dc_offset: true voice_assistant: id: va microphone: microphone: echo_microphone channels: 0 gain_factor: 4 noise_suppression_level: 2 auto_gain: 31dBFS on_start: - light.turn_on: id: led red: 0% green: 100% blue: 0% brightness: 15% effect: none on_listening: - light.turn_on: id: led blue: 100% red: 0% green: 0% effect: none - lambda: id(voice_assistant_phase) = 2; - lambda: id(stt_vad_started) = false; on_stt_vad_start: # Turn off the script if speech is detected - lambda: id(stt_vad_started) = true; on_stt_vad_end: #- logger.log: "===============================VAD is the END ==================================" - light.turn_on: id: led blue: 100% red: 0% green: 100% effect: none on_stt_end: - logger.log: format: "STT text: %s" args: ["x.c_str()"] on_tts_start: then: - light.turn_on: id: led blue: 100% red: 100% green: 100% brightness: 30% effect: none on_tts_end: - homeassistant.action: action: media_player.play_media data: entity_id: ${SPKR} media_content_id: !lambda "return x;" media_content_type: music announce: "false" on_end: - lambda: id(voice_assistant_phase) = 1; - lambda: id(stt_vad_started) = false; - script.execute: start_wake_word #- voice_assistant.start: on_error: - if: condition: lambda: |- return message.find("duplicate_wake_up_detected") != std::string::npos; then: - voice_assistant.stop: - delay: 350ms - script.execute: start_wake_word else: - lambda: id(voice_assistant_phase) = 4; - light.turn_on: id: led red: 100% green: 0% blue: 0% brightness: 100% effect: "Slow Pulse" - delay: 2s - script.execute: rboot #- script.execute: reset_led on_client_connected: - delay: 1s # Give the api server time to settle - script.execute: start_wake_word on_client_disconnected: - lambda: id(voice_assistant_phase) = 4; - script.execute: stop_wake_word - script.execute: rboot interval: - interval: 30s then: - if: condition: and: - api.connected: - not: - voice_assistant.is_running: then: - script.execute: start_wake_word script: - id: rboot mode: restart then: - delay: 180s - if: condition: lambda: |- return id(voice_assistant_phase) == 4; then: - switch.turn_on: id: rbt - id: listening_timeout mode: restart then: - delay: 4s # - logger.log: # format: "In Script >>>> C >>>> voice_assistant_phase=%d " # args: [ 'id(voice_assistant_phase)' ] - if: condition: lambda: |- return id(voice_assistant_phase) == 2 && !id(stt_vad_started); then: - logger.log: "+++++++++++++++++++++++++ reset ==========================================" - light.turn_off: id: led - voice_assistant.stop: - delay: 1s - script.execute: start_wake_word - id: start_wake_word then: - if: condition: #and: - not: - voice_assistant.is_running: then: - lambda: id(va).set_use_wake_word(true); - voice_assistant.start_continuous: - id: stop_wake_word then: - lambda: id(va).set_use_wake_word(false); - voice_assistant.stop: switch: - platform: restart name: Restart id: rbt - platform: template name: Stop Listen optimistic: true restore_mode: RESTORE_DEFAULT_OFF #entity_category: config on_turn_on: - microphone.mute: echo_microphone #- script.execute: stop_wake_word on_turn_off: - microphone.unmute: echo_microphone #- script.execute: listening_timeout