Mastering Home Assistant automations with sunrise, motion, and time triggers transforms your smart home from a remote-controlled system into a truly intelligent one. Rather than manually controlling lights and appliances, well-designed automations respond to your daily rhythms — waking the home up with the sun, keeping it comfortable when you are present, and conserving energy when you leave. This comprehensive guide covers all three trigger types with practical examples tailored for Indian households.
Table of Contents
- Home Assistant Automation Basics
- Time and Pattern Triggers
- Sunrise and Sunset Automations
- Motion Trigger Automations
- Combining Multiple Triggers
- Indian Home Automation Examples
- Debugging and Testing Automations
- Frequently Asked Questions
Home Assistant Automation Basics
Every Home Assistant automation has three components:
- Trigger: What starts the automation (time, motion, state change)
- Condition (optional): Additional checks that must pass (only on weekdays, only when home, only at night)
- Action: What happens when triggered (turn on light, send notification, adjust AC)
Automations can be created via the visual editor (Settings > Automations) or directly in YAML. The visual editor covers 90% of use cases — YAML is needed only for advanced templates and complex logic.
Time and Pattern Triggers
Fixed Time Trigger
The simplest trigger — runs at an exact time every day:
alias: Morning Geyser On
trigger:
- platform: time
at: "05:45:00"
action:
- service: switch.turn_on
entity_id: switch.bathroom_geyser
Multiple Times Trigger
alias: Prayer Time Bell
trigger:
- platform: time
at:
- "06:00:00" # Morning aarti
- "12:00:00" # Afternoon
- "19:00:00" # Evening aarti
action:
- service: media_player.play_media
entity_id: media_player.hall_speaker
data:
media_content_id: "OM_chime.mp3"
media_content_type: music
Time Pattern Trigger (Cron-like)
# Check and report every hour
trigger:
- platform: time_pattern
minutes: "0" # Every hour at :00
# Every 15 minutes
trigger:
- platform: time_pattern
minutes: "/15"
Sunrise and Sunset Automations
Home Assistant uses your configured coordinates (set during onboarding with your Indian city location) to calculate accurate local sunrise and sunset times every day. This automatically adjusts for seasonal changes without any manual updates.
Outdoor Lights at Sunset
alias: Evening Outdoor Lights
trigger:
- platform: sun
event: sunset
offset: "-00:15:00" # 15 min before sunset
action:
- service: light.turn_on
entity_id:
- light.garden_light
- light.entrance_light
data:
brightness: 255
Morning Curtains Open at Sunrise
alias: Morning Curtains
trigger:
- platform: sun
event: sunrise
offset: "+00:30:00" # 30 min after sunrise
condition:
- condition: time
weekday: [mon, tue, wed, thu, fri] # Only weekdays
action:
- service: cover.open_cover
entity_id: cover.living_room_curtains
Night Mode at Sunset Plus 2 Hours
Many Indian families follow a “lights dim after 9-10 PM” pattern regardless of season. A sunset-relative trigger handles this naturally:
alias: Night Mode Activation
trigger:
- platform: sun
event: sunset
offset: "+02:00:00"
action:
- service: light.turn_on
target:
area_id: living_room
data:
brightness: 80
color_temp: 500 # Warm white for night
- service: scene.turn_on
entity_id: scene.night_mode
Solar Production Awareness
For homes with rooftop solar (increasingly common in Gujarat, Rajasthan, Maharashtra), use solar elevation to trigger high-load appliances during peak generation hours:
alias: Run Washing Machine During Solar Peak
trigger:
- platform: numeric_state
entity_id: sun.sun
attribute: elevation
above: 45 # High sun angle = peak solar
condition:
- condition: state
entity_id: sensor.solar_power
state_numerical:
above: 2000 # More than 2kW generating
action:
- service: switch.turn_on
entity_id: switch.washing_machine
Motion Trigger Automations
Motion sensors (PIR sensors or camera-based detection) create the most satisfying automations — lights that follow you through the house.
Simple Motion-Based Light Control
alias: Kitchen Motion Light
trigger:
# Turn on when motion detected
- platform: state
entity_id: binary_sensor.kitchen_motion
to: "on"
id: motion_on
# Turn off 5 min after motion stops
- platform: state
entity_id: binary_sensor.kitchen_motion
to: "off"
for: "00:05:00"
id: motion_off
condition:
# Only at night/evening (save energy during day)
- condition: sun
after: sunset
before: sunrise
action:
- choose:
- conditions:
- condition: trigger
id: motion_on
sequence:
- service: light.turn_on
entity_id: light.kitchen
- conditions:
- condition: trigger
id: motion_off
sequence:
- service: light.turn_off
entity_id: light.kitchen
Multi-Zone Motion Tracking
Follow movement through Indian home zones:
alias: Follow Me Lights
# When motion detected in any room, turn on that room's light
# and turn off the previous room's light
trigger:
- platform: state
entity_id:
- binary_sensor.hall_motion
- binary_sensor.kitchen_motion
- binary_sensor.study_motion
to: "on"
action:
- service: light.turn_on
target:
entity_id: >-
{% if trigger.entity_id == 'binary_sensor.hall_motion' %}
light.hall
{% elif trigger.entity_id == 'binary_sensor.kitchen_motion' %}
light.kitchen
{% else %}
light.study
{% endif %}
Doorbell Motion Alert
Indian homes frequently have visitors unannounced. A motion sensor at the main entrance triggers a notification:
alias: Entrance Motion Alert
trigger:
- platform: state
entity_id: binary_sensor.entrance_motion
to: "on"
condition:
- condition: time
after: "09:00:00"
before: "22:00:00"
action:
- service: notify.mobile_app
data:
message: "Someone at the entrance"
data:
image: "/api/camera_proxy/camera.entrance" # If camera available
Combining Multiple Triggers
The most powerful automations combine multiple triggers with conditions:
alias: Smart Hall Light (Combined)
trigger:
- platform: state
entity_id: binary_sensor.hall_motion
to: "on"
- platform: sun
event: sunset
condition:
- condition: or
conditions:
- condition: sun
after: sunset
- condition: numeric_state
entity_id: sensor.hall_lux
below: 50 # Dark even during daytime
action:
- service: light.turn_on
entity_id: light.hall
data:
brightness: >-
{% if now().hour 22 %}
50
{% else %}
200
{% endif %}
Indian Home Automation Examples
Diwali Decoration Lights Schedule
alias: Diwali Lights Schedule
trigger:
- platform: sun
event: sunset
offset: "-00:30:00"
condition:
- condition: template
value_template: >-
{% set today = now() %}
{{ today.month == 10 or today.month == 11 }}
action:
- service: switch.turn_on
entity_id:
- switch.balcony_lights
- switch.entrance_fairy_lights
Power Cut Response
alias: Power Cut Alert
trigger:
- platform: state
entity_id: binary_sensor.mains_power
to: "off"
action:
- service: notify.family_group
data:
message: >-
Power cut! Inverter on.
Battery: {{ states('sensor.battery_soc') }}%
- service: switch.turn_off
entity_id:
- switch.washing_machine
- switch.bedroom_2_ac
Debugging and Testing Automations
Home Assistant’s automation editor includes a powerful trace function:
- Go to Settings > Automations
- Click on your automation
- Click the three-dot menu > Trace
- See the complete execution history with timing and condition evaluation
For rapid testing, use the Developer Tools > Template section to test Jinja2 template conditions. Use the Services tab to manually call actions (switch.turn_on, etc.) to verify your targets are correct before automating them.
Frequently Asked Questions
How do I make an automation run only on certain days of the week?
Add a time condition to your automation specifying weekday. In YAML: condition: time, weekday: [mon, tue, wed, thu, fri] for weekdays only, or [sat, sun] for weekends. This is essential for geyser, alarm, and cooking schedules that differ between weekdays and weekends in Indian households.
Why is my sunrise trigger running at the wrong time?
Check that your Home Assistant location is set correctly to your Indian city coordinates. Go to Settings > System > General > Location. If the location shows USA or UK (common default if not set during onboarding), your sunrise trigger will calculate for the wrong timezone and location.
Can automations run while Home Assistant is restarting?
No. Automations require HA to be running. If the Pi reboots after a power cut, automations resume once HA is fully loaded (typically 60-90 seconds). Design critical systems (like inverter monitoring) to have hardware-level fallbacks that work independently of HA.
How many automations can Home Assistant handle?
Home Assistant handles hundreds of automations efficiently. There is no practical limit for home use — even 200-300 automations run without performance impact on a Pi 4. The database and entity history are more likely performance bottlenecks than automation count.
Add comment