home-assistant.io/source/_integrations/intent_script.markdown
Didgeridrew 4162fe535f
Very Small PR: Edit example intent_script.markdown (#37535)
This is a single character edit to fix a non-functional example.
2025-02-19 06:16:23 +01:00

3.6 KiB

title description ha_category ha_release ha_quality_scale ha_domain ha_integration_type
Intent Script Instructions on how to setup scripts to run on intents.
Intent
0.50 internal intent_script integration

The intent_script integration allows users to configure actions and responses to intents. Intents can be fired by any integration that supports it. Examples are Alexa (Amazon Echo), Dialogflow (Google Assistant) and Snips.

If you are using intent script with LLMs and have parameters, make sure to mention the parameters and their types in the description.

{% raw %}

# Example configuration.yaml entry
intent_script:
  GetTemperature:  # Intent type
    description: Return the temperature and notify the user
    speech:
      text: We have {{ states('sensor.temperature') }} degrees
    action:
      action: notify.notify
      data:
        message: Hello from an intent!

{% endraw %}

Inside an intent we can define these variables:

{% configuration %} intent: description: Name of the intent. Multiple entries are possible. required: true type: map keys: description: description: Description of the intent. required: false type: string platforms: description: List of domains that the entity supports. required: false type: list action: description: Defines an action to run to intents. required: false type: action async_action: description: Set to True to have Home Assistant not wait for the script to finish before returning the intent response. required: false default: false type: boolean mode: description: The script mode in which to run the intent script. Use this to define if the intent should be able to run multiple times in parallel. required: false default: single type: string card: description: Card to display. required: false type: map keys: type: description: Type of card to display. required: false default: simple type: string title: description: Title of the card to display. required: true type: template content: description: Contents of the card to display. required: true type: template speech: description: Text or template to return. required: false type: map keys: type: description: Type of speech. required: false default: plain type: string text: description: Text to speech. required: true type: template {% endconfiguration %}

Using the action response

When using a speech template, data returned from the executed action are available in the action_response variable.

{% raw %}

conversation:
  intents:
    EventCountToday:
      - "How many meetings do I have today"

intent_script:
  EventCountToday:
    action:
      - action: calendar.get_events
        target:
          entity_id: calendar.my_calendar
        data_template:
          start_date_time: "{{ today_at('00:00') }}"
          duration: { "hours": 24 }
        response_variable: result                     # get action response
      - stop: ""
        response_variable: result                     # and return it
    speech:
      text: "{{ action_response['calendar.my_calendar'].events | length }}"   # use the action's response

{% endraw %}