Advanced Automation Techniques in Home Assistant
After learning the basics of automations in Home Assistant, you might want to do more with your smart home. This page covers some additional features you can use to make your automations more flexible and powerful. While we are referring to these as "advanced," there's nothing special or difficult about them once you understand how they work - they are simply extra tools you can use if you need them. Beginners don't need to worry about these right away, but you can come back to this guide as you want to do more with your automations.
Chaining Automations and Scripts
Sometimes, you want one automation or script to trigger another. For example, you might have a morning routine script that should run after your "Wake Up" automation completes. There are two main ways to call another script in Home Assistant, and it's important to understand the difference:
- Calling a script directly (e.g.,
script.script_name):
This makes the calling script wait for the called script to finish before moving on. If the called script has an error and stops, the original script will also stop.
This is a good choice if your automation depends on the other script completing successfully before moving on. -
This starts the other script "in the background" and moves on immediately, so both scripts run at the same time. If the called script fails, it won't affect the original script.
This is useful when you want things to happen in parallel, or you don't want errors in the background script to stop your main automation.
Example:
In this pattern,script_1launchesscript_2and continues to perform other actions whilescript_2runs in the background. When you reach thewait_templateline,script_1will pause untilscript_2has finished, then resume its next steps. This allows your automation to keep running even ifscript_2encounters an error.
Which method should you use?
For most automations, script.turn_on is the better default. It gives you more flexibility and prevents a problem in one script from stopping the whole chain. Only call scripts directly if you specifically need the calling script to wait and fail together with the called script.
Parallel vs. Sequential Actions
By default, Home Assistant runs actions in an automation or script one after another, waiting for each to finish before moving to the next. This is called sequential execution. But sometimes you want actions to happen at the same time - for example, turning on lights in several rooms at once. This is where parallel execution comes in.
-
Sequential (default):
Actions run one after another. If you have adelayorwaitstep, all following actions wait until it finishes. -
Parallel execution:
Use theparallel:action to run several sequences at the same time. For example:
Each action underaction: - parallel: - action: light.turn_on target: entity_id: light.kitchen - action: light.turn_on target: entity_id: light.living_roomparallel:runs independently - no waiting for the others to finish.
When to use parallel? If you want actions to happen at the exact same time (e.g. turning on lots of devices, sending multiple notifications), use parallel:. Otherwise, stick with sequential for simplicity.
Wait Templates and Wait For Trigger
Sometimes, you want your automation to pause and wait for something before continuing - like a door being opened, or a sensor reporting a value. Home Assistant provides two ways to do this:
- Wait Template:
Pauses the automation until a template evaluates as true. Example:
This waits up to 10 minutes for the front door to open.- wait_template: "{{ is_state('binary_sensor.front_door', 'on') }}" timeout: "00:10:00" continue_on_timeout: false - Wait for Trigger:
Waits for a specific event or state change (same format as automation triggers). Example:
This waits up to 30 minutes for the mailbox sensor to detect mail.- wait_for_trigger: - platform: state entity_id: binary_sensor.mailbox to: "on" timeout: "00:30:00"
Note: If the condition isn't met within the timeout, you can choose to continue or stop the automation.
Using Blueprints for Reusable Automations
Blueprints are templates for automations - they let you create a reusable automation "recipe" that others (or yourself) can use and customize. With blueprints, you define what options (like entities, times, or triggers) are configurable, and Home Assistant generates a UI for you to fill in those blanks.
- Benefits: Share automations with the community, avoid repeating yourself, and make automations easy to adjust without editing YAML.
-
How to use: Go to Settings > Automations & Scenes > Blueprints to import and use blueprints from the community - or create your own by defining
blueprint:at the top of a YAML automation.
Example: A motion-activated light blueprint lets you choose which motion sensor and light to use, as well as how long to keep the light on.
Other Advanced Techniques
-
Variables:
Store values to use later in your automation. Variables can be set using the
variables:action. - Choose (Conditional Branching): Perform different actions based on conditions, similar to "if-else" logic.
action: - choose: - conditions: "{{ is_state('sun.sun', 'above_horizon') }}" sequence: - action: light.turn_on target: entity_id: light.outdoor_lights - conditions: "{{ is_state('sun.sun', 'below_horizon') }}" sequence: - action: light.turn_off target: entity_id: light.outdoor_lights -
Loops and Repeat:
Repeat a sequence of actions a set number of times, or while a condition is true, using the
repeat:action. -
Stopping Automations:
You can stop an automation (and optionally provide a response variable for scripts and advanced integrations) using the
stop:action.
Summary
Mastering advanced automation techniques lets you create truly powerful, flexible, and maintainable smart home routines. By combining chaining, parallel actions, blueprints, wait steps, variables, and branching logic, you can automate even the most complex scenarios - while keeping your YAML clean and your automations easy to manage.
Don't be afraid to experiment! If you ever get stuck, check out the automation editor's "trace" and "debug" features to see exactly what's happening in your automations.