Voice Assistant Device Speak on Startup

Looking to have my voice assistant on startup to say a few words.

Example: “Assistant Ready”.

Not quite sure how I should do this.

Also thinking it might solve the white noise I get on when the device is ready but goes away on first reply.

Here is my code:

esphome:
  name: voice-assist-001
  friendly_name: Voice Assist 001
  on_boot:
    - priority: -100
      then:
        - wait_until: api.connected
        - delay: 1s
        - if:
            condition:
              switch.is_on: use_wake_word
            then:
              - voice_assistant.start_continuous:

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "KEY_HERE"

ota:
  password: "PASSWORD_HERE"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: STATIC_IP
    gateway: STATIC_GATEWAY_IP
    subnet: SUBNET_ADDRESS
    
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "SSID_NAME"
    password: "AP_PASSWORD"

captive_portal:

i2s_audio:
  - id: i2s_in
    i2s_lrclk_pin: GPIO26 #WS 
    i2s_bclk_pin: GPIO25 #SCK

microphone:
  - platform: i2s_audio
    adc_type: external
    pdm: false
    id: mic_i2s
    channel: right
    bits_per_sample: 32bit
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO33  #SD Pin from the INMP441 Microphone

media_player:
  - platform: i2s_audio
    name: "esp_speaker"
    id: media_player_speaker
    i2s_audio_id: i2s_in
    dac_type: external
    i2s_dout_pin: GPIO27   #  DIN Pin of the MAX98357A Audio Amplifier
    mode: mono

voice_assistant:
  microphone: mic_i2s
  id: va
  noise_suppression_level: 2
  auto_gain: 31dBFS
  volume_multiplier: 2.0
  use_wake_word: false
  media_player: media_player_speaker
  
  on_wake_word_detected: 
    - light.turn_on:
        id: led_light
  on_listening: 
    - light.turn_on:
        id: led_light
        effect: "Rainbow Spinner"
 #       red: 71%
 #       green: 0%
 #       blue: 71%

  on_stt_end:
    - light.turn_on:
        id: led_light
        effect: "None"
        red: 0%
        green: 100%
        blue: 0%

  on_error: 
    - light.turn_on:
        id: led_light
        effect: "None"
        red: 100%
        green: 0%
        blue: 0%
    - if:
        condition:
          switch.is_on: use_wake_word
        then:

          - switch.turn_off: use_wake_word
          - delay: 1sec 
          - switch.turn_on: use_wake_word      
  
  on_tts_start:                                    # this is required to play the output on a media player
    - homeassistant.service:
        service: tts.speak
        data:
          media_player_entity_id: media_player.voice_assist_001_esp_speaker    #replace this with your media player entity id
          message: !lambda 'return x;'
          entity_id: tts.piper_2                 #replace this with your piper tts id.

  on_client_connected:
    - if:
        condition:
          switch.is_on: use_wake_word
        then:
          - voice_assistant.start_continuous:

  on_client_disconnected:
    - if:
        condition:
          switch.is_on: use_wake_word
        then:
          - voice_assistant.stop:
 
  on_end:
    - light.turn_off:
        id: led_light

binary_sensor:
  - platform: status
    name: API Connection
    id: api_connection
    filters:
      - delayed_on: 1s
    on_press:
      - if:
          condition:
            switch.is_on: use_wake_word
          then:
            - voice_assistant.start_continuous:
    on_release:
      - if:
          condition:
            switch.is_on: use_wake_word
          then:
            - voice_assistant.stop:

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
    
    on_turn_off:
      - voice_assistant.stop
      - lambda: id(va).set_use_wake_word(false);
  - platform: restart
    name: "Restart"

