-
Notifications
You must be signed in to change notification settings - Fork 14
Advanced Use Cases Bedroom Sleep Mode
Keep blinds closed from bedtime until just before your alarm, overriding sunrise. A template binary sensor computes whether you're inside the sleep window, and a Custom Position slot holds the cover at 0% for as long as that sensor is on.
Once the sensor turns off, at the wake-up offset you configure, the custom position slot steps aside and the integration resumes normal adaptive tracking.
The sleep window spans midnight, so the template has two halves:
- Evening portion: sensor turns on when the clock reaches the configured bedtime (22:00 in the example below)
- Morning portion: sensor stays on from midnight until the offset-adjusted alarm time, but only if the alarm is set for today (not a future date), preventing false positives after the alarm fires
If no alarm is set or the alarm sensor is unavailable, the sensor stays on from bedtime until midnight only, a safe fallback that keeps the cover closed overnight even without an alarm entity.
Add the following to configuration.yaml, then restart Home Assistant or reload the Template integration:
template:
- binary_sensor:
- name: "Bedroom Sleep Mode"
device_class: occupancy
state: >
{% set t = now() %}
{% set alarm = states('sensor.mobile_app_phone_next_alarm') %}
{% if alarm in ('unavailable', 'unknown') %}
{{ t.hour >= 22 }}
{% else %}
{% set wake_dt = (alarm | as_datetime | as_local) - timedelta(minutes=10) %}
{% set in_evening = t.hour >= 22 %}
{% set in_morning = t.hour < 12 and t < wake_dt and wake_dt.date() == t.date() %}
{{ in_evening or in_morning }}
{% endif %}Replace sensor.mobile_app_phone_next_alarm with your actual alarm entity, typically provided by the Home Assistant Companion App.
The timedelta(minutes=10) is the wake-up offset. Increase it if you want the cover to start brightening earlier; set it to timedelta(minutes=0) to open exactly when the alarm fires.
To shift bedtime away from 22:00, change t.hour >= 22. For example, t.hour >= 23 delays the window to 23:00.
If you use a fixed wake-up time rather than a phone alarm, the template is simpler:
template:
- binary_sensor:
- name: "Bedroom Sleep Mode"
device_class: occupancy
state: >
{% set h = now().hour %}
{{ h >= 22 or h < 7 }}This keeps the blind closed from 22:00 to 07:00 every day. Replace 22 and 7 with your schedule. Note there is no wake-up offset here; add or (h == 6 and now().minute < 50) style logic if you want a window before 07:00.
Open the integration's options for your bedroom cover and configure one of the four Custom Position slots:
| Setting | Value |
|---|---|
| Custom Position Sensor | binary_sensor.bedroom_sleep_mode |
| Custom Position | 0% |
| Priority | 77 (default) |
At priority 77, the sleep mode sits above the solar (40), climate (50), cloud suppression (60), and motion timeout (75) handlers, so it overrides all of those. Manual Override runs at priority 80 and Weather Override at 90, both still take precedence, so you can open the blind manually during sleep hours if needed, and weather safety remains active.
If you want the sleep mode to hold regardless of manual interaction, raise the priority to 81. You would then need Force Override (priority 100) or disabling the integration entirely to open the blind during sleep hours.
Force(100) β Weather(90) β Manual(80) β Sleep Mode Custom(77) β Motion(75) β Cloud(60) β Climate(50) β Glare(45) β Solar(40) β Default(0)
While binary_sensor.bedroom_sleep_mode is on, the Custom Position handler fires at priority 77 and holds the cover at 0%. Solar, climate, and glare handlers run but don't claim the position. The decision trace in the dashboard card or diagnostics panel will show custom_position as the active handler with the sensor name.
When the sensor turns off at the wake-up offset, the Custom Position handler produces no result. The pipeline falls through to whichever handler is next, typically solar, which picks up the current sun position and moves the cover into its tracking position before the alarm rings.
- Custom Position: full slot configuration reference and additional examples
- How It Decides: full priority chain explanation
- Panel Card: decision trace visualization
- Advanced Use Cases: all advanced use case recipes
π Home Β· β¨ Features Β· π° What's New
π Getting Started
- Installation
- Migrating from Custom Repository
- Migrating from Adaptive Cover
- First-Time Setup
- Cover Types
π§ Core Concepts
π Cover Types
βοΈ Configuration
- Sun Tracking
- Position
- Position Matching
- Glare Zones
- Automation
- Custom Position
- Force Override
- Weather Safety
- Climate
- Templated Thresholds
- Blindspot
- Summary Screen
- Debug & Diagnostics
π Entities & Services
- Entities
- Proxy Cover Entity
- Position Verification
- My Position Support (Somfy RTS)
- Runtime Configuration Services
π οΈ Operations
π§ Advanced Use Cases
- Dynamic Temperature Thresholds
- Dynamic Tracking Window
- Bedroom Sleep Mode
- Handling Variable Cloud Cover
- Venetian Tilt-Only on Overcast Days
- Forecast-Based Shading
π¨ Dashboard
π§ͺ Testing & Simulation
π Reference
π©βπ» For Developers