This automation triggers your lights from sunset, sunrise, or the sun's elevation rather than a fixed clock time, with an offset so they arrive before the room goes dim. A time you set in autumn is wrong by spring, because the daylight moves and the timer does not.
What you need
- A smart bulb, a smart switch, or a smart plug with an ordinary lamp in it. On a plug, leave the lamp's own switch permanently on, or the plug will dutifully power a lamp that stays dark.
- A platform with sunset and sunrise triggers.
- On Apple Home, a home hub such as a HomePod mini or an Apple TV.
Why a 7pm timer only works for a few weeks a year
Pick 7:00 PM and you have picked a moment that means something different every month. In midsummer it is broad daylight and the lamp burns for hours before anyone needs it. In December it is two hours after dark, and you spend the evening reaching for the switch you bought a smart bulb to stop touching.
A sun trigger moves instead. Your platform works out sunset and sunrise from your location and today's date, then reschedules itself every night. The rule you write in October is the one still running in June.
Setting both edges of the schedule
The on edge wants an offset. Sunset is the moment the sun meets the horizon, not the moment your living room goes grey, so firing half an hour early puts the lights up while there is still colour in the sky.
The off edge is where schedules quietly rot. A sun trigger is a moment, not a condition. It puts the lights on and then has no further opinion, so the second half of the schedule is yours to write, and that is where a clock time creeps back in.
Moving one edge to the sun fixes only that edge. Lights that switch on at 6:00 AM and off at sunrise look perfect all winter, then invert in summer: sunrise now comes first, the off runs before the on, and the lamps burn through the entire day. Check the pair against the extremes of your year, not against tonight.
The safest schedule puts both edges on the sun. An outdoor light that comes on before sunset and goes off after sunrise cannot cross itself, because sunset always lands first. Indoors you rarely want the lamps burning all night, which is why the automation below ends on a set late hour instead. Any time later than your latest sunset of the year holds for the whole year.
It also brings the lamp up at a fraction of full brightness rather than all of it, because the job at dusk is to meet the fading daylight, not to replace it.
Hubitat's basic rule builder takes one trigger per rule, so an on-and-off schedule turns into two, or four once you want a morning pattern as well. Its advanced rule engine holds several triggers in one, and so does Home Assistant, which is what the block below does: one automation, both triggers, branching on whichever fired. That block controls lights. A lamp on a plug, or a relay behind a wall switch, turns up as a switch entity instead, so use its own on and off and skip the brightness step.
Get the next idea in your inbox
Automation ideas like this one, plus the week's smart home news and gear. Every Friday, free.
What the sun trigger doesn't know
Sunset is a clock event, not a light reading. It lands at the same instant on a clear evening and under the storm front that turned four in the afternoon into dusk, because the sun's position is the only thing it knows about.
If you would rather name the darkness than guess at minutes, trigger on the sun's elevation and fire when it drops below a few degrees above the horizon. An offset is a number of minutes. An elevation is the same height of sun every time. Home Assistant and Homey expose that. The cloud routine builders do not.
And if all you care about is whether the room is dark, measure the room. Some plug-in night lights carry their own illumination sensor and come on by brightness alone, no schedule involved, which beats any sun rule in a hallway that goes gloomy hours before the rest of the house.
The last thing it cannot see is people. A sun schedule lights an empty living room every evening you are away, so when the lights should answer to somebody being there rather than to the clock, that is what occupancy triggers are for.
Do you need a hub for this?
On Apple Home, yes. The automation is a handful of taps in the Automation tab (a time of day occurs, choose Sunset, every day, pick the lamp, turn on), but it needs a home hub to keep running when your phone is out of the house.
Elsewhere it is a real choice, and this is one of the few automations where cloud routines are fine. A lamp at dusk is not a switch you are standing at, waiting for. What a local hub buys you is a schedule that survives the internet: the sunset time is worked out on the box in your hallway, so the lights still come on at dusk on the evening your connection is down.
This idea is shared for inspiration only, not professional advice. If it involves wiring, breakers, or high-draw appliances, verify ratings and your local electrical code, or hire a licensed electrician. Read our full disclaimer.
Get the Home Assistant Automation YAML
Example automation (Home Assistant). A starting point; swap in your own entity names.
alias: Living room lamp follows the sun
description: >-
Turns the lamp on half an hour before sunset and off at a set late hour.
Swap in your own entity names.
mode: single
triggers:
- trigger: sun
event: sunset
offset: "-00:30:00"
id: dusk
- trigger: time
at: "23:15:00"
id: bedtime
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id: dusk
sequence:
- action: light.turn_on
target:
entity_id: light.living_room_lamp
data:
brightness_pct: 60
- conditions:
- condition: trigger
id: bedtime
sequence:
- action: light.turn_off
target:
entity_id: light.living_room_lamp
Related Ideas
Simulate occupancy with randomized lighting while away to deter burglars
This automation cycles lights on and off across rooms at randomized times while you are away, imitating how a person moves through a house after dark. A single lamp on a fixed timer does the opposite, handing a watcher the repeating pattern that marks an empty house.
Turn on lights automatically when motion is detected
Motion-activated lighting turns a lamp or ceiling light on the moment a sensor sees movement, then off again once the room has been quiet for a few minutes. Without it, you are feeling along the wall for a switch in a room you are only crossing.
Turn lights or devices on when a room is occupied, off when empty
This automation uses a presence sensor to switch a light on when someone is in a room and off once it empties. A plain motion sensor times out and drops the light while you sit still, so you end up waving an arm to bring it back.
Notify when an appliance finishes its cycle, from its power draw
This automation watches the power an appliance pulls through an energy-monitoring smart plug and alerts you once the draw stays low long enough to mean the cycle is truly over. Without it, wet laundry sits until it turns musty, or you keep checking a machine that finished an hour ago.
Tagged: lighting, scheduling, sun-triggers