Turn on or adjust lights automatically at sunset, sunrise, or by sun position

Last updated:

Includes Home Assistant automation

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.

duskbedtime30 minutes before sunsetAt 23:15Turn on (living roomlamp)Turn off (living roomlamp)
Trigger Condition Action Wait Nothing

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.

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

Validated against Home Assistant 2026.8.3 Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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

That automation is yours to keep

Get a fresh idea like it - plus the week's smart home news and gear - in your inbox every Friday. Free, and unsubscribing is one click.

Related Ideas

Tagged: lighting, scheduling, sun-triggers

Want more ideas like this?

Fresh automation ideas plus the smart home news and gear worth knowing, in your inbox every Friday.