Skip to content

Your First Automation

Easy 15 min

Now the fun begins! Automations are why we bother with all this. Lights turning on when you come home. Heating turning down when you leave.

Automation flow diagram

All automations have three parts:

PartDescriptionExample
TriggerWhat starts itSun sets, motion detected
ConditionOptional checkOnly if home, only at night
ActionWhat happensTurn on light, send notification

Think of it as: “When X happens, and if Y is true, then do Z.”

The classic first automation!

  1. Go to SettingsAutomations & scenes

  2. Click Create automationCreate new automation

  3. Trigger:

    • Click “Add trigger”
    • Select “Sun”
    • Select “Sunset”
  4. Action:

    • Click “Add action”
    • Select “Device”
    • Find your lamp
    • Select “Turn on”
  5. Save with name “Turn on living room light at sunset”

🚶 Example 2: Light on Motion (Night Only)

Section titled “🚶 Example 2: Light on Motion (Night Only)”
automations.yaml
- alias: "Hallway light on motion (night)"
description: "Turns on dim light in hallway at night"
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
condition:
- condition: time
after: "22:00:00"
before: "07:00:00"
action:
- service: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 20 # Dim light at night
- delay:
minutes: 2
- service: light.turn_off
target:
entity_id: light.hallway
mode: restart # Restarts timer on new motion

Requires smart plug with power monitoring (e.g., IKEA TRETAKT or Sonoff S31):

automations.yaml
- alias: "Washing machine done"
description: "Sends notification when laundry is finished"
trigger:
- platform: numeric_state
entity_id: sensor.washing_machine_power
below: 5 # Watts
for:
minutes: 3 # Must be low for 3 min
condition:
- condition: numeric_state
entity_id: sensor.washing_machine_power
above: 0.5 # Ensures it has been running
action:
- service: notify.mobile_app_my_phone
data:
title: "🧺 Washing Machine"
message: "The laundry is done!"
mode: single
automations.yaml
- alias: "Low temperature warning"
description: "Warns if it gets too cold"
trigger:
- platform: numeric_state
entity_id: sensor.living_room_temperature
below: 18
for:
minutes: 10
action:
- service: notify.mobile_app_my_phone
data:
title: "🥶 Cold in living room"
message: "Temperature has dropped to {{ states('sensor.living_room_temperature') }}°C"
mode: single

🎯 Start simple

Do one thing at a time. Only add conditions when the basics work.

🧪 Test thoroughly

Use the “Run” button to test actions without waiting for trigger.

📝 Good names

“Turn on outdoor light at sunset” is better than “Automation 1”.

🤔 Think edge cases

What if power goes out? What if someone already turned on the light?

TriggerWhenExample
stateEntity changes stateMotion, door opens
numeric_stateValue above/belowTemperature, power usage
sunSunrise/sunsetLight automation
timeSpecific timeMorning routine
zonePerson arrives/leavesHome/away
deviceDevice-specificButton pressed

Kommentarer