Chapter 8

Your first automation

The previous 7 chapters covered your home's structure, naming, dashboards, and notifications. In this chapter, you will create your first automation and bring Home Assistant to life.

Why this matters

Automations are at the heart of Home Assistant—and what sets it apart from an ordinary smart-plug app.

If you use Home Assistant only as a web page for remotely switching lights, it offers little more than Xiaomi or Google Home. Home Assistant becomes truly worthwhile when it can:

  • Act according to the time, such as at sunset or 7:00 every morning.
  • Respond to a sensor, such as when someone enters, the temperature gets too high, or electricity costs exceed a set amount.
  • Evaluate multiple conditions, such as whether someone is home, it is dark, and it is a weekday.

Without automations, Home Assistant is merely an expensive remote control. From this chapter onward, we will turn it into an automated household assistant.

The three-part model: trigger, condition, action

Every Home Assistant automation consists of three building blocks. Remember them, and you will be able to make sense of any example you encounter:

  • Trigger: When Home Assistant should start evaluating the automation—for example, at sunset, when a particular button is pressed, or when the temperature exceeds 28 degrees.
  • Condition: Whether the automation should actually run after it is triggered—for example, turn on the lights only when someone is home, or sound an alarm only on non-holidays. Conditions act as filters.
  • Action: What should actually happen—for example, turn on a light, send a push notification, play music, or close the curtains.
Rule of thumb: A trigger answers “when should Home Assistant check?”, a condition answers “should it proceed?”, and an action answers “what should it do?” Once these three parts are clear, you can assemble even complex automations.

The device_id and entity_id trap

This is widely recognized as one of the biggest pitfalls in the Home Assistant community, and it is why many automations “suddenly stop working” after a while.

When you create an automation in the UI, Home Assistant may use a device as the trigger—for example, “when this living-room light device turns on.” Although this seems intuitive, it ties the automation to the identifier of that physical hardware (device_id). If you replace the light, pair it with Zigbee again, or remove and re-add its integration, the device_id changes. The entire automation may then stop working, with no error message; it simply does nothing.

Rule for this guide: Use entity_id for all automation triggers and actions—for example, light.livingroom_ceiling—rather than device_id. In the UI, choose an “Entity” option rather than a “Device” option.

An entity ID is a logical name: the identifier you assigned yourself in Chapter 4. If you replace a device or reinstall an integration, assign the new device the same entity ID and all entity-based automations can reconnect without further changes.

This is why Chapter 4: Naming and labels matters so much: a good entity ID is the foundation of maintainable automations.

Further reading: Home Assistant community discussion: why and how to avoid device_id.

Hands-on: turn on the living-room light at sunset

We will build the classic “lights on at sunset” example. The goal is to turn on the main living-room light 30 minutes after sunset and send a push notification to your phone.

Terminology has changed: Starting with Home Assistant 2024.8, “Service” was officially renamed “Action.” In the UI, “Call service” became “Perform action.” Starting with 2024.10, the three top-level automation YAML keys also became plural: trigger:triggers:, condition:conditions:, and action:actions:. Within an action, service: became action:, and service_data: became data:. Home Assistant has not removed the legacy syntax, so do not worry when you encounter older examples online. The steps below use the current names; the terms in parentheses are what you may see in an older interface.
  1. Create a new automation

    Go to Settings → Automations & scenes → Create automation, then select Create new automation. Give it a descriptive name, such as “Sunset · Turn on main living-room light.”

    Create a new automation
    Figure 8-1 Start from scratch, and use a name that clearly states “when this happens, do that.”
  2. Set the trigger: Sun

    Select Add trigger, then choose Sun. Set the event to Sunset and enter +00:30:00 as the offset, which means 30 minutes after sunset.

    Configure the Sun trigger
    Figure 8-2 The Sun trigger supports sunrise or sunset, with an offset before or after the event.
  3. Optional: add a condition so it runs only when someone is home

    Select Add condition, choose Numeric state, select zone.home (or the home zone you configured in Chapter 3), and set Above to 0. This prevents the lights from wasting electricity when nobody is home.

    Configure the presence condition
    Figure 8-3 A condition is a filter that Home Assistant evaluates only after the automation is triggered.
  4. Set the action: turn on the light

    Select Add action, choose Perform action (called Call service in older versions), and select light.turn_on. Important: under Targets, choose “Entity” rather than “Device.” Select light.livingroom_ceiling (or the entity ID of your main living-room light). You can set the brightness to 60%.

    Configure the turn-on-light action
    Figure 8-4 Be sure to target the entity ID, as explained in the previous section.
  5. Add a push-notification action

    Select Add action again and choose notify.mobile_app_xxx (the notification action you configured in Chapter 7). Enter the message “The living-room light was turned on at sunset.”

    Add a push-notification action
    Figure 8-5 You can chain multiple actions; Home Assistant runs them in sequence.
  6. Save and test

    Select Save in the lower-right corner and confirm the name. Return to the automation list, open the automation you just created, and select Run actions to test it manually. Confirm that the light turns on and your phone receives the notification.

    Save and test the automation
    Figure 8-6 Running the actions manually bypasses the trigger and conditions, allowing you to test the actions directly.
