Home Assistant Automations Explained: Triggers, Conditions and Actions

Every Home Assistant automation is one sentence: when something happens, if the situation is right, then do something. Those three parts — trigger, condition and action — are the whole model. Once that sentence clicks, the automation editor stops being a form to guess at and becomes a tool you can reason with, and debugging stops being superstition and becomes checking which part of the sentence failed.

Published Nov 17, 2026 · Last updated Nov 18, 2026

This guide explains each part with examples you can copy, covers the four automation modes that quietly cause most “it fired twice” mysteries, and ends with a debugging method that finds the broken part in minutes instead of evenings.

What you need

The three parts, precisely

A trigger is an event, a moment in time: a door opened, the sun set, motion started, a phone entered a zone. Triggers are not states. “The door is open” does not trigger anything; “the door changed from closed to open” does. A condition is a test applied at the moment the trigger fires: is it after sunset, is anyone home, is the door still open? Conditions never start anything — they only allow or block. An action is what runs when the trigger fires and every condition passes: turn on a light, send a notification, wait ten minutes and check again. Holding those definitions firmly prevents almost every beginner mistake.

Flow diagram showing a trigger event passing through a condition check before running actions
The whole model in one line: an event fires the trigger, conditions decide whether to proceed, and actions do the work.

Step-by-step: build a porch light automation

  1. Create the automation and name it like a sentence. Go to Settings, then Automations & scenes, then Create automation. Name it “Porch light on when the front door opens after dark”. A name that states the trigger and the condition saves you opening the automation to remember what it does, and it makes the traces list readable months later.
  2. Add a state trigger. Choose a state trigger on your front door contact sensor, from closed to open — in entity terms, from off to on for most contact sensors. Leaving the from and to fields blank would fire on every change, including battery updates on some devices, so be specific whenever you can.
  3. Add the condition that makes it polite. Add a sun condition, after sunset and before sunrise. Now the sentence reads correctly: opening the door at noon does nothing, because the trigger fired but the condition blocked it. This separation is why you should resist cramming time logic into triggers — conditions are where “only when” belongs.
  4. Add the first action. Call the light turn-on service on the porch light, with a brightness that suits an entryway rather than a stadium. Test it now with the Run action button in the editor — note that running manually skips the trigger and, depending on how you invoke it, may skip conditions too, so a successful manual run proves the action works, not that the whole sentence does.
  5. Add a timed off, the careful way. Add a wait for a trigger — the door closing — with a timeout of ten minutes, then turn the light off. Prefer waiting on an event like this over a blind fixed delay: if someone is loading shopping through the door, a blind timer turns the light off on them, while an event-based wait responds to what the house is actually doing.
  6. Choose the mode deliberately. Open the automation settings and set the mode. Single mode ignores new triggers while the automation is already running — right for this porch light. Restart mode cancels the current run and starts again — right for motion lighting, where each new motion should extend the timer. Queued and parallel modes have real uses, explained below, but they should be a choice, not a surprise.
  7. Save, then test the whole sentence. Wait for the condition to be true, or temporarily adjust it, then open the door for real. If it works, open the automation's Traces view and look at the run: it shows the trigger, each condition result and each action step. Learning to read traces now will save you hours later.

The same automation in YAML

automation:
  - alias: "Porch light when front door opens after dark"
    description: "Entry light for arrivals after sunset"
    trigger:
      - platform: state
        entity_id: binary_sensor.front_door_contact
        from: "off"
        to: "on"
    condition:
      - condition: sun
        after: sunset
        before: sunrise
    action:
      - service: light.turn_on
        target:
          entity_id: light.porch
        data:
          brightness_pct: 80
      - wait_for_trigger:
          - platform: state
            entity_id: binary_sensor.front_door_contact
            to: "off"
        timeout: "00:10:00"
        continue_on_timeout: true
      - service: light.turn_off
        target:
          entity_id: light.porch
    mode: single

Read the wait in the middle carefully, because it decides when the light goes off. The light turns off when the door closes — or after 10 minutes if the door is still open. The timeout with continue_on_timeout: true is a deliberate safety fallback: if the door is left ajar, or the close event is ever missed, the automation carries on to the turn-off step anyway instead of leaving the porch light on all night.

Diagram of the four automation modes: single, restart, queued and parallel, with overlapping runs shown differently for each
The four modes decide what happens when a trigger fires while a previous run is still going — the hidden cause of most double-firing mysteries.

The four modes, in plain language

Single ignores new triggers until the current run finishes; use it for doorbells, alerts and anything where a duplicate is worse than a miss. Restart stops the current run and starts fresh; use it for motion lights and timers that should extend. Queued lines up runs and executes them in order, up to a limit you set; use it rarely, for sequences that must each complete. Parallel lets runs overlap freely; use it when each trigger is independent, such as logging or notifying per event. If an automation behaves strangely under repeated triggers, the mode is the first thing to check.

Common mistakes and troubleshooting

Official documentation and references

FAQ

Should I write automations in the visual editor or in YAML?

Both produce the same automations. The visual editor is safer while learning and shows you valid options; the YAML view behind it, available from the menu in the editor, teaches you the structure. Pick per automation, and never hand-edit the automations file while also expecting the editor to track your changes unless you understand how storage mode works.

What is the difference between a script and an automation?

An automation is a trigger plus actions; a script is just the actions, saved to run on demand or be called by several automations. When two automations share the same sequence — the same “goodnight” routine, for example — move that sequence into a script and call it from both.

Why did my automation fire when Home Assistant restarted?

Some triggers, especially state triggers without specific from and to values, can match as entities settle after a restart, and time-pattern triggers can align unexpectedly. Tighten from and to states, and for sensitive automations add a condition that Home Assistant has been running for a few minutes using an uptime sensor.

Related guides