Researched from current Home Assistant documentation on September 19, 2026. This is a configuration example, not a report of testing on a Tara installation. The cover is an AI-generated illustration.
Use an evening window, not just an on command
A Home Assistant sunset lights automation can use the built-in Sun integration to follow the changing seasons. For an evening lamp, use a sunset start, a bedtime finish, and a check of whether the lamp should be on now. That last check lets the routine recover after Home Assistant missed the start or finish.
The example below turns one existing lamp on 20 minutes before sunset and off at 23:00. A dashboard toggle pauses the routine. When enabled, the routine also keeps the lamp off outside that evening window, so choose a lamp you are happy to give this schedule.
Start with a non-essential table lamp you can see. Check the location and manual control first, create the pause toggle, then add the automation and rehearse it. You do not need a new sensor, a custom integration, or a subscription for the scheduling logic. The lamp must already be controllable in Home Assistant. If you are still choosing controls, start with the room-by-room smart-lighting guide.
1. Decide what “evening” should mean
For a predictable daily routine, start with the example’s 20 minutes before sunset to 23:00. The Sun integration calculates events using your home location. It does not measure light in the room.
On a phone, scroll sideways to compare the options.
| Your goal | Choose | Main limit |
|---|---|---|
| A regular evening lamp that follows sunset through the year. | Sunset, optionally with a fixed early-start offset. Use the example below. | Twenty minutes before sunset is a timing preference, not a guaranteed darkness level. |
| Outdoor lighting at a similar stage of twilight. | A sun-elevation threshold: the sun’s angle above or below the horizon. | Clouds, hills and buildings still affect actual brightness. |
| A room that needs light on dark afternoons too. | A suitable illuminance sensor, which measures brightness in lux. | It needs careful placement and separate on/off thresholds so the lamp’s own light does not make it cycle. |
Home Assistant recommends sun elevation for dawn or dusk timing because twilight duration changes through the year. Keep the sunset example when the household simply wants an evening schedule.
Scope of this example: bedtime is before midnight, and the home has an ordinary daily sunset. Official sun-condition documentation excludes polar-circle locations and highly skewed local time zones. Use a separately designed elevation or brightness rule there. A bedtime after midnight also needs a different time-window design; changing 23:00 to 01:00 in this example is not enough.
2. Check the lamp and create the pause toggle
- Check Home information. Under Settings → System → Home information (called General in older versions), confirm the home location and time zone. A correct phone clock does not prove Home Assistant uses the right location. See the official Home information settings. Under Settings → Devices & services, confirm the Sun integration is present; if you removed it, add Sun again.
- Find the lamp’s entity ID. An entity is the control or reading Home Assistant exposes. Open the lamp’s settings and note its ID, such as
light.living_room_lamp. Turn it on and off from its normal dashboard control and watch the physical lamp. - Create a Toggle helper. Go to Settings → Devices & services → Helpers → Create helper → Toggle. Name it “Evening lamp schedule.” A helper is a control stored in Home Assistant rather than a separate device. Leave it off while setting up.
- Check the helper ID and put it on your dashboard. The code expects
input_boolean.evening_lamp_schedule. Add it beside the lamp control with an obvious label such as “Evening lamp schedule — off to pause.”
The Toggle helper normally restores its previous state after restart. Turning it off pauses this routine; it does not itself turn the lamp off. For a manual change, pause first, then use the normal lamp control. Other automations or a manufacturer’s app can still act, so remove conflicting schedules for this lamp.
This version expects a light. entity. If your lamp is a switch. entity, replace its ID everywhere and change light.turn_on/light.turn_off to switch.turn_on/switch.turn_off. Keep electrical wiring and essential stair or emergency lighting outside this practice setup.
3. Add the complete automation
Open Settings → Automations & scenes → Create automation → Create new automation. In the editor menu, select Edit in YAML, replace the new automation’s contents with this example, and save. YAML is the text version of the automation. Replace every occurrence of the lamp and helper IDs if yours differ.
The example uses the documented general sun trigger. Recent editors may show a Sunset trigger with separate Before/After controls; labels depend on the installed version. When editing this YAML, keep its two negative offsets identical and its two bedtime values identical.
alias: Evening lamp from sunset to bedtime
description: Apply the current evening window while scheduling is enabled.
triggers:
- trigger: sun
event: sunset
offset: "-00:20:00"
- trigger: time
at: "23:00:00"
- trigger: homeassistant
event: start
- trigger: state
entity_id: input_boolean.evening_lamp_schedule
to: "on"
- trigger: time_pattern
minutes: "/5"
conditions: []
actions:
- condition: state
entity_id: input_boolean.evening_lamp_schedule
state: "on"
- condition: template
value_template: >-
{{ states('sun.sun') in ['above_horizon', 'below_horizon']
and states('light.living_room_lamp') in ['on', 'off'] }}
- choose:
- conditions:
- condition: sun
after: sunset
after_offset: "-00:20:00"
- condition: time
before: "23:00:00"
sequence:
- condition: state
entity_id: light.living_room_lamp
state: "off"
- action: light.turn_on
target:
entity_id: light.living_room_lamp
default:
- condition: state
entity_id: light.living_room_lamp
state: "on"
- action: light.turn_off
target:
entity_id: light.living_room_lamp
mode: single
There are no hours-long waits. Each trigger asks the same question: is it at least 20 minutes before today’s sunset, but still before 23:00? The Choose action requests on inside that window and off outside it. A state check avoids sending a command when the reported lamp state already matches.
The startup trigger checks after Home Assistant starts. If the lamp is not ready then, the five-minute trigger checks again at clock minutes 00, 05, 10 and so on. Unknown or unavailable readings stop that run. This checks Home Assistant’s reported state; it does not prove the bulb received a command or refresh a stale device reading.
Manual-control tradeoff: with the schedule toggle on, a manual change can be reversed at the next check. Turn the toggle off first to keep the lamp as you want it. Turning it back on immediately applies the current window. For a timed pause that resumes automatically, see the manual-override guide.
4. Walk through a sample evening
Suppose today’s sunset is 18:40. The intended lighting window is 18:20–23:00. These are hypothetical inputs and code decisions, not measured behavior from a home.
| Situation | Expected decision | Reason |
|---|---|---|
| 18:20; schedule enabled; lamp is off. | Request on. | The early-start trigger and condition use the same 20-minute offset. |
| Home Assistant starts at 19:10 after missing the start; lamp is available and off. | Request on. | It applies the current evening window, without replaying missed events. |
| At 21:00 you pause the schedule, then turn the lamp off. | Leave it alone, including at 23:00. | A pause stops both on and off commands from this routine. |
| 23:00; schedule enabled; lamp is on. | Request off. | The bedtime condition stops passing at the cutoff. |
| Home Assistant starts at 00:10; schedule enabled; lamp is still on. | Request off. | The previous evening’s after-sunset condition ended at midnight. |
| In summer, sunset is 23:30 and the start would be 23:10. | Keep the lamp off. | The proposed start is already past bedtime. There is no evening window that day. |
| Lamp is unavailable at 18:20, then reports off at 18:27. | Skip while unavailable; request on at the 18:30 check. | Recovery waits for a usable state and another trigger. Device response is not guaranteed. |
The midnight behavior is deliberate. An after sunset condition by itself covers the evening only. An all-night rule is a different choice; do not add “before sunrise” to this example while retaining its before-23:00 cutoff.
5. Rehearse with one visible lamp
- Verify the pause first. Leave the helper off, set the lamp to a state you can see, and select the automation’s Run actions. Expected result: no change. The first action-list condition stops the sequence.
- Check the current window. Turn the helper on while watching the lamp. During the evening window, an off lamp should turn on; outside it, an on lamp should turn off. Pause again when you need manual control.
- Check an actual boundary. During an evening window, temporarily move both 23:00 entries to the same time a few minutes ahead, still before midnight. Save. The lamp should turn off at that cutoff. Restore both entries afterwards; if the evening window is still open, the next check can turn the lamp back on. Confirm the early-start event on the next evening too.
- Check recovery at your next planned restart. Keep the lamp powered. With scheduling enabled, expect the current window to apply once Home Assistant and the lamp connection are ready, by a subsequent five-minute check if needed. With scheduling paused, expect no command from this routine.
- Read Traces and look at the lamp. Traces show the trigger and the branch taken. A successful software action alone does not establish that the physical lamp changed.
Run actions skips triggers and top-level conditions. The guard checks here are inside the action sequence, so a whole-sequence manual run still observes them. Running one action by itself can bypass earlier checks. Neither manual test proves that the scheduled trigger will fire.
If the lamp does something unexpected
- It turns on early, then goes off until sunset: compare the two offsets. An early trigger paired with an unshifted sunset condition disagrees about when the window starts.
- The whole evening is shifted: check Home information and the next sunset shown by the Sun integration before changing the rule.
- It ignores a manual change: pause the helper first. If it still changes while paused, inspect other automations and vendor schedules. The general automation troubleshooting guide explains traces and failed steps.
- The trace asks for on but the lamp stays dark: try its ordinary dashboard control. If that fails too, investigate the lamp connection rather than changing the sunset time.
- You want varying lights only while away: use the separate vacation-lighting routine. This example runs every enabled evening, whether someone is home or not.
Frequently asked questions
How do I change how early the lamp turns on?
Change both the sunset trigger’s offset and the sun condition’s after_offset to the same value. For exactly sunset, use "00:00:00" in both places. A fixed offset follows the sunset time, but it does not track clouds or indoor brightness.
Will this work without internet?
The Sun calculation and automation run in Home Assistant. The lamp also needs a local control connection to work without internet; a cloud-based integration can still depend on its vendor. No commands are sent while Home Assistant is down.
Why not just wait until bedtime after turning the lamp on?
Separate triggers and a current-window check avoid depending on one long-running action sequence. This example can apply the right state after downtime. For a countdown with its own saved deadline, use the separate timer guide.
For help coordinating everyday schedules and clear household controls, see Tara’s home automation kit for local routines.
