Once Home Assistant is installed and a few devices are connected, the next screen you meet is automations.
Open automations in settings and you get three sections: When, And if, and Then.
On the first pass it is not obvious what belongs where, and I stayed stuck on that screen for a while.
My first attempt was an entry light that should come on when the door opened. It never did, and I spent the next morning working out why. The condition was sitting in the trigger slot, so there was nothing for it to check against.
What I did not know then is that a condition gets one look at the instant the trigger fires. This post goes through what each of the three slots does, how the same thing reads in YAML, and where people usually get stuck.
1. Three slots and what each does
The official definition is short. An automation needs at least a trigger and an action. A condition is optional, and it filters the actions.
A trigger is the event that starts the automation.
The sun sets, a door opens, a button gets pressed.
An action is what Home Assistant actually does at that moment.
Turn on a light, change a temperature, send a notification.
A condition is the checkpoint a started automation has to pass.
It is checked when the trigger fires, and if it does not pass, the actions never happen.

The door opens (trigger), it is night and someone is home (condition), the hallway light comes on (action).
Any automation with all three slots fits into a line like that.
2. When a condition is checked
This is the part that catches most people.
A condition is not re-checked later. It gets one look at the instant the trigger fires, and that is it.
The example in the official docs makes it click. Say an automation turns the lights on when someone comes home after sunset.
If someone is already home before sunset, nothing happens at sunset.
The condition was not wrong. The moment to check it had already gone by.
Before I understood that, I re-paired the sensor and rebuilt the automation twice. None of it was the problem.

So "turn the light on at sunset" needs the sun as the trigger, while "turn the light on when I get home after dark" needs arrival as the trigger.
Deciding the action first, then asking whether the moment belongs in the trigger slot or the condition slot, keeps the two from swapping places.
3. What goes in the trigger slot
These are the triggers that come up in practice.
- State: a door sensor opening, a person entity switching to home
- Time: a fixed clock time, like 7:00 every morning
- Sun: sunrise or sunset, with an offset if you want it to run 30 minutes earlier
- Numeric state: temperature or humidity crossing a value, optionally only after it stays there a while
- Zone: entering or leaving an area you defined as home
- Event or webhook: another device or service sending a signal
You can add more than one trigger. Any one of them starts the automation.
Start with one. With several, the first question in the trace becomes which one actually fired.
4. More than one condition
With no condition, every trigger runs the actions.
A condition narrows that down.
Multiple conditions are all required by default.
Wrap them in an Or block when any one is enough, and use Not to invert one.
The ones I reach for are state, time, and template conditions. A time condition is how you keep an automation inside 22:00 to 06:00.
There is a trap here too.
Conditions are evaluated top to bottom, and anything after a failing condition is skipped.
Put a condition in the middle of the action list and the actions before it have already run.
That is how you build "do this much, then skip the rest depending on a condition".
5. Where service became action
Actions are service calls. Turn on a light, set a temperature, activate a scene, send a notification.
An action carries a target and some data.
The target is which device it applies to. The data holds the details, like brightness or a message body.
Older docs and blog examples often write that slot as service:. Current official examples use action:.
It is the same slot under a new name, so when you copy an example, just check which one it is written with.
6. What it looks like in YAML
Automations built in the UI are stored as YAML. Open one, use the menu in the top right, and pick edit in YAML.
Three keys are all you need to read it.
The list under triggers is when to start, conditions is the filter, and actions is the work.
List items start with a hyphen and lean on indentation for hierarchy.
Indentation scared me most at first. Two spaces off and it quietly does not run.
- alias: "Entry light on when arriving after dark"
id: "evening_entry_light"
triggers:
- trigger: state
entity_id: person.me
to: "home"
conditions:
- condition: sun
after: sunset
actions:
- action: light.turn_on
target:
entity_id: light.entry
Someone arrives home and it is after sunset, so the entry light comes on.
The condition is a time check, judged only when the trigger fires. Arrive during the day and nothing happens.
If you would rather get a notification when humidity climbs, only the trigger changes.
triggers:
- trigger: numeric_state
entity_id: sensor.living_room_humidity
above: 70
for: "00:10:00"
actions:
- action: notify.notify
data:
message: "Living room humidity has been above 70% for 10 minutes"
One caution. automations.yaml is managed by the UI and should not be edited by hand.
If you want to manage automations yourself, put them in a separate automation block in configuration.yaml, and reload automations after every edit.
7. Sensor values in a notification
Sooner or later you want a number in the message. That is what templates are for.
An expression between double braces is replaced with the value at run time.
actions:
- action: notify.notify
data:
message: "Living room is {{ states('sensor.living_room_temperature') }}C, humidity {{ states('sensor.living_room_humidity') }}%"
Templates work in conditions too, for example to notify only when nobody is home.
A small syntax mistake can quietly produce an empty value, though.
That kind of failure cost me a notification once. An error message is easy to chase. An empty value looks like it worked.
Check the result in the template editor under developer tools before you rely on it.
8. When it does not run
Matching "what I want" to "which slot" clears up most of the confusion.
| What you want | Which slot |
|---|---|
| Run only after 22:00 | Condition (time) |
| Start at 22:00 | Trigger (time) |
| Only when someone is home | Condition (state) |
| When someone arrives | Trigger (state) |
| Notify only at night | Condition (sun) |
| Notify at sunset | Trigger (sun) |
If that does not settle it, these are the next four.
- More than one trigger: if behavior depends on which one fired, give each trigger an id and branch on it in the conditions.
- Overlapping runs: the default mode is single, so a second trigger during a run is ignored and only logged as a warning. Something like motion turning a light on and off after three minutes is easier in restart mode, which stops the run in progress and starts over.
- Not knowing where it broke: with an id on the automation, Home Assistant keeps a trace, five of them by default. That is where you see whether it stopped at a condition or failed in an action.
- YAML edits that do nothing: usually it was saved and never reloaded.
9. Start with notifications
For a first automation, sending a notification beats moving a device.
A light that stays off tells you nothing about where the chain broke. A notification either arrives or it does not.
Once it arrives, keep the same trigger and condition and swap the action for turning on a light.
Then build it up in order: door opens, notify. Notify only at night. At night, turn on the hallway light.
Doing it that way makes it obvious which link is the problem. One automation that runs reliably beats five built at once.
10. Past ten automations
Two automations turn into ten faster than you expect, and from then on finding and fixing one is harder than writing it.
A naming rule pays off the most. If the name says whether it is lighting, ventilation, or a notification, the list stays readable.
Automations are entities, so they can be switched off.
When testing a new one, turning the others off for a minute is faster than untangling which one fired.
When several automations repeat the same work, move it into a script.
One script for a shared message or a group of devices means editing the text in one place later.
Even past ten automations, the first one is the one I remember.
Watching the hallway light come on because a door opened is a small thing, and I still grinned at it alone in the hallway.
Since then it has saved me a few trips across the room every day. Rather than building something grand, pick the one thing you keep doing by hand and move that into an automation first.
When it stops working, check whether the moment belongs in the trigger or the condition before anything else. Most of the time, that is where it is.
References
Home Assistant, Automations basics
https://www.home-assistant.io/docs/automation/basics/
Home Assistant, Automation YAML
https://www.home-assistant.io/docs/automation/yaml/
Home Assistant, Automation modes