Created
December 16, 2025 18:08
-
-
Save Ltek/f38f506ea2c64bdeb1b03d32b65c15da to your computer and use it in GitHub Desktop.
Home Assistant Blueprint : Smart Night Light by Ltek
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| blueprint: | |
| name: "π Smart Night Light by LTek" | |
| description: | | |
| **Smart Night Light** | |
| π Version 2025.12.16.01d | |
| Author: LTek | |
| How it works... | |
| β’ When night settings are true, Lights maintain the user set brigntess level for Night. | |
| β’ If motion is detected and Night settings are true, the light brightness level changes to the user level set for Motion. | |
| β’ Triggers can be enabled for any, or all, Start and End for each type of setting. | |
| π **Day** - Lights are turned Off if/when turned on | |
| π **Night Settings** - user selectible options for Time, Ambient light, Sun Elevation. Trigger on Start & End for any or all. | |
| π **Night Motion** - Lights brighten to user setting level when Motion and night trigger settings are true. | |
| **FEATURES** | |
| π― Multi-sensor support with motion confirmation and cooldown | |
| π Smart night detection via ambient light, sun elevation, or time schedule | |
| β±οΈ Configurable timeouts with optional grace periods | |
| οΈβπ₯ Automatic brightness adjustment for manual changes during night | |
| βπ§ Bypass system for temporary automation override | |
| π’ Comprehensive notification system | |
| π Persistent Web UI Notifications | |
| π± Mobile Notifications | |
| π Sunset/sunrise triggers for automatic scheduling | |
| π« Smooth transitions between all lighting states | |
| π Debug mode for troubleshooting | |
| π Community Discussion, Help, and Details... https://community.home-assistant.io/ | |
| source_url: https://gist.github.com/Ltek/ | |
| domain: automation | |
| input: | |
| target_lights: | |
| name: "π‘ Target Light" | |
| description: "Light entity to control and monitor" | |
| selector: | |
| entity: | |
| domain: light | |
| motion_sensors: | |
| name: "π― Motion Sensor(s)" | |
| description: Motion sensor(s) that trigger the automation | |
| selector: | |
| entity: | |
| multiple: true | |
| filter: | |
| - domain: binary_sensor | |
| device_class: motion | |
| motion_settings: | |
| name: "ποΈ Motion & Brightness Settings" | |
| description: Configure motion detection and light brightness levels | |
| collapsed: true | |
| input: | |
| motion_brightness: | |
| name: "Motion Brightness" | |
| description: Brightness level when motion is detected | |
| default: 100 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| unit_of_measurement: "%" | |
| night_brightness: | |
| name: "Night Mode Brightness" | |
| description: Brightness level for night mode (when no motion) | |
| default: 10 | |
| selector: | |
| number: | |
| min: 1 | |
| max: 100 | |
| unit_of_measurement: "%" | |
| motion_timeout: | |
| name: "Motion Timeout" | |
| description: Time to wait after motion clears before dimming/turning off | |
| default: 300 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 3600 | |
| unit_of_measurement: seconds | |
| bright_to_dim_timeout: | |
| name: "Bright to Dim Timeout" | |
| description: Time to wait before dimming lights that are above night brightness during night conditions | |
| default: 300 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 3600 | |
| unit_of_measurement: seconds | |
| motion_confirmation_delay: | |
| name: "Motion Confirmation Delay" | |
| description: "Delay to confirm motion is real (prevents false triggers)" | |
| default: 1 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 5 | |
| unit_of_measurement: seconds | |
| cooldown_period: | |
| name: "Cooldown Period" | |
| description: Minimum time between motion triggers in seconds | |
| default: 30 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 3600 | |
| unit_of_measurement: seconds | |
| grace_period_settings: | |
| name: "β±οΈ Grace Period Settings" | |
| description: Add delay before adjusting lights after motion timeout | |
| collapsed: true | |
| input: | |
| use_grace_period: | |
| name: "Use Grace Period" | |
| description: "Add grace period after motion timeout before adjusting lights" | |
| default: false | |
| selector: | |
| boolean: | |
| grace_period_duration: | |
| name: "Grace Period Duration" | |
| description: "Time to wait before adjusting lights after motion timeout" | |
| default: 30 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 300 | |
| unit_of_measurement: seconds | |
| bypass_settings: | |
| name: "βΈοΈ Bypass Settings" | |
| description: Manually override automation when needed | |
| collapsed: true | |
| input: | |
| use_bypass: | |
| name: "Use Bypass System" | |
| description: "Enable bypass switch to manually override automation" | |
| default: false | |
| selector: | |
| boolean: | |
| bypass_switch: | |
| name: "Bypass Switch" | |
| description: "Switch to bypass automation (input_boolean or switch)" | |
| default: "" | |
| selector: | |
| entity: | |
| filter: | |
| - domain: input_boolean | |
| - domain: switch | |
| multiple: false | |
| bypass_action: | |
| name: "Bypass Action" | |
| description: "What happens when bypass is active?" | |
| default: keep_current | |
| selector: | |
| select: | |
| options: | |
| - label: "Keep lights at current state" | |
| value: keep_current | |
| - label: "Turn lights OFF during bypass" | |
| value: turn_off | |
| - label: "Turn lights ON during bypass" | |
| value: turn_on | |
| time_range_settings: | |
| name: "π Time Range Settings" | |
| description: Define night mode time schedule | |
| collapsed: true | |
| input: | |
| use_time_range: | |
| name: "Use Time Range" | |
| description: Enable time range as a night condition | |
| default: true | |
| selector: | |
| boolean: | |
| enable_time_start_trigger: | |
| name: "Use Start Time Trigger" | |
| description: "Turn on lights at night brightness when start time is reached" | |
| default: false | |
| selector: | |
| boolean: | |
| enable_time_end_trigger: | |
| name: "Use End Time Trigger" | |
| description: "Turn off lights when end time is reached" | |
| default: false | |
| selector: | |
| boolean: | |
| night_start_time: | |
| name: "Night Start Time" | |
| description: Time when night mode can begin | |
| default: "17:00:00" | |
| selector: | |
| time: | |
| night_end_time: | |
| name: "Night End Time" | |
| description: Time when night mode ends | |
| default: "05:00:00" | |
| selector: | |
| time: | |
| sun_elevation_settings: | |
| name: "π Sun Elevation Settings" | |
| description: Use sun position to determine night mode | |
| collapsed: true | |
| input: | |
| use_sun_elevation: | |
| name: "Use Sun Elevation" | |
| description: Enable sun elevation as a night condition | |
| default: true | |
| selector: | |
| boolean: | |
| enable_sun_sunset_trigger: | |
| name: "Use Sunset Trigger" | |
| description: "Turn on lights at night brightness when sunset occurs" | |
| default: false | |
| selector: | |
| boolean: | |
| enable_sun_sunrise_trigger: | |
| name: "Use Sunrise Trigger" | |
| description: "Turn off lights when sunrise occurs" | |
| default: false | |
| selector: | |
| boolean: | |
| sun_elevation_falling: | |
| name: "Sun Elevation (Falling)" | |
| description: Degrees below horizon when sun is setting | |
| default: -1.5 | |
| selector: | |
| number: | |
| min: -20 | |
| max: 20 | |
| step: 0.1 | |
| sun_elevation_rising: | |
| name: "Sun Elevation (Rising)" | |
| description: Degrees below horizon when sun is rising | |
| default: -4.0 | |
| selector: | |
| number: | |
| min: -20 | |
| max: 20 | |
| step: 0.1 | |
| ambient_light_settings: | |
| name: "βοΈ Ambient Light Settings" | |
| description: Use light sensor to determine night mode | |
| collapsed: true | |
| input: | |
| use_ambient_light: | |
| name: "Use Ambient Light Sensor" | |
| description: Enable ambient light as a night condition | |
| default: false | |
| selector: | |
| boolean: | |
| ambient_light_sensor: | |
| name: "Ambient Light Sensor" | |
| description: Light sensor to monitor | |
| default: "" | |
| selector: | |
| entity: | |
| filter: | |
| - domain: sensor | |
| device_class: illuminance | |
| ambient_light_threshold: | |
| name: "Ambient Light Threshold" | |
| description: Light level below which night mode activates | |
| default: 40 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 1000 | |
| unit_of_measurement: lx | |
| enable_ambient_dark_trigger: | |
| name: "Use Dark Trigger" | |
| description: "Turn on lights at night brightness when it gets dark (below threshold)" | |
| default: false | |
| selector: | |
| boolean: | |
| enable_ambient_bright_trigger: | |
| name: "Use Bright Trigger" | |
| description: "Turn off lights when it gets bright (above threshold)" | |
| default: false | |
| selector: | |
| boolean: | |
| notification_settings: | |
| name: "π Notification Settings" | |
| description: Configure alerts for automation events | |
| collapsed: true | |
| input: | |
| enable_mobile_notifications: | |
| name: "Enable Mobile Notifications" | |
| description: Send notifications to mobile devices | |
| default: false | |
| selector: | |
| boolean: | |
| mobile_notify_device: | |
| name: "Mobile Notification Device" | |
| description: Device to receive mobile notifications | |
| default: [] | |
| selector: | |
| device: | |
| integration: mobile_app | |
| multiple: true | |
| enable_ui_notifications: | |
| name: "Enable UI Notifications" | |
| description: Show notifications in Home Assistant UI | |
| default: false | |
| selector: | |
| boolean: | |
| notify_on_motion: | |
| name: "Notify on Motion Detection" | |
| description: Send notification when motion is detected | |
| default: false | |
| selector: | |
| boolean: | |
| notify_on_timeout: | |
| name: "Notify on Motion Timeout" | |
| description: Send notification when motion timeout occurs | |
| default: false | |
| selector: | |
| boolean: | |
| notify_on_night_adjust: | |
| name: "Notify on Night Adjustment" | |
| description: Send notification when lights adjust for night mode | |
| default: false | |
| selector: | |
| boolean: | |
| notify_on_manual_change: | |
| name: "Notify on Manual Light Change" | |
| description: "Send notification when lights are manually changed" | |
| default: false | |
| selector: | |
| boolean: | |
| notify_on_bypass: | |
| name: "Notify on Bypass Change" | |
| description: "Send notification when bypass is activated/deactivated" | |
| default: false | |
| selector: | |
| boolean: | |
| debug_settings: | |
| name: "π Debug Settings" | |
| description: Troubleshooting and diagnostic options | |
| collapsed: true | |
| input: | |
| enable_debug_notifications: | |
| name: "Enable Debug Notifications" | |
| description: "Show debug notifications for troubleshooting" | |
| default: false | |
| selector: | |
| boolean: | |
| mode: restart | |
| max_exceeded: silent | |
| variables: | |
| motion_brightness: !input motion_brightness | |
| motion_timeout_var: !input motion_timeout | |
| bright_to_dim_timeout_var: !input bright_to_dim_timeout | |
| motion_confirmation_delay: !input motion_confirmation_delay | |
| night_brightness_var: !input night_brightness | |
| cooldown_period_var: !input cooldown_period | |
| motion_sensors_var: !input motion_sensors | |
| target_lights_var: !input target_lights | |
| use_grace_period: !input use_grace_period | |
| grace_period_duration: !input grace_period_duration | |
| use_bypass: !input use_bypass | |
| bypass_switch: !input bypass_switch | |
| bypass_action: !input bypass_action | |
| use_ambient: !input use_ambient_light | |
| ambient_sensor: !input ambient_light_sensor | |
| ambient_threshold: !input ambient_light_threshold | |
| enable_ambient_dark_trigger: !input enable_ambient_dark_trigger | |
| enable_ambient_bright_trigger: !input enable_ambient_bright_trigger | |
| use_sun: !input use_sun_elevation | |
| sun_falling: !input sun_elevation_falling | |
| sun_rising: !input sun_elevation_rising | |
| enable_sun_sunset_trigger: !input enable_sun_sunset_trigger | |
| enable_sun_sunrise_trigger: !input enable_sun_sunrise_trigger | |
| use_time: !input use_time_range | |
| time_start: !input night_start_time | |
| time_end: !input night_end_time | |
| enable_time_start_trigger: !input enable_time_start_trigger | |
| enable_time_end_trigger: !input enable_time_end_trigger | |
| notify_on_motion: !input notify_on_motion | |
| notify_on_timeout: !input notify_on_timeout | |
| notify_on_night_adjust: !input notify_on_night_adjust | |
| notify_on_manual_change: !input notify_on_manual_change | |
| notify_on_bypass: !input notify_on_bypass | |
| enable_mobile_notifications: !input enable_mobile_notifications | |
| mobile_notify_device: !input mobile_notify_device | |
| enable_ui_notifications: !input enable_ui_notifications | |
| enable_debug_notifications: !input enable_debug_notifications | |
| motion_sensors_list: > | |
| {% if motion_sensors_var is string %} | |
| {{ [motion_sensors_var] }} | |
| {% else %} | |
| {{ motion_sensors_var | list }} | |
| {% endif %} | |
| target_lights_list: > | |
| {{ [target_lights_var] }} | |
| is_bypassed: > | |
| {% if use_bypass and bypass_switch != "" %} | |
| {{ is_state(bypass_switch, 'on') }} | |
| {% else %} | |
| false | |
| {% endif %} | |
| is_night_time: > | |
| {% set night_conditions = [] %} | |
| {% if use_ambient and ambient_sensor != "" %} | |
| {% if states(ambient_sensor) | float(999) < ambient_threshold %} | |
| {% set night_conditions = night_conditions + ['ambient_light'] %} | |
| {% endif %} | |
| {% endif %} | |
| {% if use_sun %} | |
| {% set elevation = state_attr('sun.sun', 'elevation') | float(0) %} | |
| {% set sun_state = states('sun.sun') %} | |
| {% if sun_state == 'below_horizon' %} | |
| {% if (elevation <= sun_rising) or (elevation <= sun_falling) %} | |
| {% set night_conditions = night_conditions + ['sun_elevation'] %} | |
| {% endif %} | |
| {% endif %} | |
| {% endif %} | |
| {% if use_time %} | |
| {% set current_time = now().strftime('%H:%M:%S') %} | |
| {% if time_start > time_end %} | |
| {% if current_time >= time_start or current_time <= time_end %} | |
| {% set night_conditions = night_conditions + ['time_range'] %} | |
| {% endif %} | |
| {% else %} | |
| {% if current_time >= time_start and current_time <= time_end %} | |
| {% set night_conditions = night_conditions + ['time_range'] %} | |
| {% endif %} | |
| {% endif %} | |
| {% endif %} | |
| {{ night_conditions | length > 0 }} | |
| current_brightness_pct: > | |
| {% if states(target_lights_var) == 'on' %} | |
| {% set brightness = state_attr(target_lights_var, 'brightness') | float(0) %} | |
| {% if brightness > 0 %} | |
| {{ (brightness / 255 * 100) | round(0) }} | |
| {% else %} | |
| 0 | |
| {% endif %} | |
| {% else %} | |
| 0 | |
| {% endif %} | |
| needs_night_adjustment: > | |
| {% if is_night_time and states(target_lights_var) == 'on' %} | |
| {{ current_brightness_pct != night_brightness_var and current_brightness_pct > 0 }} | |
| {% else %} | |
| false | |
| {% endif %} | |
| trigger: | |
| - platform: state | |
| entity_id: !input motion_sensors | |
| to: "on" | |
| id: motion_detected_confirmed | |
| - platform: state | |
| entity_id: !input motion_sensors | |
| to: "off" | |
| id: motion_timeout_with_grace | |
| - platform: state | |
| entity_id: !input target_lights | |
| id: light_state_change | |
| - platform: state | |
| entity_id: !input target_lights | |
| attribute: brightness | |
| id: light_state_change | |
| - platform: time | |
| at: !input night_start_time | |
| id: time_start_trigger | |
| - platform: time | |
| at: !input night_end_time | |
| id: time_end_trigger | |
| - platform: sun | |
| event: sunset | |
| offset: 0 | |
| id: sun_sunset_trigger | |
| - platform: sun | |
| event: sunrise | |
| offset: 0 | |
| id: sun_sunrise_trigger | |
| - platform: state | |
| entity_id: !input ambient_light_sensor | |
| id: ambient_light_change | |
| condition: [] | |
| action: | |
| - variables: | |
| trigger_id: "{{ trigger.id }}" | |
| trigger_from_state: "{{ trigger.from_state.state if trigger.from_state else '' }}" | |
| trigger_to_state: "{{ trigger.to_state.state if trigger.to_state else '' }}" | |
| motion_timeout_seconds: > | |
| {% set base_timeout = motion_timeout_var | int %} | |
| {% set grace = grace_period_duration | int if use_grace_period else 0 %} | |
| {{ base_timeout + grace }} | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Trigger Fired" | |
| message: "Trigger: {{ trigger_id }}, Time: {{ now().strftime('%H:%M:%S') }}, Light State: {{ states(target_lights_var) }} ({{ current_brightness_pct }}%), Night Time: {{ is_night_time }}, Bypassed: {{ is_bypassed }}" | |
| notification_id: "night_light_debug_{{ trigger_id }}" | |
| - if: | |
| - condition: template | |
| value_template: "{{ is_bypassed }}" | |
| then: | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Bypass Active" | |
| message: "Automation stopped - Bypass is ON ({{ bypass_action }})" | |
| notification_id: "night_light_debug_bypass" | |
| - choose: | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ bypass_action == 'turn_off' }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| sequence: | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 1 | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ bypass_action == 'turn_on' }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != 100 }}" | |
| sequence: | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: 100 | |
| transition: 1 | |
| - stop: "Bypass is active" | |
| - choose: | |
| - conditions: | |
| - condition: trigger | |
| id: motion_detected_confirmed | |
| - condition: template | |
| value_template: "{{ is_night_time }}" | |
| sequence: | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Motion Detected (Night)" | |
| message: "Processing motion trigger - waiting {{ motion_confirmation_delay }}s" | |
| notification_id: "night_light_debug_motion" | |
| - delay: | |
| seconds: "{{ motion_confirmation_delay }}" | |
| - condition: template | |
| value_template: > | |
| {% set motion_still_on = false %} | |
| {% for sensor in motion_sensors_list %} | |
| {% if states(sensor) == 'on' %} | |
| {% set motion_still_on = true %} | |
| {% endif %} | |
| {% endfor %} | |
| {{ motion_still_on }} | |
| - variables: | |
| last_motion_time: "{{ state_attr(this.entity_id, 'last_triggered') | as_timestamp | default(as_timestamp(now()) - 3600) }}" | |
| time_since_last_motion: "{{ as_timestamp(now()) - last_motion_time }}" | |
| - condition: template | |
| value_template: "{{ time_since_last_motion >= cooldown_period_var }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != motion_brightness }}" | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ motion_brightness }}" | |
| transition: 1 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned ON to {{ motion_brightness }}% (Motion trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_motion and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Motion Detected" | |
| message: "Lights turned on to {{ motion_brightness }}%" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_motion and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Motion detected - Lights set to {{ motion_brightness }}%" | |
| - conditions: | |
| - condition: trigger | |
| id: motion_timeout_with_grace | |
| sequence: | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Motion Cleared" | |
| message: "Waiting {{ motion_timeout_seconds }}s before adjusting lights" | |
| notification_id: "night_light_debug_timeout" | |
| - delay: | |
| seconds: "{{ motion_timeout_seconds }}" | |
| - condition: template | |
| value_template: > | |
| {% set motion_still_off = true %} | |
| {% for sensor in motion_sensors_list %} | |
| {% if states(sensor) == 'on' %} | |
| {% set motion_still_off = false %} | |
| {% endif %} | |
| {% endfor %} | |
| {{ motion_still_off }} | |
| - choose: | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ is_night_time }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != night_brightness_var }}" | |
| sequence: | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ night_brightness_var }}" | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights dimmed to {{ night_brightness_var }}% (Night mode after timeout)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_timeout and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Motion Timeout" | |
| message: "No motion - Lights dimmed to {{ night_brightness_var }}% (night mode)" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_timeout and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Motion timeout - Lights dimmed to {{ night_brightness_var }}% (night mode)" | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ not is_night_time }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| sequence: | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned OFF (Day mode after timeout)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_timeout and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Motion Timeout" | |
| message: "No motion - Lights turned off (day mode)" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_timeout and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Motion timeout - Lights turned off (day mode)" | |
| - conditions: | |
| - condition: trigger | |
| id: light_state_change | |
| sequence: | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Light State Changed" | |
| message: "Light changed: {{ trigger_from_state }} to {{ trigger_to_state }}, Brightness: {{ current_brightness_pct }}%" | |
| notification_id: "night_light_debug_light_change" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_manual_change and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Manual Light Change Detected" | |
| message: "Light {{ target_lights_var }} changed from {{ trigger_from_state }} to {{ trigger_to_state }} {% if trigger_to_state == 'on' %}at {{ current_brightness_pct }}% brightness{% endif %}" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_manual_change and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Manual Light Change Detected" | |
| message: "Light {{ target_lights_var }} changed from {{ trigger_from_state }} to {{ trigger_to_state }} {% if trigger_to_state == 'on' %}at {{ current_brightness_pct }}% brightness{% endif %}" | |
| - condition: template | |
| value_template: "{{ trigger_to_state == 'on' }}" | |
| - variables: | |
| motion_active: > | |
| {% set motion = false %} | |
| {% for sensor in motion_sensors_list %} | |
| {% if states(sensor) == 'on' %} | |
| {% set motion = true %} | |
| {% endif %} | |
| {% endfor %} | |
| {{ motion }} | |
| - condition: template | |
| value_template: "{{ not motion_active }}" | |
| - choose: | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ is_night_time }}" | |
| sequence: | |
| - delay: | |
| milliseconds: 500 | |
| - condition: template | |
| value_template: "{{ needs_night_adjustment }}" | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ night_brightness_var }}" | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Auto-adjusted to night brightness {{ night_brightness_var }}% (Manual change during night)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Night Mode Adjustment" | |
| message: "Manual light change detected - Adjusted to night brightness: {{ night_brightness_var }}%" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Manual light change detected - Adjusted to night brightness: {{ night_brightness_var }}%" | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ not is_night_time }}" | |
| sequence: | |
| - delay: | |
| seconds: "{{ bright_to_dim_timeout_var }}" | |
| - condition: template | |
| value_template: "{{ not is_night_time }}" | |
| - condition: template | |
| value_template: > | |
| {% set motion_during_delay = false %} | |
| {% for sensor in motion_sensors_list %} | |
| {% if states(sensor) == 'on' %} | |
| {% set motion_during_delay = true %} | |
| {% endif %} | |
| {% endfor %} | |
| {{ not motion_during_delay }} | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned OFF (Manual turn-on during day)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Day Mode Adjustment" | |
| message: "Manual light turned on during day - Turning off" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Manual light turned on during day - Turning off" | |
| - conditions: | |
| - condition: trigger | |
| id: time_start_trigger | |
| - condition: template | |
| value_template: "{{ use_time and enable_time_start_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != night_brightness_var }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ night_brightness_var }}" | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned ON to {{ night_brightness_var }}% (Time start trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Time Schedule Started" | |
| message: "Night start time reached - Lights set to {{ night_brightness_var }}%" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Night start time reached - Lights set to {{ night_brightness_var }}%" | |
| - conditions: | |
| - condition: trigger | |
| id: time_end_trigger | |
| - condition: template | |
| value_template: "{{ use_time and enable_time_end_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned OFF (Time end trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Time Schedule Ended" | |
| message: "Night end time reached - Lights turned off" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Night end time reached - Lights turned off" | |
| - conditions: | |
| - condition: trigger | |
| id: sun_sunset_trigger | |
| - condition: template | |
| value_template: "{{ use_sun and enable_sun_sunset_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != night_brightness_var }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ night_brightness_var }}" | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned ON to {{ night_brightness_var }}% (Sunset trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Sunset Detected" | |
| message: "Sunset occurred - Lights set to {{ night_brightness_var }}%" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Sunset occurred - Lights set to {{ night_brightness_var }}%" | |
| - conditions: | |
| - condition: trigger | |
| id: sun_sunrise_trigger | |
| - condition: template | |
| value_template: "{{ use_sun and enable_sun_sunrise_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned OFF (Sunrise trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Sunrise Detected" | |
| message: "Sunrise occurred - Lights turned off" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Sunrise occurred - Lights turned off" | |
| - conditions: | |
| - condition: trigger | |
| id: ambient_light_change | |
| - condition: template | |
| value_template: "{{ use_ambient and ambient_sensor != '' }}" | |
| sequence: | |
| - variables: | |
| light_level: "{{ states(ambient_sensor) | float(0) }}" | |
| is_dark: "{{ light_level < ambient_threshold }}" | |
| is_bright: "{{ light_level > ambient_threshold }}" | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Ambient Light Changed" | |
| message: "Level: {{ light_level }} lx, Threshold: {{ ambient_threshold }} lx, Is Dark: {{ is_dark }}, Is Bright: {{ is_bright }}" | |
| notification_id: "night_light_debug_ambient" | |
| - choose: | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ is_dark and enable_ambient_dark_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'off' or current_brightness_pct != night_brightness_var }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_on | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| brightness_pct: "{{ night_brightness_var }}" | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned ON to {{ night_brightness_var }}% (Ambient dark trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Ambient Light Dark" | |
| message: "Light level below threshold - Lights set to {{ night_brightness_var }}%" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Light level below threshold - Lights set to {{ night_brightness_var }}%" | |
| - conditions: | |
| - condition: template | |
| value_template: "{{ is_bright and enable_ambient_bright_trigger }}" | |
| - condition: template | |
| value_template: "{{ states(target_lights_var) == 'on' }}" | |
| sequence: | |
| - delay: | |
| seconds: 2 | |
| - service: light.turn_off | |
| target: | |
| entity_id: "{{ target_lights_list }}" | |
| data: | |
| transition: 2 | |
| - if: | |
| - condition: template | |
| value_template: "{{ enable_debug_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "π DEBUG: Action Taken" | |
| message: "Lights turned OFF (Ambient bright trigger)" | |
| notification_id: "night_light_debug_action" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_mobile_notifications and mobile_notify_device | length > 0 }}" | |
| then: | |
| - repeat: | |
| for_each: "{{ mobile_notify_device }}" | |
| sequence: | |
| - service: "notify.mobile_app_{{ device_attr(repeat.item, 'name') | slugify }}" | |
| data: | |
| title: "Ambient Light Bright" | |
| message: "Light level above threshold - Lights turned off" | |
| - if: | |
| - condition: template | |
| value_template: "{{ notify_on_night_adjust and enable_ui_notifications }}" | |
| then: | |
| - service: persistent_notification.create | |
| data: | |
| title: "Night Light Automation" | |
| message: "Light level above threshold - Lights turned off" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment