Automations in Home Assistant allow you to create smart actions based on triggers like time, motion, or device states. This guide explains how to set up automations using both the UI and YAML configuration.
Automations consist of three parts:
1️⃣ Triggers – Events that start the automation (e.g., motion detected, sunset, button press).
2️⃣ Conditions – (Optional) Conditions that must be met (e.g., only run at night).
3️⃣ Actions – The result of the automation (e.g., turn on lights, send a notification).
For more flexibility, automations can be written in YAML inside automations.yaml
.
Add the following to automations.yaml
:
- alias: 'Turn on lights when motion is detected'
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor
to: 'on'
action:
- service: light.turn_on
target:
entity_id: light.living_room
How to Apply Changes:
1-Save the file.
2-Restart Home Assistant to apply the automation.
Move on to Troubleshooting & FAQs to solve common automation issues.