Home Assistant YAML Automations
YAML Style Rules
- 2-space indentation (never tabs)
- Lowercase booleans:
true / false
- Entity IDs:
domain.entity_name (lowercase, underscores)
Automation Template
automation:
- id: "unique_automation_id"
alias: "Descriptive Name"
description: "What this does"
mode: single
trigger:
- trigger: state
entity_id: binary_sensor.front_door
to: "on"
condition:
- condition: time
after: "08:00:00"
before: "22:00:00"
action:
- action: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 100
Common Triggers
- trigger: state
entity_id: sensor.temperature
above: 25
- trigger: time
at: "07:30:00"
- trigger: sun
event: sunset
offset: "-00:30:00"
- trigger: template
value_template: "{{ states('sensor.power') | float > 1000 }}"
- trigger: webhook
webhook_id: "my_unique_webhook_id"
allowed_methods: [POST]
Common Conditions
- condition: state
entity_id: alarm_control_panel.home
state: "armed_away"
- condition: numeric_state
entity_id: sensor.temperature
above: 20
below: 30
- condition: time
after: "08:00:00"
before: "23:00:00"
weekday: [mon, tue, wed, thu, fri]
- condition: template
value_template: "{{ is_state('person.john', 'home') }}"
- condition: and
conditions:
- condition: state
entity_id: input_boolean.guest_mode
state: "off"
- condition: state
entity_id: binary_sensor.motion
state: "on"
Common Actions
- action: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 80
- delay:
seconds: 30
- wait_for_trigger:
- trigger: state
entity_id: binary_sensor.motion
to: "off"
timeout:
minutes: 5
continue_on_timeout: true
- choose:
- conditions:
- condition: state
entity_id: input_select.mode
state: "away"
sequence:
- action: climate.set_temperature
target:
entity_id: climate.thermostat
data:
temperature: 18
default:
- action: notify.mobile_app
data:
message: "Unknown mode"
- repeat:
count: 3
sequence:
- action: light.toggle
target:
entity_id: light.alert
- delay:
seconds: 1
Key Rules
- Use
action: not service: (modern syntax)
- Use
trigger: as type key (not platform:)
- Always include
alias and description
- Use
target: for entity/area/device targeting
- Templates use Jinja2:
"{{ states('sensor.x') }}"
Related Skills
- Scripts →
ha-scripts
- Blueprints →
ha-blueprints
- Device triggers →
ha-device-triggers