Skip to main content
Scripts are reusable sequences of actions that can be called from automations, scenes, or manually triggered. They provide a way to organize and reuse complex action sequences.

What is a Script?

A script is a named sequence of actions that can be executed on demand. Unlike automations, scripts don’t have triggers - they must be explicitly called via a service call.

Script Structure

Scripts are entities with the domain script and are implemented in homeassistant/components/script/.

Script Entity

Each script is represented as an entity that extends ToggleEntity and RestoreEntity:

Key Properties

  • entity_id: Format is script.<script_name>
  • state: Either “on” (running) or “off” (not running)
  • last_triggered: Timestamp of last execution
  • mode: Execution mode (single, restart, queued, parallel)
  • current: Number of currently running executions
  • max: Maximum number of parallel/queued executions

Script Definition

Scripts are defined with the following structure:

Execution Modes

Scripts support different execution modes when called while already running:

Script Fields

Scripts can accept input parameters through fields:

Variables

Scripts can define variables for use throughout the sequence:

Calling Scripts

From YAML

From Python

Script Actions

Scripts support all the same actions as automations:

Service Calls

Delays

Waits

Conditional Execution

Repeat Actions

Script Management

Services

Helper Functions

The script component provides helper functions:

Tracing

Scripts support execution tracing for debugging:
Traces provide:
  • Execution timeline
  • Variable values at each step
  • Action results
  • Execution duration

Blueprints

Scripts can use blueprints for reusability:

Response Data

Scripts can return response data:
Call with response:

Best Practices

Descriptive Names

Use clear aliases and descriptions for better maintainability.

Parameterization

Use fields to make scripts reusable with different parameters.

Proper Mode

Choose execution modes that match your script’s behavior.

Error Handling

Use conditions and choose blocks to handle different scenarios.

Documentation

Include descriptions for fields to help users understand parameters.

Events

Script execution fires events:
Event data includes:
  • entity_id: The script entity
  • name: Script name
  • variables: Variables passed to script

Common Patterns

Notification Script

Device Control

Automations

Learn how scripts integrate with automations

Scenes

Understand scene activation patterns

Service Calls

Explore the service call system

Templates

Master templating in scripts