light:
  - platform: neopixelbus
    id: led_light
    type: grb
    pin: GPIO32       # DIN pin of the LED Strip
    num_leds: 24      # change the Number of LEDS according to your LED Strip.
    name: "Light"
    variant: ws2812x
    default_transition_length: 0.5s
      
    effects:
      - addressable_scan:
          name: Scan Effect With Custom Values
          move_interval: 50ms
          scan_width: 2
      - addressable_rainbow:
          name: Rainbow Spinner
          speed: 50
          width: 24
      - addressable_rainbow:
          name: Rainbow Fader
          speed: 50
      - addressable_random_twinkle:
          name: Random Twinkle Effect With Custom Values
          twinkle_probability: 50%
          progress_interval: 32ms
      - addressable_flicker:
          name: Flicker Effect With Custom Values
          update_interval: 16ms
          intensity: 100%

How about an automation triggered on HA startup?

That seems to be when HA starts up. Trying to do voice assistant device.

I have mine play an mp3 from HAs www folder using this:

voice_assistant:                        # Voice Assistant
  on_client_connected:
    - media_player.play_media: "http://192.168.5.5:8123/local/Voice_assistant/connected.mp3"

…and similar in on_wake_word_detected: , making it play a short pip sound so you know its heard the wake word and is listening.
You could always use HA to produce an MP3 of it saying something using TTS, by making it say it and then checking the TTS cache folder (\\Your_HA_IP\config\tts) :wink:

Or you could use an automation in HA. Triggering on its API connecting and adding TTS as an action like this:

description: ""
mode: single
trigger:
  - type: connected
    platform: device
    device_id: d9909511c12525c6dd64cc53d6a5959e
    entity_id: e955044baa5e6f59e91484687597288d
    domain: binary_sensor
condition: []
action:
  - service: tts.speak
    metadata: {}
    data:
      cache: true
      media_player_entity_id: media_player.jarvis_media_player
      message: What it should say
    target:
      entity_id: tts.piper

…which is a dead easy way to have it announce/alert anything you like from HA. I use it to have mine tell me when the washing machine’s finished or the kettle’s boiled, that kind of thing.

1 Like

Had a bit more of a play with this today and get on best using this automation in HA:

alias: Assistant Jarvis connected
description: ""
trigger:
  - type: connected
    platform: device
    device_id: d9909511c12525c6dd64cc53d6a5959e
    entity_id: e955044baa5e6f59e91484687597288d
    domain: binary_sensor
    id: connected
    enabled: false
  - platform: state
    entity_id:
      - switch.jarvis_enable_assist
    to: "on"
    id: listening
  - platform: state
    entity_id:
      - switch.jarvis_enable_assist
    to: "off"
    id: not_listening
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - connected
        sequence:
          - service: tts.speak
            metadata: {}
            data:
              cache: true
              media_player_entity_id: media_player.jarvis_media_player
              message: I'm connected
            target:
              entity_id: tts.piper
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 500
      - conditions:
          - condition: trigger
            id:
              - listening
        sequence:
          - service: tts.speak
            metadata: {}
            data:
              cache: true
              media_player_entity_id: media_player.jarvis_media_player
              message: I'm connected and listening
            target:
              entity_id: tts.piper
      - conditions:
          - condition: trigger
            id:
              - not_listening
        sequence:
          - service: tts.speak
            metadata: {}
            data:
              cache: true
              media_player_entity_id: media_player.jarvis_media_player
              message: I'm not listening
            target:
              entity_id: tts.piper
mode: single

Triggered when the switch.jarvis_enable_assist goes either on or off, and reports if it’s ‘listening’ or not.
Covers the device starting and if the switch is toggled once it’s already runnning.

Thanks, still playing with it. My TTS seems not to be working (this automation). It does when I use the “set_conversation_response” other automation.It is saving the mp3 but not speaking it…

I am running HA in a docker container and piper on a separate server with with a low profile 12gb nvidia card. Plan on moving everything to the server with the nvidia card.

Put this under on_wakeword_detected:

    - homeassistant.service:
        service: tts.speak
        data:
          entity_id: tts.your tts engine here
          cache: 'true'
          media_player_entity_id: Your media player here
          message: Your message here