What is an Automation?
An automation is a rule that consists of three main components:- Triggers: What starts the automation
- Conditions: Optional checks that must pass for actions to execute
- Actions: What happens when triggered (and conditions pass)
Automation Structure
Automations in Home Assistant are represented as entities with the domainautomation. The automation component is implemented in homeassistant/components/automation/.
Automation Entity
Each automation is an entity that extendsToggleEntity and RestoreEntity:
Key Properties
entity_id: Format isautomation.<automation_name>state: Either “on” (enabled) or “off” (disabled)last_triggered: Timestamp of last executionmode: Execution mode (single, restart, queued, parallel)
Triggers
Triggers define when an automation should run. Common trigger types include:State Triggers
Fire when an entity changes state:Time Triggers
Fire at specific times:Event Triggers
Fire when an event occurs:Numeric State Triggers
Fire when a numeric value crosses a threshold:Home Assistant supports many more trigger types including sun, zone, template, webhook, and more.
Conditions
Conditions are optional checks that must evaluate to true for the automation’s actions to execute.Common Condition Types
Actions
Actions define what happens when the automation is triggered (and conditions pass).Service Calls
Sequences
Actions can include delays and multiple steps:Conditional Actions
Usechoose for conditional action execution:
Automation Modes
Automations support different execution modes when triggered while already running:Variables
Automations can use variables for dynamic behavior:Trigger Variables
Variables available in automation context:trigger.platform: Trigger platform that firedtrigger.entity_id: Entity that triggeredtrigger.from_state: Previous state objecttrigger.to_state: New state objecttrigger.event: Event object (for event triggers)
Managing Automations
Services
Automations respond to standard services:Reload Automations
Automation Helper Functions
The automation component provides helper functions for working with automations:Tracing and Debugging
Home Assistant provides tracing capabilities for automations:- Execution path through the automation
- Trigger data
- Variable values at each step
- Action results
- Timing information
Blueprints
Blueprints allow you to create reusable automation templates:Creating Automations Programmatically
Best Practices
Meaningful Names
Use descriptive aliases that explain what the automation does.
Use Conditions
Avoid unnecessary action executions by using appropriate conditions.
Choose the Right Mode
Select an execution mode that matches your automation’s behavior requirements.
Enable Tracing
Use trace storage for debugging complex automations.
Test Thoroughly
Test automations manually using the trigger service before relying on them.
Events
Automations fire events that can be used for monitoring:automation_triggered: Fired when an automation is triggeredautomation_reloaded: Fired when automations are reloaded
Related Resources
Scripts
Learn about reusable action sequences
Scenes
Understand scene activation and management
Triggers
Explore available trigger platforms
Conditions
Learn about condition types