Home Assistant Automations Examples: 7 Practical YAML Fixes
If you've ever walked into a dark house, forgotten to turn off the porch light, or gotten halfway to work wondering if you left the thermostat blasting — you already understand why Home Assistant automations exist. The problem is, most tutorials show you how to write YAML without telling you why it matters for your daily life. This post changes that.
Below you'll find seven practical Home Assistant automations examples, complete with YAML code snippets, that solve real problems in real households. Whether you're new to home automation or looking to level up your existing setup, these examples will give you a working foundation you can adapt immediately.
Why Home Assistant Automations Matter
Home Assistant is one of the most powerful open-source home automation platforms available. Unlike locked-down ecosystems, it gives you full control over your devices, your data, and your logic. But that freedom comes with a learning curve — especially around automations.
Automations in Home Assistant follow a simple three-part structure:
- Trigger — What starts the automation (a time, a state change, a sensor reading)
- Condition — Optional checks that must be true for the automation to run
- Action — What happens when the trigger fires and conditions are met
Once you internalize that structure, the YAML starts to make sense. Let's get into the examples.
---
1. Turn Lights On at Sunset Automatically
This is the classic starter automation and a fan favorite for good reason. Instead of fumbling for switches at dusk, your lights just... turn on.
yaml
alias: "Lights On at Sunset"
trigger:
- platform: sun
event: sunset
offset: "-00:15:00"
action:
- service: light.turn_on
target:
entity_id: light.front_porch
data:
brightness_pct: 80
The offset field is powerful here — it fires the automation 15 minutes before sunset, so your lights are ready before it gets dark. Swap the entity ID for any light in your system.
---
2. Turn Off All Lights When Everyone Leaves
Device trackers make this one possible. When the last person leaves home, the house shuts down.
yaml
alias: "All Lights Off When House Empty"
trigger:
- platform: state
entity_id: group.all_devices
to: "not_home"
condition:
- condition: state
entity_id: group.all_devices
state: "not_home"
action:
- service: light.turn_off
target:
entity_id: all
Pair this with a group entity that tracks all your household members' phones via the Home Assistant companion app. You can also extend the action to turn off the TV, set the thermostat to away mode, and lock the front door — all in one automation.
---
3. Morning Routine Automation
Automate your entire morning with a single trigger. This example turns on lights gradually, starts a coffee maker switch, and sends a notification to your phone.
yaml
alias: "Morning Routine Weekdays"
trigger:
- platform: time
at: "06:30:00"
condition:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: light.turn_on
target:
entity_id: light.bedroom
data:
brightness_pct: 30
color_temp: 4000
- delay: "00:05:00"
- service: switch.turn_on
target:
entity_id: switch.coffee_maker
- service: notify.mobile_app_your_phone
data:
message: "Good morning! Coffee is brewing."
The condition block ensures this only fires on weekdays. The delay gives you five minutes before the coffee maker kicks on — so it's ready when you actually get to the kitchen.
---
4. Smart Thermostat Control Based on Occupancy
Heating or cooling an empty house is expensive. This automation adjusts your thermostat based on whether anyone is home, saving energy without sacrificing comfort.
yaml
alias: "Thermostat Away Mode"
trigger:
- platform: state
entity_id: binary_sensor.home_occupied
to: "off"
action:
- service: climate.set_temperature
target:
entity_id: climate.home_thermostat
data:
temperature: 65
hvac_mode: heat
You'll want a companion automation that sets it back to a comfortable temperature when someone arrives home. Combine this with a 10-minute delay to avoid false triggers from quick grocery runs.
For households managing multiple smart devices across different systems, working with a knowledgeable local technology partner like Digital Kitsap can help you design an integration strategy that actually fits your home and lifestyle.
---
5. Motion-Activated Hallway Lights at Night
This one is incredibly practical — lights only come on at night when motion is detected, and they turn off automatically after a few minutes.
yaml
alias: "Hallway Night Light on Motion"
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
condition:
- condition: time
after: "22:00:00"
before: "06:00:00"
action:
- service: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 20
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "off"
for: "00:02:00"
- service: light.turn_off
target:
entity_id: light.hallway
Low brightness (20%) is intentional — bright enough to navigate safely without waking anyone up fully. Adjust the time window and brightness to match your household's schedule.
---
6. Water Leak Notification with Auto Shutoff
This one can save you thousands of dollars. If you have a water leak sensor and a smart water valve, you can automate emergency shutoff and get an instant alert.
yaml
alias: "Water Leak Alert and Shutoff"
trigger:
- platform: state
entity_id: binary_sensor.basement_leak_sensor
to: "on"
action:
- service: switch.turn_off
target:
entity_id: switch.main_water_valve
- service: notify.mobile_app_your_phone
data:
message: "⚠️ Water leak detected in basement! Main valve closed."
title: "URGENT: Water Leak"
This automation requires a compatible smart water valve (brands like Dome or Insteon make popular options). The peace of mind alone is worth the setup time. If you're building out a more comprehensive smart home safety system, the team at Digital Kitsap helps homeowners in the Kitsap Peninsula area design and implement reliable setups that go beyond basic automations.
---
7. Goodnight Scene with One Button
Instead of checking every room before bed, one button — or one voice command — handles everything.
yaml
alias: "Goodnight Scene"
trigger:
- platform: state
entity_id: input_boolean.goodnight_trigger
to: "on"
action:
- service: light.turn_off
target:
entity_id: all
- service: lock.lock
target:
entity_id: lock.front_door
- service: climate.set_temperature
target:
entity_id: climate.home_thermostat
data:
temperature: 68
- service: media_player.turn_off
target:
entity_id: all
- service: input_boolean.turn_off
target:
entity_id: input_boolean.goodnight_trigger
The input_boolean acts as a virtual button you can trigger from the Home Assistant dashboard, a physical button, or a voice assistant. The last action resets it so it's ready for tomorrow night.
---
Tips for Getting the Most Out of Home Assistant Automations
Start Simple and Layer Complexity
Don't try to automate everything at once. Pick one automation, get it working perfectly, then add the next. Debugging a single-action automation is much easier than untangling a 10-step sequence.
Use Blueprints to Speed Up Common Patterns
Home Assistant's Blueprint library lets you import pre-built automation templates from the community. If your specific use case is common, someone has probably already solved it.
Test in Trace Mode
The Automation Trace feature in Home Assistant shows you exactly what happened during each automation run — what triggered it, which conditions passed or failed, and what actions executed. It's invaluable for debugging.
Document Your Setup
As your automation library grows, add comments to your YAML using #. Your future self will thank you.
If you're building a smart home on the Kitsap Peninsula and want expert guidance navigating device compatibility, network setup, or complex automation logic, Digital Kitsap's technology services are a local resource worth exploring. Smart home tech works best when it's designed for your specific space — not just copied from a tutorial.
---
Final Takeaway
These Home Assistant automations examples are starting points, not endpoints. Each YAML snippet above can be extended, combined, and customized to fit exactly how you live. The real power of Home Assistant isn't any single automation — it's the ecosystem of logic you build over time.
Start with whichever example solves your most annoying daily problem. Get it working. Then build from there. That's how you turn a smart home into a home that actually works for you.
Have questions about implementing any of these or want help designing a broader home automation strategy? Reach out to Digital Kitsap — we're here to help make technology work smarter for Pacific Northwest homeowners.
Stay Ahead
Delivered each morning.