Daily Sun-Based Device Scheduler with Optional Timer
A robust, “set-and-forget” Home Assistant blueprint for scheduling switches, lights, and fans to turn on automatically at sunset with a custom offset and off at a fixed time, featuring built-in day-of-week filtering and fully optional, bidirectional timer synchronization. This blueprint includes edge-case handling for manual physical overrides and smart recovery logic after system reboots or mid-schedule turn-ons.
Features
-
Sunset-Based Scheduling: Automatically turns devices on relative to sunset with positive or negative offsets (e.g.,
-00:30:00for 30 minutes before sunset). -
Fixed Turn Off Time: Easily specify an off-time directly in the UI.
-
Day-of-Week Filtering: Toggle individual days of the week (
Mon–Sun) on or off. -
Optional Bidirectional Timer Sync: Link a timer helper (
timer.*) for live dashboard tracking. The blueprint keeps the timer and device in sync automatically:Event Action Taken Sunset Trigger Starts Starts the timer with the calculated duration remaining until the scheduled Off time. Device Turned On Manually / Mid-Schedule Detects physical or external turn-on events and starts the timer countdown using the smart remaining time left until the scheduled off-time. Timer Ends or Cancelled Automatically turns off the controlled device. Device Turned Off Automatically cancels the running timer helper. Home Assistant Restarts Evaluates whether the device is on after a reboot, syncing the timer to the exact remaining time left in the schedule rather than restarting a fixed duration.
Blueprint Inputs
| Input | Description | Required? | Default |
|---|---|---|---|
| Device to Control | The switch, light, or fan entity to automate. | Yes | N/A |
| Sunset Offset | Offset relative to sunset in HH:MM:SS text format. Use a minus sign for before sunset (e.g., -00:30:00) or positive for after sunset (e.g., 00:15:00). |
No | -00:30:00 |
| Turn Off Time | Fixed time of day to turn the device off. | Yes | N/A |
| Timer Helper (Optional) | A timer helper (timer.*) to track countdowns and enable sync. |
No | Blank (Disabled) |
| Monday – Sunday | Individual day toggles to restrict scheduled execution. | No | true (All enabled) |
Important Notes & Pro-Tips
- Entering Offsets: Because sunset times change dynamically throughout the year, the
Sunset Offsetinput uses text formatting (HH:MM:SS). Enter a minus sign for time before sunset (e.g.,-00:45:00) or a positive format for time after sunset (e.g.,00:20:00). - Manual Override & Smart Recovery: If the device is flipped on manually or after a system restart midway through an active schedule, the automation automatically calculates and syncs to the remaining time left until the off-time rather than restarting a fixed total duration.
- Disabling the Schedule: If you uncheck all day-of-week toggles, the scheduled on/off automation actions will never execute, acting identically to pausing or disabling the automation.
- Timer Restarts & Power Loss Safety: If you use an optional timer helper, make sure to enable the “Restore” option in its helper settings (
Settings > Devices & Services > Helpers). This allows the timer to survive Home Assistant system restarts and accurately finish the countdown.
Installation
Method 1: Click to Import (Easiest)
Click the badge below to import this blueprint directly into your Home Assistant instance:
Method 2: Manual Installation
- Download or clone the raw YAML file from this repository:
daily_sun_based_device_scheduler.yaml - In your Home Assistant configuration directory, navigate to your blueprints folder (e.g.,
config/blueprints/automation/ufans123/). - Paste the code into a file named
daily_sun_based_device_scheduler.yaml. - Reload your automations or restart Home Assistant.
(For now I would recommend using the link in Method 2 as there have been issues with Method 1 blueprint UI redirects not loading expected popup prompts since recent core updates)