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 domainscript and are implemented in homeassistant/components/script/.
Script Entity
Each script is represented as an entity that extendsToggleEntity and RestoreEntity:
Key Properties
entity_id: Format isscript.<script_name>state: Either “on” (running) or “off” (not running)last_triggered: Timestamp of last executionmode: Execution mode (single, restart, queued, parallel)current: Number of currently running executionsmax: 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:| Mode | Behavior |
|---|---|
single | Ignore new calls while running (default) |
restart | Stop current run and start new one |
queued | Queue new runs to execute sequentially |
parallel | Run multiple instances in parallel |
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:- 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: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:entity_id: The script entityname: Script namevariables: Variables passed to script
Common Patterns
Notification Script
Device Control
Related Resources
Automations
Learn how scripts integrate with automations
Scenes
Understand scene activation patterns
Service Calls
Explore the service call system
Templates
Master templating in scripts