Automation asks a question and wait for a response

I want to create an automation that will ask a question and wait for a response. But I need to process that response within the automation.

I currently have two use cases in mind:

  1. When my garage door opens as I arrive, I want the VPE that I have in my garage to ask “is Don there” every 60 seconds until I say yes. Then when I do so, read out the items on a specific task list (the “returning home list”) that contains a list of things I need to do when I arrive home.

  2. In the past, when my alarm goes off I have sometimes turned it off while I was still sleeping. So when it is time for the alarm, I want my bedroom VPE to sound an alarm. When I tell it to stop or press the button, I want it to select 2 random single-digit numbers and tell me to add them together. If I give it the correct answer, it’ll cancel the alarm otherwise, it’ll start playing the alarm again. If 5 minutes pass and the sensor in the hallway hasn’t detected my presence, the alarm starts again and can’t be stopped unless a button on the dashboard in the hall (or my phone) is pressed.

This can be done, but will require a few edits to the satellite configuration file.
You will need an event that returns your response.

    on_stt_end:
      - homeassistant.event:
          event: esphome.stt_text
          data:
            text: !lambda return x;

Also, a button to stop the pipelines would be useful if you don’t need a response from the LLM

button:
  - platform: template
    name: "VA stop"
    on_press:
      then:
        - voice_assistant.stop:

Here is an example of my integration, which by presence sensor asks me if I need light. Your task will require more work with variables, but I think you’ll figure it out.

triggers:
  - trigger: state
    entity_id:
      - binary_sensor.psbr
    to: "on"
conditions: []
actions:
  - action: assist_satellite.start_conversation
    metadata: {}
    data:
      preannounce: true
      start_message: Shall I turn on the light for you?
    target:
      entity_id: assist_satellite.esp32va02_assist_satellite
  - wait_for_trigger:
      - event_type: esphome.stt_text
        trigger: event
    timeout:
      seconds: 10
    continue_on_timeout: false
  - if:
      - condition: template
        value_template: "{{ 'yes' in wait.trigger.event.data.text | lower }}"
    then:
      - action: button.press
        metadata: {}
        data: {}
        target:
          entity_id: button.esp32va02_va_stop
      - action: light.turn_on
        data: {}
        target:
          entity_id: light.yeelight_ceil29_0x13e3b603

There is an option to not use assist_satellite.start_conversation. Instead, just call the tts service, then call voice_assistant.start

Instead of buttons, you can call actions via api if you add this entry:

api:
...
   actions:
    - action: start_va
      then:
        - voice_assistant.start
    - action: stop_va
      then:
        - voice_assistant.stop
1 Like