Verify: At the actual time 30 minutes after sunset, the light should turn on. Do not change your phone's clock; that will not alter Home Assistant's sunset trigger. For an immediate action test, go to Settings → Automations & scenes, open the automation, and select Run actions. If your phone receives “The living-room light was turned on at sunset,” the light and notification actions work. To test the complete trigger → condition → action → notification path, temporarily use a safe trigger that will occur soon, verify the result, and then restore the sunset trigger.

Run modes: single, restart, queued, and parallel

What should happen if an automation is triggered again while it is still running? Its run mode determines the answer. You can find the Mode setting at the bottom of the automation editor.

Mode Behavior Best suited to
single (default) Ignores a new trigger while the previous run is still in progress Automations that simply need to finish once, such as sunset lighting or a daily backup
restart Stops the previous run when a new trigger arrives, then starts again from the beginning Turning on a light when motion is detected, then turning it off after 5 minutes (the timer restarts whenever motion is detected)
queued Queues new triggers and runs them in order after earlier runs finish Doorbell chimes that must play one at a time, or bursts of many events in a short period
parallel Runs multiple instances at the same time Uncommon cases that explicitly require concurrent runs

If you are unsure, leave the mode set to single; it is the safest default.

Blueprints: import ready-made automations

Blueprints are Home Assistant's official automation-template system. The author defines the logic and exposes the customizable parts as form fields, so you can create a working automation simply by completing a few selections.

Common uses include:

  • Assigning actions to Zigbee buttons, including IKEA, Aqara, and Hue remotes
  • Turning on lights when motion is detected, then turning them off after a timeout
  • Sending notifications when a washer or dryer finishes
  • Sending low-battery alerts

To import a Blueprint:

  1. Find the Blueprint you want on the Home Assistant Blueprint Exchange forum or GitHub, then copy its URL.
  2. In Home Assistant, go to Settings → Automations & scenes → Blueprints → Import Blueprint, then paste the URL.
  3. Return to Automations, select Create automation from Blueprint, choose the Blueprint you imported, and complete its device and entity fields.
Recommendation: Build an automation yourself first, as you did in this chapter, before relying on Blueprints. If a Blueprint later causes trouble, you will know how to inspect and modify it.

Troubleshooting

Problem 1: The automation did not run, and there is no error message.

Open the automation from the list and select Traces in the upper-right corner. This view shows the complete path of the five most recent runs: which trigger fired, whether the conditions passed, and how far the actions progressed. Examining a trace is the first troubleshooting step and is usually more direct than checking the logs.

Problem 2: The trigger fired, but a condition blocked the automation.

The trace uses color to show what happened. If a condition appears gray or white, it did not pass; hover over it to see the entity's value at that moment. Common causes include zone.home being 0 because nobody is home, or a time condition that does not match your time zone.

Problem 3: An entity ID is misspelled or has been renamed.

If you change an entity ID, an existing automation may retain the old reference and quietly stop working. Home Assistant versions released since 2024 have added tools for finding unused entities and prompts for updating references after a rename. For older automations, run a manual validation from Settings → Tools → YAML → Check configuration (Settings → Tools → YAML; this page was called Developer Tools in older versions, moved under Settings in 2026.2, and was simplified to Tools in 2026.8).

Frequently asked questions

Can one automation call another automation?
Yes, but a Script is usually the better choice. A Script is a reusable sequence of actions that multiple automations can call, and you can also add a dashboard button to run it manually. Create one under Settings → Automations & scenes → Scripts.
Should I create automations in the UI or write them in YAML?
Beginners should use the UI: its error messages are easier to understand, and it provides Trace debugging. YAML is better suited to experienced users who need version control or want to copy configurations between multiple Home Assistant installations. Automations created in the UI are stored as YAML behind the scenes and can be exported at any time.
Why is my sunset trigger so far from the actual time it gets dark?
Home Assistant calculates sunset from the latitude and longitude configured in Chapter 2. If those coordinates are missing, it uses defaults—which may point to Germany—and the time will be wrong. Check them under Settings → System → Home information (called General in older versions).
Can I temporarily disable an automation, for example while I am abroad?
Yes. Use the switch on the right side of the automation list to disable it directly. Alternatively, create an input_boolean helper as a “Vacation mode” switch and reference it in the automation's conditions. You can then toggle vacation mode from your dashboard.