What makes up an automation
An automation has three parts. A trigger decides when it starts, such as a motion sensor turning on or a set time arriving. Conditions are optional checks that must pass before it continues, such as “only after sunset.” Actions are the steps it runs, such as turning on a light or sending a notification.
Most of the work happens in the actions, so it helps to know how they are named.
Services are now called actions
Home Assistant used to call these commands services. From version 2024.8 the name became actions. The idea is the same. Each action has a name in the form domain.action, for example light.turn_on, notify.mobile_app_<device> or rest_command.<name>.
In YAML, the key is action::
automation:
- alias: "Kitchen light at sunset"
triggers:
- trigger: sun
event: sunset
actions:
- action: light.turn_on
target:
entity_id: light.kitchen
data:
brightness_pct: 60
The older service: key still works, so existing automations do not need rewriting just to change the key.
Targets can point at entities, devices, areas, floors and labels. To try an action before putting it in an automation, open Developer Tools > Actions. This tab was called Services before the rename.
Automation keys were renamed in 2024.10
From 2024.10, the automation keys are plural: triggers:, conditions: and actions:. Each trigger names its type with trigger:, where older YAML used platform:. The old keys are still accepted, but the examples in this guide use the newer ones.
Automation modes
The mode: setting controls what happens when an automation is triggered during a run that is already in progress:
single(the default): the new trigger is ignored, and Home Assistant logs an “Already running” message.restart: the current run stops and a new one starts.queued: new runs wait in line.parallel: runs happen side by side.
For queued and parallel, the default limit is 10 runs. Motion lights are a common case for restart, because new motion should extend the off-timer. Use single when overlapping runs could cause problems.
Flow control and actions that return data
Sequences can wait and branch with actions such as delay, wait_template, wait_for_trigger, choose, if / then / else, repeat, parallel and stop. To keep a sequence running after one step fails, set continue_on_error: true on that step.
Some actions return data, such as a weather forecast. Store the returned data with response_variable::
actions:
- action: weather.get_forecasts
target:
entity_id: weather.home
data:
type: daily
response_variable: forecast
REST commands: sending HTTP requests
A REST command lets Home Assistant send an HTTP request to a device or web service when an automation calls it. Common examples are a gate controller’s web endpoint and a status update sent to a web service.
REST commands are set up in configuration.yaml, not in the UI. Restart Home Assistant after you add or change one.
rest_command:
open_gate:
url: "http://192.168.1.50/open"
method: get
update_status:
url: "https://example.com/api/status"
method: post
headers:
Authorization: !secret status_api_token
Accept: "application/json"
content_type: "application/json; charset=utf-8"
payload: '{"status": "{{ status_text }}"}'
Replace the addresses with your own. The status_api_token value lives in secrets.yaml.
The main options:
urlis required and can contain templates.methoddefaults toget. Other methods includepost,put,patchanddelete.headersandpayloadcan contain templates. Pairpayloadwithcontent_typefor JSON or form data.timeoutdefaults to 10 seconds.verify_ssldefaults totrue. Set it tofalseonly for a trusted local device with a self-signed certificate.username,passwordandauthentication(basicordigest) cover common logins.
Call a REST command like any other action. Values in data: become template variables inside the command:
automation:
- alias: "Post status when working from home"
triggers:
- trigger: state
entity_id: input_boolean.work_mode
to: "on"
actions:
- action: rest_command.update_status
data:
status_text: "Working from home"
In recent versions you can capture a REST command’s result with response_variable, which gives access to the status, content and headers. Check the release notes for your version before relying on it.
Three things that look similar
rest_commandsends a request out from Home Assistant when an automation calls it.- The RESTful sensor (the
rest:platform) polls a web API on a schedule and turns the results into sensors. Use it when you want values on a dashboard. - Webhook triggers receive requests sent to Home Assistant from outside. They are a separate feature.
If you want values on a dashboard, use the RESTful sensor. If you want an automation to send a request, use rest_command.
Debugging automations
Open an automation and select Traces to see recent runs. Home Assistant keeps the last five by default. A trace shows which steps ran, which condition stopped the run, and which action failed. If no trace appears, the trigger never fired.
Running an automation with Run actions skips its triggers and conditions, so a successful manual run does not prove that the trigger works. For a full walkthrough, see our guide to why an automation isn’t triggering.
Keep credentials and connections safe
- Put API keys and tokens in
secrets.yamland reference them with!secret. - Remove tokens and passwords from any YAML you post on a forum or share in a support thread.
- Turn
verify_ssloff only on a trusted local network, since it leaves traffic open to interception. - Do not expose Home Assistant to the internet without HTTPS and strong logins. Turn on two-factor authentication.
Where to go next
- For reusable values, see variables and helpers.
- For alerts on your phone or dashboard, see notifications.
- For ready-made automations, see how to import and use blueprints.
- For a practical trigger example, see how to turn on lights with a motion sensor.