Skip to content

Instantly share code, notes, and snippets.

@Ltek
Last active February 25, 2026 16:50
Show Gist options
  • Select an option

  • Save Ltek/e6fce54b4553b3f05cac250ad0dba7b5 to your computer and use it in GitHub Desktop.

Select an option

Save Ltek/e6fce54b4553b3f05cac250ad0dba7b5 to your computer and use it in GitHub Desktop.
✨ Smart Light Timer by LTek
blueprint:
name: "✨ Smart Light Timer by LTek"
description: |
**✨ Smart Light Timer**
Handles both motion and manual control seamlessly — no conflicts, no workarounds, no separate automations needed.
Author: LTek
🚀 Version 2026.02.25.33c
- NEW: Per-profile Light Control settings (brightness, transition, colour) in separate UI sections
- FIX: minor visual bugs
- RECENT: Cooldown options
- RECENT: Profile-specific Additional Actions
📖 Community Discussion, Help, and Details... https://community.home-assistant.io/t/smart-light-timer-easily-create-multiple-profiles-in-a-single-automation/968751
**HOW IT WORKS**
- Enabled profiles are checked in order 1 → 2 → 3 → 4 (create your Profiles in order of priority)
- The first profile conditions to be true AND trigger restrictions match is the only profile that is ran/used.
- If no profiles are true, no actions are taken.
- Profile's Additional Actions run AFTER the main light control actions
- Additional Actions only run if the profile's conditions are met AND the profile is selected
- Additional Actions run in the order they are defined
- Trigger Types
- Controlled... Lights/switches that both trigger and are controlled by the automation
- Motion... Sensors that trigger and turn on all controlled lights
- Additional... Entities that trigger but aren't controlled (locks, covers, etc.)
NOTE >> the blueprint prevents using the same entity in both as a Trigger and as a Bypass; to avoid conflicts.
**FEATURES**
🎯 4 Profiles — Each with day/time schedules, conditions, trigger restrictions, and custom actions
⏱️ Configurable Timeouts — Per-profile time delays to keep lights on
🚧 Bypass System — Temporarily override automation to keep on, keep off, or keep as-is
⏸️ Motion Grace Period — Lights turn back on if motion detected shortly after turning off
🧊 Cooldown — Prevents rapid retriggering from motion sensors or physical switches
💫 Synchronize Entities — Turn all controlled lights on/off together, or let them operate independently
⌛ Timer Helper — Survives Home Assistant restarts
Why this blueprint is unique...
One unified automation that handles both motion control and manual override, seamlessly without conflicts and no "stepping on each other" issues that occur when multiple automations control the same entities. With other blueprints, it requires two separate automations and careful planning to do make it work properly.
This blueprint eliminates the need for complex workarounds like input_booleans, separate automation groups, or template sensors that are typically required to achieve similar functionality. It provides a clean, maintainable solution that handles the most common home automation use case: "I want my lights to turn on with motion, but also control them manually without breaking the automation."
The design ensures that manual interaction is respected while still maintaining automated control, creating a seamless user experience that feels natural rather than fighting against the automation system
source_url: https://gist.github.com/Ltek/e6fce54b4553b3f05cac250ad0dba7b5
domain: automation
input:
main_settings:
name: Main Settings
icon: mdi:lightning-bolt
collapsed: true
input:
trigger_input:
name: Controlled Triggers - Lights & Switches
description: |
These act as Triggers AND are Controlled. They turn OFF after the configured time delay
**Note** — Entities must support ON and OFF states
default: []
selector:
entity:
filter:
- domain:
- light
- switch
multiple: true
reorder: false
motion_trigger_input:
name: Motion Sensor Trigger
description: |
Motion turns ON ALL Controlled Triggers, then the configured time delay starts
Supports single or multiple sensors, and Helper Groups.
**Note** — Leave empty to disable motion triggers
default: []
selector:
entity:
filter:
- domain:
- binary_sensor
multiple: true
reorder: false
additional_trigger_input:
name: Additional Triggers (optional)
description: |
These entities act ONLY as Triggers - they will trigger the automation but will not be turned on/off.
Supported domains: Lights, Switches, Locks, Covers, Binary Sensors
default: []
selector:
entity:
filter:
- domain:
- light
- switch
- lock
- cover
- binary_sensor
multiple: true
reorder: false
include_trigger_sync:
name: Synchronize the Device Entities?
description: 'This will synchronize the ON/OFF states of all selected entities. If more than one entity is chosen, they will automatically turn ON and OFF together in sync.
'
default: disable_trigger_sync
selector:
select:
options:
- label: Enable Synchronize entities
value: enable_trigger_sync
- label: Disable Synchronize entities
value: disable_trigger_sync
multiple: false
custom_value: false
sort: false
enable_profiles:
name: Enable Profiles
description: 'Select which profiles to enable. Profiles are checked in order: 1 → 2 → 3 → 4. First true profile is used.'
default: []
selector:
select:
options:
- label: Profile 1
value: enable_condition_1
- label: Profile 2
value: enable_condition_2
- label: Profile 3
value: enable_condition_3
- label: Profile 4
value: enable_condition_4
multiple: true
custom_value: false
sort: false
conditional_delay1:
name: Profile 1 - Settings & Conditions
description: 'Check #1 - If True, Profile 2, 3 and 4 are NOT checked. ALL conditions must be true for this profile to run.'
icon: mdi:timer-cog-outline
collapsed: true
input:
condition_1_time_delay:
name: Time to Keep On
description: 'Time delay to use when Profile 1 is met.'
default:
days: 0
hours: 0
minutes: 10
seconds: 0
selector:
duration: {}
condition_1_trigger_restrictions:
name: Trigger Restrictions
description: 'Restrict which triggers can activate this profile. Leave empty to allow all triggers.'
default: []
selector:
select:
options:
- label: Motion Sensors
value: motion
- label: Controlled Devices
value: device
- label: Additional Triggers
value: additional
- label: Bypass Triggers
value: bypass
multiple: true
custom_value: false
condition_1_days:
name: Days of Week
description: 'Select days this condition applies to. Leave empty to apply to all days.'
default: []
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
multiple: true
custom_value: false
condition_1_time_after:
name: Time After
description: 'Start Time. Leave at 00:00:00 to start from midnight.'
default: '00:00:00'
selector:
time: {}
condition_1_time_before:
name: Time Before
description: 'End Time. Leave at 00:00:00 to apply until midnight.'
default: '00:00:00'
selector:
time: {}
condition_1_entity_condition:
name: Additional Conditions (optional)
description: 'Configure additional conditions for this profile. Leave empty if only day/time conditions are needed.'
default:
- condition: template
value_template: "{{true}}"
selector:
condition: {}
condition_1_additional_actions:
name: Additional Actions (optional)
description: 'Additional actions to perform when this profile is active. These actions run AFTER the main light control actions. Use for setting scenes, adjusting thermostats, sending notifications, etc.'
default: []
selector:
action: {}
conditional_delay2:
name: Profile 2 - Settings & Conditions
description: 'Check #2 - If True, Profile 3 and 4 are NOT checked.'
icon: mdi:timer-cog-outline
collapsed: true
input:
condition_2_time_delay:
name: Time to Keep On
description: 'Time delay to use when Profile 2 is met.'
default:
days: 0
hours: 0
minutes: 15
seconds: 0
selector:
duration: {}
condition_2_trigger_restrictions:
name: Trigger Restrictions
description: 'Restrict which triggers can activate this profile. Leave empty to allow all triggers.'
default: []
selector:
select:
options:
- label: Motion Sensors
value: motion
- label: Controlled Devices
value: device
- label: Additional Triggers
value: additional
- label: Bypass Triggers
value: bypass
multiple: true
custom_value: false
condition_2_days:
name: Days of Week
description: 'Select days this condition applies to. Leave empty to apply to all days.'
default: []
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
multiple: true
custom_value: false
condition_2_time_after:
name: Time After
description: 'Start Time. Leave at 00:00:00 to start from midnight.'
default: '00:00:00'
selector:
time: {}
condition_2_time_before:
name: Time Before
description: 'End Time. Leave at 00:00:00 to apply until midnight.'
default: '00:00:00'
selector:
time: {}
condition_2_entity_condition:
name: Additional Conditions (optional)
description: 'Configure additional conditions for this profile. Leave empty if only day/time conditions are needed.'
default:
- condition: template
value_template: "{{true}}"
selector:
condition: {}
condition_2_additional_actions:
name: Additional Actions (optional)
description: 'Additional actions to perform when this profile is active. These actions run AFTER the main light control actions. Use for setting scenes, adjusting thermostats, sending notifications, etc.'
default: []
selector:
action: {}
conditional_delay3:
name: Profile 3 - Settings & Conditions
description: 'Check #3 - If True, Profile 4 is NOT checked.'
icon: mdi:timer-cog-outline
collapsed: true
input:
condition_3_time_delay:
name: Time to Keep On
description: 'Time delay to use when Profile 3 is met.'
default:
days: 0
hours: 0
minutes: 20
seconds: 0
selector:
duration: {}
condition_3_trigger_restrictions:
name: Trigger Restrictions
description: 'Restrict which triggers can activate this profile. Leave empty to allow all triggers.'
default: []
selector:
select:
options:
- label: Motion Sensors
value: motion
- label: Controlled Devices
value: device
- label: Additional Triggers
value: additional
- label: Bypass Triggers
value: bypass
multiple: true
custom_value: false
condition_3_days:
name: Days of Week
description: 'Select days this condition applies to. Empty selector applies all days by Default.'
default: []
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
multiple: true
custom_value: false
condition_3_time_after:
name: Time After
description: 'Start Time. Leave at 00:00:00 to start from midnight.'
default: '00:00:00'
selector:
time: {}
condition_3_time_before:
name: Time Before
description: 'End Time. Leave at 00:00:00 to apply until midnight.'
default: '00:00:00'
selector:
time: {}
condition_3_entity_condition:
name: Additional Conditions (optional)
description: 'Configure additional conditions for this profile. Leave empty if only day/time conditions are needed.'
default:
- condition: template
value_template: "{{true}}"
selector:
condition: {}
condition_3_additional_actions:
name: Additional Actions (optional)
description: 'Additional actions to perform when this profile is active. These actions run AFTER the main light control actions. Use for setting scenes, adjusting thermostats, sending notifications, etc.'
default: []
selector:
action: {}
conditional_delay4:
name: Profile 4 - Settings & Conditions
description: 'Check #4 - Only checked when Profile 1, 2 and 3 were NOT true.'
icon: mdi:timer-cog-outline
collapsed: true
input:
condition_4_time_delay:
name: Time to Keep On
description: 'Time delay to use when Profile 4 is met.'
default:
days: 0
hours: 0
minutes: 25
seconds: 0
selector:
duration: {}
condition_4_trigger_restrictions:
name: Trigger Restrictions
description: 'Restrict which triggers can activate this profile. Leave empty to allow all triggers.'
default: []
selector:
select:
options:
- label: Motion Sensors
value: motion
- label: Controlled Devices
value: device
- label: Additional Triggers
value: additional
- label: Bypass Triggers
value: bypass
multiple: true
custom_value: false
condition_4_days:
name: Days of Week
description: 'Select days this condition applies to. Empty selector applies all days by Default.'
default: []
selector:
select:
options:
- label: Monday
value: mon
- label: Tuesday
value: tue
- label: Wednesday
value: wed
- label: Thursday
value: thu
- label: Friday
value: fri
- label: Saturday
value: sat
- label: Sunday
value: sun
multiple: true
custom_value: false
condition_4_time_after:
name: Time After
description: 'Start Time. Leave at 00:00:00 to start from midnight.'
default: '00:00:00'
selector:
time: {}
condition_4_time_before:
name: Time Before
description: 'End Time. Leave at 00:00:00 to apply until midnight.'
default: '00:00:00'
selector:
time: {}
condition_4_entity_condition:
name: Additional Conditions (optional)
description: 'Configure additional conditions for this profile. Leave empty if only day/time conditions are needed.'
default:
- condition: template
value_template: "{{true}}"
selector:
condition: {}
condition_4_additional_actions:
name: Additional Actions (optional)
description: 'Additional actions to perform when this profile is active. These actions run AFTER the main light control actions. Use for setting scenes, adjusting thermostats, sending notifications, etc.'
default: []
selector:
action: {}
profile_1_light_control:
name: "Profile 1 - Light Control"
description: 'Light control settings applied when Profile 1 is active. These settings only affect light entities.'
icon: mdi:lightbulb-on-outline
collapsed: true
input:
condition_1_include_light_control:
name: Light Control Options (Optional)
description: 'Select if you would like to use brightness or transition when Profile 1 is active.'
default: []
selector:
select:
multiple: true
options:
- label: Use Brightness
value: use_brightness
- label: Use Transition
value: use_transition
custom_value: false
sort: false
condition_1_light_brightness:
name: Brightness
description: 'The brightness level (1-100%) for lights when Profile 1 is active.'
default: 100
selector:
number:
min: 1
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
condition_1_light_transition_on:
name: Transition - ON
description: 'Transition time in seconds when lights turn ON under Profile 1.'
default: 1
selector:
number:
min: 0.0
max: 5.0
step: 0.5
unit_of_measurement: seconds
mode: slider
condition_1_light_transition_off:
name: Transition - OFF
description: 'Transition time in seconds when lights turn OFF under Profile 1.'
default: 1
selector:
number:
min: 0.0
max: 30.0
step: 1.0
unit_of_measurement: seconds
mode: slider
condition_1_include_light_colour_control:
name: Light Colour Control Options (Optional)
description: 'Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour for Profile 1.'
default: disable_colour_control
selector:
select:
options:
- label: Use Colour Temperature
value: use_colour_temperature
- label: Use RGB Colour
value: use_rgb_colour
- label: Use RGBW Colour
value: use_rgbw_colour
- label: Use RGBWW Colour
value: use_rgbww_colour
- label: Disable Colour Control
value: disable_colour_control
custom_value: false
sort: false
multiple: false
condition_1_light_colour_temperature:
name: Colour Temperature
description: 'Colour temperature in Kelvin for Profile 1 lights.'
default: 5000
selector:
number:
min: 2000.0
max: 8000.0
step: 100.0
unit_of_measurement: kelvin
mode: slider
condition_1_light_rgb_colour:
name: RGB Colour
description: 'RGB colour for Profile 1 lights.'
default: [255, 255, 255]
selector:
color_rgb: {}
condition_1_light_rgbw_colour:
name: RGBW Colour
description: 'RGBW colour for Profile 1. Enter four integers (0-255) for Red, Green, Blue, White.'
default: [255, 255, 255, 255]
selector:
object:
multiple: false
condition_1_light_rgbww_colour:
name: RGBWW Colour
description: 'RGBWW colour for Profile 1. Enter five integers (0-255) for Red, Green, Blue, Cold White, Warm White.'
default: [255, 255, 255, 255, 255]
selector:
object:
multiple: false
profile_2_light_control:
name: "Profile 2 - Light Control"
description: 'Light control settings applied when Profile 2 is active. These settings only affect light entities.'
icon: mdi:lightbulb-on-outline
collapsed: true
input:
condition_2_include_light_control:
name: Light Control Options (Optional)
description: 'Select if you would like to use brightness or transition when Profile 2 is active.'
default: []
selector:
select:
multiple: true
options:
- label: Use Brightness
value: use_brightness
- label: Use Transition
value: use_transition
custom_value: false
sort: false
condition_2_light_brightness:
name: Brightness
description: 'The brightness level (1-100%) for lights when Profile 2 is active.'
default: 100
selector:
number:
min: 1
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
condition_2_light_transition_on:
name: Transition - ON
description: 'Transition time in seconds when lights turn ON under Profile 2.'
default: 1
selector:
number:
min: 0.0
max: 5.0
step: 0.5
unit_of_measurement: seconds
mode: slider
condition_2_light_transition_off:
name: Transition - OFF
description: 'Transition time in seconds when lights turn OFF under Profile 2.'
default: 1
selector:
number:
min: 0.0
max: 30.0
step: 1.0
unit_of_measurement: seconds
mode: slider
condition_2_include_light_colour_control:
name: Light Colour Control Options (Optional)
description: 'Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour for Profile 2.'
default: disable_colour_control
selector:
select:
options:
- label: Use Colour Temperature
value: use_colour_temperature
- label: Use RGB Colour
value: use_rgb_colour
- label: Use RGBW Colour
value: use_rgbw_colour
- label: Use RGBWW Colour
value: use_rgbww_colour
- label: Disable Colour Control
value: disable_colour_control
custom_value: false
sort: false
multiple: false
condition_2_light_colour_temperature:
name: Colour Temperature
description: 'Colour temperature in Kelvin for Profile 2 lights.'
default: 5000
selector:
number:
min: 2000.0
max: 8000.0
step: 100.0
unit_of_measurement: kelvin
mode: slider
condition_2_light_rgb_colour:
name: RGB Colour
description: 'RGB colour for Profile 2 lights.'
default: [255, 255, 255]
selector:
color_rgb: {}
condition_2_light_rgbw_colour:
name: RGBW Colour
description: 'RGBW colour for Profile 2. Enter four integers (0-255) for Red, Green, Blue, White.'
default: [255, 255, 255, 255]
selector:
object:
multiple: false
condition_2_light_rgbww_colour:
name: RGBWW Colour
description: 'RGBWW colour for Profile 2. Enter five integers (0-255) for Red, Green, Blue, Cold White, Warm White.'
default: [255, 255, 255, 255, 255]
selector:
object:
multiple: false
profile_3_light_control:
name: "Profile 3 - Light Control"
description: 'Light control settings applied when Profile 3 is active. These settings only affect light entities.'
icon: mdi:lightbulb-on-outline
collapsed: true
input:
condition_3_include_light_control:
name: Light Control Options (Optional)
description: 'Select if you would like to use brightness or transition when Profile 3 is active.'
default: []
selector:
select:
multiple: true
options:
- label: Use Brightness
value: use_brightness
- label: Use Transition
value: use_transition
custom_value: false
sort: false
condition_3_light_brightness:
name: Brightness
description: 'The brightness level (1-100%) for lights when Profile 3 is active.'
default: 100
selector:
number:
min: 1
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
condition_3_light_transition_on:
name: Transition - ON
description: 'Transition time in seconds when lights turn ON under Profile 3.'
default: 1
selector:
number:
min: 0.0
max: 5.0
step: 0.5
unit_of_measurement: seconds
mode: slider
condition_3_light_transition_off:
name: Transition - OFF
description: 'Transition time in seconds when lights turn OFF under Profile 3.'
default: 1
selector:
number:
min: 0.0
max: 30.0
step: 1.0
unit_of_measurement: seconds
mode: slider
condition_3_include_light_colour_control:
name: Light Colour Control Options (Optional)
description: 'Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour for Profile 3.'
default: disable_colour_control
selector:
select:
options:
- label: Use Colour Temperature
value: use_colour_temperature
- label: Use RGB Colour
value: use_rgb_colour
- label: Use RGBW Colour
value: use_rgbw_colour
- label: Use RGBWW Colour
value: use_rgbww_colour
- label: Disable Colour Control
value: disable_colour_control
custom_value: false
sort: false
multiple: false
condition_3_light_colour_temperature:
name: Colour Temperature
description: 'Colour temperature in Kelvin for Profile 3 lights.'
default: 5000
selector:
number:
min: 2000.0
max: 8000.0
step: 100.0
unit_of_measurement: kelvin
mode: slider
condition_3_light_rgb_colour:
name: RGB Colour
description: 'RGB colour for Profile 3 lights.'
default: [255, 255, 255]
selector:
color_rgb: {}
condition_3_light_rgbw_colour:
name: RGBW Colour
description: 'RGBW colour for Profile 3. Enter four integers (0-255) for Red, Green, Blue, White.'
default: [255, 255, 255, 255]
selector:
object:
multiple: false
condition_3_light_rgbww_colour:
name: RGBWW Colour
description: 'RGBWW colour for Profile 3. Enter five integers (0-255) for Red, Green, Blue, Cold White, Warm White.'
default: [255, 255, 255, 255, 255]
selector:
object:
multiple: false
profile_4_light_control:
name: "Profile 4 - Light Control"
description: 'Light control settings applied when Profile 4 is active. These settings only affect light entities.'
icon: mdi:lightbulb-on-outline
collapsed: true
input:
condition_4_include_light_control:
name: Light Control Options (Optional)
description: 'Select if you would like to use brightness or transition when Profile 4 is active.'
default: []
selector:
select:
multiple: true
options:
- label: Use Brightness
value: use_brightness
- label: Use Transition
value: use_transition
custom_value: false
sort: false
condition_4_light_brightness:
name: Brightness
description: 'The brightness level (1-100%) for lights when Profile 4 is active.'
default: 100
selector:
number:
min: 1
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
condition_4_light_transition_on:
name: Transition - ON
description: 'Transition time in seconds when lights turn ON under Profile 4.'
default: 1
selector:
number:
min: 0.0
max: 5.0
step: 0.5
unit_of_measurement: seconds
mode: slider
condition_4_light_transition_off:
name: Transition - OFF
description: 'Transition time in seconds when lights turn OFF under Profile 4.'
default: 1
selector:
number:
min: 0.0
max: 30.0
step: 1.0
unit_of_measurement: seconds
mode: slider
condition_4_include_light_colour_control:
name: Light Colour Control Options (Optional)
description: 'Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour for Profile 4.'
default: disable_colour_control
selector:
select:
options:
- label: Use Colour Temperature
value: use_colour_temperature
- label: Use RGB Colour
value: use_rgb_colour
- label: Use RGBW Colour
value: use_rgbw_colour
- label: Use RGBWW Colour
value: use_rgbww_colour
- label: Disable Colour Control
value: disable_colour_control
custom_value: false
sort: false
multiple: false
condition_4_light_colour_temperature:
name: Colour Temperature
description: 'Colour temperature in Kelvin for Profile 4 lights.'
default: 5000
selector:
number:
min: 2000.0
max: 8000.0
step: 100.0
unit_of_measurement: kelvin
mode: slider
condition_4_light_rgb_colour:
name: RGB Colour
description: 'RGB colour for Profile 4 lights.'
default: [255, 255, 255]
selector:
color_rgb: {}
condition_4_light_rgbw_colour:
name: RGBW Colour
description: 'RGBW colour for Profile 4. Enter four integers (0-255) for Red, Green, Blue, White.'
default: [255, 255, 255, 255]
selector:
object:
multiple: false
condition_4_light_rgbww_colour:
name: RGBWW Colour
description: 'RGBWW colour for Profile 4. Enter five integers (0-255) for Red, Green, Blue, Cold White, Warm White.'
default: [255, 255, 255, 255, 255]
selector:
object:
multiple: false
motion:
name: Motion Sensor Time Delay
icon: mdi:motion-sensor
collapsed: true
input:
include_motion_trigger:
name: Use the Motion Sensor Time Delay? (Optional)
description: 'Enable this option to use a motion sensor for time delay control. Whether using a timer helper or the built-in time delay in Home Assistant, the timer or delay will pause while motion is detected and reset once motion is cleared.'
default: disable_motion_trigger
selector:
select:
options:
- label: Enable the Motion Sensor Time Delay
value: enable_motion_trigger
- label: Disable the Motion Sensor Time Delay
value: disable_motion_trigger
multiple: false
custom_value: false
sort: false
motion_trigger:
name: Motion Sensor Time Delay - Binary Sensors
description: 'Select a single motion sensor or binary sensor to use for time delay control. If you need to use multiple sensors, group them together using a group helper first.'
default: ""
selector:
entity:
filter:
- domain:
- binary_sensor
multiple: false
reorder: false
advanced_timers:
name: Advanced Timing Controls
icon: mdi:timer-plus-outline
collapsed: true
input:
include_timer_helper:
name: Use a Timer Helper? (optional)
description: 'If you want to use a Timer Helper entity.
**Note** : Create the Timer Helper and enable `Restore` so it will survive a Home Assistant restart. Do not set a duration in the timer helper itself; the time is controlled by the settings below.'
default: disable_timer_helper
selector:
select:
options:
- label: Enable Timer Helper
value: enable_timer_helper
- label: Disable Timer Helper
value: disable_timer_helper
multiple: false
custom_value: false
sort: false
timer_helper:
name: Timer Helper Entity
description: 'Choose the timer helper. Must be created manually in Home Assistant.'
default: ""
selector:
entity:
filter:
- domain:
- timer
multiple: false
reorder: false
# ============================================
# ENHANCED: SEPARATE COOLDOWN SETTINGS
# ============================================
enable_motion_cooldown:
name: Enable Motion Cooldown
description: 'Prevents rapid retriggering from motion sensors. Motion triggers will be ignored for the cooldown period after the last trigger.'
default: true
selector:
boolean: {}
motion_cooldown_time:
name: Motion Cooldown Duration
description: 'How long to ignore motion triggers after the last motion trigger. Helps prevent timer reset from continuous motion.'
default:
days: 0
hours: 0
minutes: 0
seconds: 10
selector:
duration: {}
enable_device_cooldown:
name: Enable Device Cooldown
description: 'Optional: Prevents rapid retriggering from device triggers (lights/switches). Useful for debouncing physical switches.'
default: false
selector:
boolean: {}
device_cooldown_time:
name: Device Cooldown Duration
description: 'How long to ignore device triggers after the last device trigger. Usually 1-3 seconds for switch debouncing.'
default:
days: 0
hours: 0
minutes: 0
seconds: 2
selector:
duration: {}
grace_period:
name: Motion Grace Period (optional)
icon: mdi:motion-sensor-off
collapsed: true
input:
include_grace_period:
name: Use Motion Grace Period?
description: 'Introduces a time period after the lights turn OFF due to no motion. If motion is detected during this period, the lights will turn back ON automatically.
**Note** - This option only works when the motion sensor time delay is enabled.'
default: disable_grace_period
selector:
select:
options:
- label: Enable Motion Grace Period
value: enable_grace_period
- label: Disable Motion Grace Period
value: disable_grace_period
multiple: false
custom_value: false
sort: false
grace_period_timer_helper:
name: Grace Period Timer Helper
description: 'Select the timer helper to be used if you have chosen to use a grace period above.
**Note** — When creating your timer helper, tick the `Restore` box so it will survive a Home Assistant restart. Do not set a duration in the timer helper itself; the time is controlled by the settings below.
If using a timer in the **Timer Helper Option** above, you must use a separate, independent timer here.'
default: ""
selector:
entity:
filter:
- domain:
- timer
multiple: false
reorder: false
grace_period_time_delay:
name: Grace Period Time Delay
description: 'Set how long the grace period lasts after the lights turn OFF due to no motion. During this time, if motion is detected, the lights will turn back ON automatically. After the grace period ends, the lights must be switched ON manually.'
default:
days: 0
hours: 0
minutes: 5
seconds: 0
selector:
duration: {}
saved_lights_input:
name: Text Helper to Save ON Lights
description: 'Can be used when you have more than one trigger entity and are not using **Synchronize Entities**. Create a `text helper` entity for the automation to use to store the list of lights that are ON.
**Note** — Leave empty if you are using only one trigger entity or the **Synchronize Entities** is enabled.'
default: ""
selector:
entity:
filter:
- domain:
- input_text
multiple: false
reorder: false
bypass_settings:
name: Bypass (optional)
icon: mdi:cog-pause-outline
collapsed: true
input:
include_bypass:
name: Use Bypass
description: "Each option determines lights behaviors when the Bypass entity state is ON:\n\n 1 - Turns Lights ON\n 2 - Turns Lights OFF\n 3 - Keeps Lights at the current state\n\nNOTE - each enabled option requires the corresponding bypass entity selected."
default: []
selector:
select:
options:
- label: 1 - Bypass Turns Lights ON
value: bypass_enabled_turn_on
- label: 2 - Bypass Turns Lights OFF
value: bypass_enabled_turn_off
- label: 3 - Bypass Keeps Lights at Current State
value: bypass_enabled_stop
multiple: true
custom_value: false
sort: false
bypass_lights_on:
name: Turn Lights ON
description: 'Select the switches that will turn your lights ON, bypass the trigger sensor, and allow your lights to function as normal. Please note that the entity cannot be included in the "Trigger - Lights & Switches" selections.'
default: []
selector:
entity:
filter:
- domain:
- switch
- input_boolean
multiple: true
reorder: false
bypass_lights_off:
name: Turn Lights OFF
description: 'Select the switches that will turn your lights OFF, bypass the trigger sensor, and allow your lights to function as normal. Please note that the entity cannot be included in the "Trigger - Lights & Switches" selections.'
default: []
selector:
entity:
filter:
- domain:
- switch
- input_boolean
multiple: true
reorder: false
bypass_lights_stop:
name: Keep the Lights Current State
description: 'Select the switches that will keep your lights current state, bypass the trigger sensor, and allow your lights to function as normal. Please note that the entity cannot be included in the "Trigger - Lights & Switches" selections.'
default: []
selector:
entity:
filter:
- domain:
- switch
- input_boolean
multiple: true
reorder: false
bypass_time_delay:
name: Bypass Time Delay
description: "This delay is used only with these specific bypass scenarios when your lights are ON.\n\n -- When Bypass is enabled and Option 2 is selected (Turn Lights OFF)\n -- When all bypasses are OFF and the lights remain ON.\n\nIn both cases, the automation will turn the lights OFF after the configured time delay."
default: 0
selector:
number:
min: 0.0
max: 10.0
step: 0.25
unit_of_measurement: minutes
mode: slider
include_bypass_auto_off:
name: Use The Bypass Auto OFF Option (Optional)
description: "Enable this option if you want the bypass to automatically turn OFF after a set time delay. You can choose which bypass option the auto OFF will apply to:\n\nEach option corresponds to one of the bypass options above."
default: []
selector:
select:
options:
- label: 1 - Turn Lights ON
value: bypass_auto_off_enabled_on
- label: 2 - Turn Lights OFF
value: bypass_auto_off_enabled_off
- label: 3 - Keep Lights at Current State
value: bypass_auto_off_enabled_stop
multiple: true
custom_value: false
sort: false
bypass_auto_off_delay:
name: Bypass Auto OFF - Time Delay
description: 'Set the bypass auto OFF time delay. The time delay starts from the last bypass that was turned ON. If multiple bypasses are ON, turning one OFF while another remains ON will also reset the time delay.'
default: 60
selector:
number:
min: 1.0
max: 240.0
step: 1.0
unit_of_measurement: minutes
mode: slider
debug_settings:
name: Debug Settings
icon: mdi:bug
collapsed: true
input:
enable_debug:
name: Enable Debug Mode
description: 'When enabled, the automation will send persistent Web UI notifications for every trigger event, showing the trigger that started the automation, the entity, and its value. It will also indicate whether defaults or a specific profile number was used.'
default: false
selector:
boolean: {}
mode: single
max_exceeded: silent
variables:
# Timer Helper variables
include_timer_helper: !input include_timer_helper
timer_helper: !input timer_helper
# ENHANCED: Separate cooldown variables
enable_motion_cooldown: !input enable_motion_cooldown
motion_cooldown_time: !input motion_cooldown_time
enable_device_cooldown: !input enable_device_cooldown
device_cooldown_time: !input device_cooldown_time
# Profile enable variables
enable_profiles: !input enable_profiles
enable_condition_1: "{{ 'enable_condition_1' in enable_profiles }}"
enable_condition_2: "{{ 'enable_condition_2' in enable_profiles }}"
enable_condition_3: "{{ 'enable_condition_3' in enable_profiles }}"
enable_condition_4: "{{ 'enable_condition_4' in enable_profiles }}"
# Trigger restrictions variables
condition_1_trigger_restrictions: !input condition_1_trigger_restrictions
condition_2_trigger_restrictions: !input condition_2_trigger_restrictions
condition_3_trigger_restrictions: !input condition_3_trigger_restrictions
condition_4_trigger_restrictions: !input condition_4_trigger_restrictions
# Additional Actions variables
condition_1_additional_actions: !input condition_1_additional_actions
condition_2_additional_actions: !input condition_2_additional_actions
condition_3_additional_actions: !input condition_3_additional_actions
condition_4_additional_actions: !input condition_4_additional_actions
# Current timestamp
now_ts: "{{ now().timestamp() }}"
# Additional Conditions variables
condition_1_entity_condition: !input condition_1_entity_condition
condition_2_entity_condition: !input condition_2_entity_condition
condition_3_entity_condition: !input condition_3_entity_condition
condition_4_entity_condition: !input condition_4_entity_condition
# Existing variables
enable_debug: !input enable_debug
trigger_input: !input trigger_input
motion_trigger_input: !input motion_trigger_input
additional_trigger_input: !input additional_trigger_input
include_motion_trigger: !input include_motion_trigger
motion_trigger: !input motion_trigger
include_grace_period: !input include_grace_period
grace_period_timer_helper: !input grace_period_timer_helper
grace_period_time_delay: !input grace_period_time_delay
saved_lights_input: !input saved_lights_input
include_bypass: !input include_bypass
bypass_lights_on: !input bypass_lights_on
bypass_lights_off: !input bypass_lights_off
bypass_lights_stop: !input bypass_lights_stop
bypass_time_delay: !input bypass_time_delay
include_bypass_auto_off: !input include_bypass_auto_off
bypass_auto_off_delay: !input bypass_auto_off_delay
# Profile 1 variables
condition_1_include_light_control: !input condition_1_include_light_control
condition_1_light_brightness: !input condition_1_light_brightness
condition_1_light_transition_on: !input condition_1_light_transition_on
condition_1_light_transition_off: !input condition_1_light_transition_off
condition_1_include_light_colour_control: !input condition_1_include_light_colour_control
condition_1_light_colour_temperature: !input condition_1_light_colour_temperature
condition_1_light_rgb_colour: !input condition_1_light_rgb_colour
condition_1_light_rgbw_colour: !input condition_1_light_rgbw_colour
condition_1_light_rgbww_colour: !input condition_1_light_rgbww_colour
condition_1_time_delay: !input condition_1_time_delay
condition_1_days: !input condition_1_days
condition_1_time_after: !input condition_1_time_after
condition_1_time_before: !input condition_1_time_before
# Profile 2 variables
condition_2_include_light_control: !input condition_2_include_light_control
condition_2_light_brightness: !input condition_2_light_brightness
condition_2_light_transition_on: !input condition_2_light_transition_on
condition_2_light_transition_off: !input condition_2_light_transition_off
condition_2_include_light_colour_control: !input condition_2_include_light_colour_control
condition_2_light_colour_temperature: !input condition_2_light_colour_temperature
condition_2_light_rgb_colour: !input condition_2_light_rgb_colour
condition_2_light_rgbw_colour: !input condition_2_light_rgbw_colour
condition_2_light_rgbww_colour: !input condition_2_light_rgbww_colour
condition_2_time_delay: !input condition_2_time_delay
condition_2_days: !input condition_2_days
condition_2_time_after: !input condition_2_time_after
condition_2_time_before: !input condition_2_time_before
# Profile 3 variables
condition_3_include_light_control: !input condition_3_include_light_control
condition_3_light_brightness: !input condition_3_light_brightness
condition_3_light_transition_on: !input condition_3_light_transition_on
condition_3_light_transition_off: !input condition_3_light_transition_off
condition_3_include_light_colour_control: !input condition_3_include_light_colour_control
condition_3_light_colour_temperature: !input condition_3_light_colour_temperature
condition_3_light_rgb_colour: !input condition_3_light_rgb_colour
condition_3_light_rgbw_colour: !input condition_3_light_rgbw_colour
condition_3_light_rgbww_colour: !input condition_3_light_rgbww_colour
condition_3_time_delay: !input condition_3_time_delay
condition_3_days: !input condition_3_days
condition_3_time_after: !input condition_3_time_after
condition_3_time_before: !input condition_3_time_before
# Profile 4 variables
condition_4_include_light_control: !input condition_4_include_light_control
condition_4_light_brightness: !input condition_4_light_brightness
condition_4_light_transition_on: !input condition_4_light_transition_on
condition_4_light_transition_off: !input condition_4_light_transition_off
condition_4_include_light_colour_control: !input condition_4_include_light_colour_control
condition_4_light_colour_temperature: !input condition_4_light_colour_temperature
condition_4_light_rgb_colour: !input condition_4_light_rgb_colour
condition_4_light_rgbw_colour: !input condition_4_light_rgbw_colour
condition_4_light_rgbww_colour: !input condition_4_light_rgbww_colour
condition_4_time_delay: !input condition_4_time_delay
condition_4_days: !input condition_4_days
condition_4_time_after: !input condition_4_time_after
condition_4_time_before: !input condition_4_time_before
# Main Settings variables
include_trigger_sync: !input include_trigger_sync
# Default settings
time_delay:
days: 0
hours: 0
minutes: 5
seconds: 0
default_brightness: 100
# Helper variables
trigger_entities_on: "{{ expand(trigger_input) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}"
trigger_entities_off: "{{ expand(trigger_input) | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}"
# Determine trigger type
trigger_type: >-
{% if trigger.id in ["t0_motion_trigger", "t4_motion_delay"] %}
{{ "motion" }}
{% elif trigger.id in ["t1", "t2"] %}
{{ "device" }}
{% elif trigger.id == "t1a" %}
{{ "additional" }}
{% elif trigger.id in ["t5_on", "t5_off", "t5_stop", "t6_on", "t6_off", "t6_stop"] %}
{{ "bypass" }}
{% else %}
{{ "unknown" }}
{% endif %}
# Initialize profile variables
current_profile: 0
active_time_delay: "{{ time_delay }}"
active_brightness: "{{ default_brightness }}"
active_include_light_control: []
active_light_transition_on: 1
active_light_transition_off: 1
active_include_light_colour_control: "disable_colour_control"
active_light_colour_temperature: 5000
active_light_rgb_colour: [255, 255, 255]
active_light_rgbw_colour: [255, 255, 255, 255]
active_light_rgbww_colour: [255, 255, 255, 255, 255]
trigger_variables:
timer_helper: !input timer_helper
motion_trigger: !input motion_trigger
triggers:
# Main motion trigger - turns lights ON when motion is detected
- trigger: state
id: t0_motion_trigger
entity_id: !input motion_trigger_input
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 0
# Device triggers - with debounce to prevent loops
- trigger: state
id: t1
entity_id: !input trigger_input
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 2
- trigger: state
id: t1a
entity_id: !input additional_trigger_input
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 2
- trigger: state
id: t2
entity_id: !input trigger_input
from: 'on'
to: 'off'
for:
hours: 0
minutes: 0
seconds: 2
# Timer helper idle trigger - fires when optional timer helper finishes
- trigger: template
id: t3
value_template: >-
{{ timer_helper != '' and timer_helper != none and timer_helper != []
and is_state(timer_helper, 'idle') }}
# Motion delay trigger - resets timer when motion is detected while lights are ON
- trigger: template
id: t4_motion_delay
value_template: >-
{{ motion_trigger != '' and motion_trigger != none and motion_trigger != []
and is_state(motion_trigger, 'on') }}
# Bypass triggers - with debounce
- trigger: state
id: t5_on
entity_id: !input bypass_lights_on
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: state
id: t5_off
entity_id: !input bypass_lights_off
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: state
id: t5_stop
entity_id: !input bypass_lights_stop
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: state
id: t6_on
entity_id: !input bypass_lights_on
from: 'on'
to: 'off'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: state
id: t6_off
entity_id: !input bypass_lights_off
from: 'on'
to: 'off'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: state
id: t6_stop
entity_id: !input bypass_lights_stop
from: 'on'
to: 'off'
for:
hours: 0
minutes: 0
seconds: 1
- trigger: homeassistant
id: t7
event: start
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: trigger
id: t0_motion_trigger
- condition: and
conditions:
- condition: trigger
id:
- t1
- t1a
- condition: state
entity_id: !input trigger_input
match: any
state: 'on'
- alias: Check if grace period entity state is enabled
condition: or
conditions:
- condition: and
conditions:
- '{{ include_grace_period == ''enable_grace_period'' }}'
- condition: template
value_template: '{{ is_state(grace_period_timer_helper, ''idle'') }}'
- condition: template
value_template: '{{ include_grace_period == ''disable_grace_period'' }}'
- condition: template
value_template: '{{ trigger.to_state.context.parent_id is none }}'
- condition: and
conditions:
- condition: trigger
id: t2
- condition: template
value_template: '{{include_trigger_sync == ''enable_trigger_sync''}}'
- condition: and
conditions:
- condition: trigger
id: t3
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
- condition: template
value_template: '{{ expand(trigger_input) | selectattr(''state'', ''=='', ''on'') | list | count > 0 }}'
- condition: and
conditions:
- condition: trigger
id: t4_motion_delay
- '{{include_motion_trigger == ''enable_motion_trigger''}}'
- alias: Pass if lights are off (t0 fallback), lights are on, or grace period is active
condition: or
conditions:
- condition: template
value_template: '{{ expand(trigger_input) | selectattr(''state'', ''=='', ''off'') | list | count > 0 }}'
- condition: and
conditions:
- condition: template
value_template: '{{ expand(trigger_input) | selectattr(''state'', ''=='', ''on'') | list | count > 0 }}'
- condition: and
conditions:
- condition: template
value_template: '{{ include_grace_period == ''enable_grace_period'' }}'
- condition: template
value_template: '{{ is_state(grace_period_timer_helper, ''active'') }}'
- condition: and
conditions:
- condition: trigger
id: t5_on
- '{{ ''bypass_enabled_turn_on'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t5_off
- '{{ ''bypass_enabled_turn_off'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t5_stop
- '{{ ''bypass_enabled_stop'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t6_on
- '{{ ''bypass_enabled_turn_on'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t6_off
- '{{ ''bypass_enabled_turn_off'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t6_stop
- '{{ ''bypass_enabled_stop'' in include_bypass }}'
- condition: and
conditions:
- condition: trigger
id: t7
- condition: template
value_template: '{{ expand(trigger_input) | selectattr(''state'', ''=='', ''on'') | list | count > 0 }}'
- condition: and
conditions:
- condition: trigger
id: t7
- '{{ (''bypass_enabled_turn_on'' in include_bypass) or (''bypass_enabled_turn_off'' in include_bypass) or (''bypass_enabled_stop'' in include_bypass) }}'
- '{{ (''bypass_auto_off_enabled_on'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) or (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
- condition: or
conditions:
- condition: state
entity_id: !input bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input bypass_lights_stop
match: any
state: 'on'
- condition: or
conditions:
- '{{ include_bypass == [] }}'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_on
state: 'off'
- condition: state
entity_id: !input bypass_lights_off
state: 'off'
- condition: state
entity_id: !input bypass_lights_stop
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_on
state: 'off'
- condition: state
entity_id: !input bypass_lights_off
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off'' not in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_on
state: 'off'
- condition: state
entity_id: !input bypass_lights_stop
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_off
state: 'off'
- condition: state
entity_id: !input bypass_lights_stop
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_enabled_turn_off'' not in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_on
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_enabled_stop'' not in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_off
state: 'off'
- condition: and
conditions:
- '{{ (''bypass_enabled_turn_on'' not in include_bypass) and (''bypass_enabled_turn_off'' not in include_bypass) and (''bypass_enabled_stop'' in include_bypass) }}'
- condition: state
entity_id: !input bypass_lights_stop
state: 'off'
- condition: trigger
id:
- t0_motion_trigger
- t4_motion_delay
- t5_on
- t5_off
- t5_stop
- t6_on
- t6_off
- t6_stop
- t7
action:
# Initialize profile selection variables
- variables:
profile_matched: false
selected_profile: 0
selected_time_delay: "{{ time_delay }}"
selected_brightness: "{{ default_brightness }}"
# Evaluate Profile 1 if enabled
- if:
condition: template
value_template: "{{ enable_condition_1 and not profile_matched }}"
then:
# Check day of week
- if:
condition: template
value_template: >
{% if condition_1_days|length > 0 %}
{% set current_day = now().strftime('%a').lower() %}
{{ current_day in condition_1_days }}
{% else %}
true
{% endif %}
then:
# Check time window
- if:
condition: template
value_template: >
{% if condition_1_time_after != '00:00:00' or condition_1_time_before != '00:00:00' %}
{% set current_time = now().strftime('%H:%M:%S') %}
{% if condition_1_time_after < condition_1_time_before %}
{{ condition_1_time_after <= current_time < condition_1_time_before }}
{% else %}
{{ current_time >= condition_1_time_after or current_time < condition_1_time_before }}
{% endif %}
{% else %}
true
{% endif %}
then:
# Check trigger restrictions
- if:
condition: template
value_template: >
{% if condition_1_trigger_restrictions|length > 0 %}
{{ trigger_type in condition_1_trigger_restrictions }}
{% else %}
true
{% endif %}
then:
# Check additional conditions using !input directly
- if: !input condition_1_entity_condition
then:
- variables:
profile_matched: true
selected_profile: 1
selected_time_delay: "{{ condition_1_time_delay }}"
selected_brightness: "{{ condition_1_light_brightness }}"
selected_include_light_control: "{{ condition_1_include_light_control }}"
selected_light_transition_on: "{{ condition_1_light_transition_on }}"
selected_light_transition_off: "{{ condition_1_light_transition_off }}"
selected_include_light_colour_control: "{{ condition_1_include_light_colour_control }}"
selected_light_colour_temperature: "{{ condition_1_light_colour_temperature }}"
selected_light_rgb_colour: "{{ condition_1_light_rgb_colour }}"
selected_light_rgbw_colour: "{{ condition_1_light_rgbw_colour }}"
selected_light_rgbww_colour: "{{ condition_1_light_rgbww_colour }}"
alias: "Profile 1 selected"
# Evaluate Profile 2 if enabled and no profile matched yet
- if:
condition: template
value_template: "{{ enable_condition_2 and not profile_matched }}"
then:
# Check day of week
- if:
condition: template
value_template: >
{% if condition_2_days|length > 0 %}
{% set current_day = now().strftime('%a').lower() %}
{{ current_day in condition_2_days }}
{% else %}
true
{% endif %}
then:
# Check time window
- if:
condition: template
value_template: >
{% if condition_2_time_after != '00:00:00' or condition_2_time_before != '00:00:00' %}
{% set current_time = now().strftime('%H:%M:%S') %}
{% if condition_2_time_after < condition_2_time_before %}
{{ condition_2_time_after <= current_time < condition_2_time_before }}
{% else %}
{{ current_time >= condition_2_time_after or current_time < condition_2_time_before }}
{% endif %}
{% else %}
true
{% endif %}
then:
# Check trigger restrictions
- if:
condition: template
value_template: >
{% if condition_2_trigger_restrictions|length > 0 %}
{{ trigger_type in condition_2_trigger_restrictions }}
{% else %}
true
{% endif %}
then:
# Check additional conditions using !input directly
- if: !input condition_2_entity_condition
then:
- variables:
profile_matched: true
selected_profile: 2
selected_time_delay: "{{ condition_2_time_delay }}"
selected_brightness: "{{ condition_2_light_brightness }}"
selected_include_light_control: "{{ condition_2_include_light_control }}"
selected_light_transition_on: "{{ condition_2_light_transition_on }}"
selected_light_transition_off: "{{ condition_2_light_transition_off }}"
selected_include_light_colour_control: "{{ condition_2_include_light_colour_control }}"
selected_light_colour_temperature: "{{ condition_2_light_colour_temperature }}"
selected_light_rgb_colour: "{{ condition_2_light_rgb_colour }}"
selected_light_rgbw_colour: "{{ condition_2_light_rgbw_colour }}"
selected_light_rgbww_colour: "{{ condition_2_light_rgbww_colour }}"
alias: "Profile 2 selected"
# Evaluate Profile 3 if enabled and no profile matched yet
- if:
condition: template
value_template: "{{ enable_condition_3 and not profile_matched }}"
then:
# Check day of week
- if:
condition: template
value_template: >
{% if condition_3_days|length > 0 %}
{% set current_day = now().strftime('%a').lower() %}
{{ current_day in condition_3_days }}
{% else %}
true
{% endif %}
then:
# Check time window
- if:
condition: template
value_template: >
{% if condition_3_time_after != '00:00:00' or condition_3_time_before != '00:00:00' %}
{% set current_time = now().strftime('%H:%M:%S') %}
{% if condition_3_time_after < condition_3_time_before %}
{{ condition_3_time_after <= current_time < condition_3_time_before }}
{% else %}
{{ current_time >= condition_3_time_after or current_time < condition_3_time_before }}
{% endif %}
{% else %}
true
{% endif %}
then:
# Check trigger restrictions
- if:
condition: template
value_template: >
{% if condition_3_trigger_restrictions|length > 0 %}
{{ trigger_type in condition_3_trigger_restrictions }}
{% else %}
true
{% endif %}
then:
# Check additional conditions using !input directly
- if: !input condition_3_entity_condition
then:
- variables:
profile_matched: true
selected_profile: 3
selected_time_delay: "{{ condition_3_time_delay }}"
selected_brightness: "{{ condition_3_light_brightness }}"
selected_include_light_control: "{{ condition_3_include_light_control }}"
selected_light_transition_on: "{{ condition_3_light_transition_on }}"
selected_light_transition_off: "{{ condition_3_light_transition_off }}"
selected_include_light_colour_control: "{{ condition_3_include_light_colour_control }}"
selected_light_colour_temperature: "{{ condition_3_light_colour_temperature }}"
selected_light_rgb_colour: "{{ condition_3_light_rgb_colour }}"
selected_light_rgbw_colour: "{{ condition_3_light_rgbw_colour }}"
selected_light_rgbww_colour: "{{ condition_3_light_rgbww_colour }}"
alias: "Profile 3 selected"
# Evaluate Profile 4 if enabled and no profile matched yet
- if:
condition: template
value_template: "{{ enable_condition_4 and not profile_matched }}"
then:
# Check day of week
- if:
condition: template
value_template: >
{% if condition_4_days|length > 0 %}
{% set current_day = now().strftime('%a').lower() %}
{{ current_day in condition_4_days }}
{% else %}
true
{% endif %}
then:
# Check time window
- if:
condition: template
value_template: >
{% if condition_4_time_after != '00:00:00' or condition_4_time_before != '00:00:00' %}
{% set current_time = now().strftime('%H:%M:%S') %}
{% if condition_4_time_after < condition_4_time_before %}
{{ condition_4_time_after <= current_time < condition_4_time_before }}
{% else %}
{{ current_time >= condition_4_time_after or current_time < condition_4_time_before }}
{% endif %}
{% else %}
true
{% endif %}
then:
# Check trigger restrictions
- if:
condition: template
value_template: >
{% if condition_4_trigger_restrictions|length > 0 %}
{{ trigger_type in condition_4_trigger_restrictions }}
{% else %}
true
{% endif %}
then:
# Check additional conditions using !input directly
- if: !input condition_4_entity_condition
then:
- variables:
profile_matched: true
selected_profile: 4
selected_time_delay: "{{ condition_4_time_delay }}"
selected_brightness: "{{ condition_4_light_brightness }}"
selected_include_light_control: "{{ condition_4_include_light_control }}"
selected_light_transition_on: "{{ condition_4_light_transition_on }}"
selected_light_transition_off: "{{ condition_4_light_transition_off }}"
selected_include_light_colour_control: "{{ condition_4_include_light_colour_control }}"
selected_light_colour_temperature: "{{ condition_4_light_colour_temperature }}"
selected_light_rgb_colour: "{{ condition_4_light_rgb_colour }}"
selected_light_rgbw_colour: "{{ condition_4_light_rgbw_colour }}"
selected_light_rgbww_colour: "{{ condition_4_light_rgbww_colour }}"
alias: "Profile 4 selected"
# Stop automation if no profile matched
- if:
condition: template
value_template: "{{ not profile_matched }}"
then:
- stop: "No profile matched - stopping automation"
# Set the active profile variables for use in actions
- variables:
current_profile: "{{ selected_profile }}"
active_time_delay: "{{ selected_time_delay }}"
active_brightness: "{{ selected_brightness }}"
active_include_light_control: "{{ selected_include_light_control }}"
active_light_transition_on: "{{ selected_light_transition_on }}"
active_light_transition_off: "{{ selected_light_transition_off }}"
active_include_light_colour_control: "{{ selected_include_light_colour_control }}"
active_light_colour_temperature: "{{ selected_light_colour_temperature }}"
active_light_rgb_colour: "{{ selected_light_rgb_colour }}"
active_light_rgbw_colour: "{{ selected_light_rgbw_colour }}"
active_light_rgbww_colour: "{{ selected_light_rgbww_colour }}"
# Update debug notification with profile info
- choose:
- conditions: "{{ enable_debug }}"
sequence:
- alias: Update Debug Notification with Profile
action: persistent_notification.create
data:
notification_id: "{{ state_attr(this.entity_id, 'friendly_name') }}"
title: "{{ state_attr(this.entity_id, 'friendly_name') }} Debug"
message: |
**Time:** {{ now() }}
**Trigger:** {{ trigger.id }}
**Trigger Type:** {{ trigger_type }}
**Selected Profile:** {{ selected_profile }}
**Time Delay:** {{ selected_time_delay }}
**Brightness:** {{ selected_brightness }}%
**Light Control:** {{ selected_include_light_control }}
**Transition ON:** {{ selected_light_transition_on }}s
**Transition OFF:** {{ selected_light_transition_off }}s
**Colour Control:** {{ selected_include_light_colour_control }}
**Profile Matched:** {{ profile_matched }}
**Motion Cooldown:** {{ 'Enabled' if enable_motion_cooldown else 'Disabled' }} ({{ motion_cooldown_time }})
**Device Cooldown:** {{ 'Enabled' if enable_device_cooldown else 'Disabled' }} ({{ device_cooldown_time }})
# Original action sequences - now using the variables set above
- choose:
- alias: Motion Sensor Trigger - Turn ON lights
conditions:
- condition: trigger
id: t0_motion_trigger
sequence:
- alias: Apply active profile light control to lights
choose:
- alias: Use brightness and colour temperature
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_colour_temperature' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
color_temp_kelvin: "{{ active_light_colour_temperature }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGB colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgb_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgb_color: "{{ active_light_rgb_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGBW colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgbw_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgbw_color: "{{ active_light_rgbw_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGBWW colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgbww_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgbww_color: "{{ active_light_rgbww_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness only
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'disable_colour_control' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use colour temperature only (no brightness)
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'use_colour_temperature' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
color_temp_kelvin: "{{ active_light_colour_temperature }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use RGB colour only (no brightness)
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'use_rgb_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
rgb_color: "{{ active_light_rgb_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use transition only (no brightness, no colour)
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'disable_colour_control' and 'use_transition' in active_include_light_control }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
transition: "{{ active_light_transition_on }}"
- alias: No light control - basic turn on
conditions:
- condition: template
value_template: "{{ true }}"
sequence:
- action: homeassistant.turn_on
entity_id: !input trigger_input
# Execute Profile Additional Actions if profile is selected
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 1 and condition_1_additional_actions|length > 0 }}"
sequence: !input condition_1_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 2 and condition_2_additional_actions|length > 0 }}"
sequence: !input condition_2_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 3 and condition_3_additional_actions|length > 0 }}"
sequence: !input condition_3_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 4 and condition_4_additional_actions|length > 0 }}"
sequence: !input condition_4_additional_actions
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Turn ON the timer helper
action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration: "{{ active_time_delay }}"
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait for the time that has been set in the time delay
delay: "{{ active_time_delay }}"
- alias: Turn OFF the entities
action: homeassistant.turn_off
target:
entity_id: !input trigger_input
- alias: Lights turned ON - Start timer (BUT NOT when lights were just turned on by motion)
conditions:
- condition: and
conditions:
- condition: trigger
id:
- t1
- t1a
# CRITICAL: Don't run this if we just turned lights on from motion trigger
- condition: template
value_template: '{{ trigger.id != "t1" or (trigger.id == "t1" and trigger.to_state.state == "on" and trigger.from_state.state == "off" and trigger.to_state.last_changed != trigger.from_state.last_changed) }}'
sequence:
- alias: Check if the synchronize option is enabled
choose:
- conditions:
- condition: template
value_template: '{{include_trigger_sync == ''enable_trigger_sync''}}'
sequence:
- alias: Turn ON the entities
action: homeassistant.turn_on
entity_id: !input trigger_input
- alias: Check if triggered by motion sensor or additional trigger
choose:
- conditions:
- condition: trigger
id:
- t0_motion_trigger
- t1a
sequence:
- alias: Apply active profile light control to lights
choose:
- alias: Use brightness and colour temperature
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_colour_temperature' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
color_temp_kelvin: "{{ active_light_colour_temperature }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGB colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgb_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgb_color: "{{ active_light_rgb_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGBW colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgbw_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgbw_color: "{{ active_light_rgbw_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGBWW colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgbww_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgbww_color: "{{ active_light_rgbww_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness only
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'disable_colour_control' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use colour temperature only
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'use_colour_temperature' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
color_temp_kelvin: "{{ active_light_colour_temperature }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use RGB colour only
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'use_rgb_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
rgb_color: "{{ active_light_rgb_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use transition only
conditions:
- condition: template
value_template: "{{ 'use_brightness' not in active_include_light_control and active_include_light_colour_control == 'disable_colour_control' and 'use_transition' in active_include_light_control }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
transition: "{{ active_light_transition_on }}"
- alias: No light control - basic turn on
conditions:
- condition: template
value_template: "{{ true }}"
sequence:
- action: homeassistant.turn_on
entity_id: !input trigger_input
# Execute Profile Additional Actions if profile is selected
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 1 and condition_1_additional_actions|length > 0 }}"
sequence: !input condition_1_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 2 and condition_2_additional_actions|length > 0 }}"
sequence: !input condition_2_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 3 and condition_3_additional_actions|length > 0 }}"
sequence: !input condition_3_additional_actions
- choose:
conditions:
- condition: template
value_template: "{{ selected_profile == 4 and condition_4_additional_actions|length > 0 }}"
sequence: !input condition_4_additional_actions
- alias: Check if the time helper is enabled
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Turn ON the timer helper
action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration: "{{ active_time_delay }}"
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait for the time that has been set in the time delay
delay: "{{ active_time_delay }}"
- alias: Turn OFF the entities
action: homeassistant.turn_off
target:
entity_id: !input trigger_input
- alias: Lights turned OFF - Check if synchronize is enabled
conditions:
- condition: trigger
id: t2
sequence:
- choose:
- alias: Check if synchronize is enabled
conditions:
- condition: template
value_template: '{{include_trigger_sync == ''enable_trigger_sync''}}'
sequence:
- alias: Turn OFF the entities
action: homeassistant.turn_off
entity_id: !input trigger_input
- alias: Timer finished - Turn OFF lights
conditions:
- condition: trigger
id: t3
sequence:
- alias: Turn OFF entities with transition if configured
choose:
- alias: Use transition on turn off
conditions:
- condition: template
value_template: "{{ 'use_transition' in active_include_light_control }}"
sequence:
- action: light.turn_off
target:
entity_id: !input trigger_input
data:
transition: "{{ active_light_transition_off }}"
- alias: No transition - basic turn off
conditions:
- condition: template
value_template: "{{ true }}"
sequence:
- action: homeassistant.turn_off
entity_id: !input trigger_input
- alias: Motion detected - Turn on lights if off, reset timer (t0 fallback + time delay)
conditions:
- condition: trigger
id: t4_motion_delay
sequence:
- alias: Turn on lights if they are currently off (acting as t0 fallback)
if:
- condition: template
value_template: '{{ expand(trigger_input) | selectattr(''state'', ''=='', ''off'') | list | count > 0 }}'
then:
- alias: Apply active profile light control to lights
choose:
- alias: Use brightness and colour temperature
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_colour_temperature' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
color_temp_kelvin: "{{ active_light_colour_temperature }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness and RGB colour
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control and active_include_light_colour_control == 'use_rgb_colour' }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
rgb_color: "{{ active_light_rgb_colour }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: Use brightness only
conditions:
- condition: template
value_template: "{{ 'use_brightness' in active_include_light_control }}"
sequence:
- action: light.turn_on
target:
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
transition: "{{ active_light_transition_on if 'use_transition' in active_include_light_control else 0 }}"
- alias: No light control - basic turn on
conditions:
- condition: template
value_template: "{{ true }}"
sequence:
- action: homeassistant.turn_on
entity_id: !input trigger_input
- alias: Check if the time helper is enabled
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Reset the timer helper
action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration: "{{ active_time_delay }}"
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait for the time that has been set in the time delay
delay: "{{ active_time_delay }}"
- alias: Turn OFF the entities
action: homeassistant.turn_off
target:
entity_id: !input trigger_input
- alias: By-pass is turned on & check by-pass option - Turn lights on
conditions:
- condition: trigger
id: t5_on
sequence:
- alias: Cancel any running timer so bypass fully takes control
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ timer_helper }}"
- alias: Cancel grace period timer if active
choose:
- conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: template
value_template: '{{ is_state(grace_period_timer_helper, ''active'') }}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ grace_period_timer_helper }}"
- alias: Turn ON the controlled entities
action: homeassistant.turn_on
entity_id: !input trigger_input
- alias: Handle bypass auto off if enabled
if:
- condition: template
value_template: '{{ ''bypass_auto_off_enabled_on'' in include_bypass_auto_off }}'
then:
- choose:
- alias: Wait using timer helper
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration:
minutes: !input bypass_auto_off_delay
- wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: "{{ timer_helper }}"
- alias: Wait using delay
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- delay:
minutes: !input bypass_auto_off_delay
- alias: Turn off the bypass entity
action: homeassistant.turn_off
entity_id: !input bypass_lights_on
else:
- stop: Stop the automation
- alias: bypass is turned on & check bypass option - Turn lights off
conditions:
- condition: trigger
id: t5_off
sequence:
- alias: Cancel any running timers immediately
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ timer_helper }}"
- choose:
- alias: If grace period is active, cancel it
conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: template
value_template: '{{ is_state(grace_period_timer_helper, ''active'') }}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ grace_period_timer_helper }}"
- alias: Apply bypass time delay then turn lights off
choose:
- conditions:
- condition: template
value_template: '{{ bypass_time_delay | float > 0 }}'
sequence:
- delay:
minutes: !input bypass_time_delay
- alias: Turn OFF the controlled entities
action: homeassistant.turn_off
entity_id: !input trigger_input
- alias: Handle bypass auto off if enabled
if:
- condition: template
value_template: '{{ ''bypass_auto_off_enabled_off'' in include_bypass_auto_off }}'
then:
- choose:
- alias: Wait using timer helper
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration:
minutes: !input bypass_auto_off_delay
- wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: "{{ timer_helper }}"
- alias: Wait using delay
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- delay:
minutes: !input bypass_auto_off_delay
- alias: Turn off the bypass entity
action: homeassistant.turn_off
entity_id: !input bypass_lights_off
else:
- stop: Stop the automation
- alias: bypass is turned on & check bypass option - Keep the current lights state
conditions:
- condition: trigger
id: t5_stop
sequence:
- alias: Cancel any running timer to freeze the current light state
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ timer_helper }}"
- alias: Cancel grace period timer if active
choose:
- conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: template
value_template: '{{ is_state(grace_period_timer_helper, ''active'') }}'
sequence:
- action: timer.cancel
target:
entity_id: "{{ grace_period_timer_helper }}"
- alias: Handle bypass auto off if enabled
if:
- condition: template
value_template: '{{ ''bypass_auto_off_enabled_stop'' in include_bypass_auto_off }}'
then:
- choose:
- alias: Wait using timer helper
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration:
minutes: !input bypass_auto_off_delay
- wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: "{{ timer_helper }}"
- alias: Wait using delay
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- delay:
minutes: !input bypass_auto_off_delay
- alias: Turn off the bypass entity
action: homeassistant.turn_off
entity_id: !input bypass_lights_stop
else:
- stop: Stop the automation
- alias: bypass is turned OFF - Restart automation
conditions:
- condition: trigger
id:
- t6_on
- t6_off
- t6_stop
sequence:
- choose:
- alias: Check if any lights are on
conditions:
- condition: state
entity_id: !input trigger_input
match: any
state: 'on'
sequence:
- alias: Check if the time helper is enabled
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Turn ON the timer helper
action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration: "{{ active_time_delay }}"
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait for the time that has been set in the time delay
delay: "{{ active_time_delay }}"
- alias: Turn OFF the entities
action: homeassistant.turn_off
target:
entity_id: '{{ trigger_entities_on }}'
- alias: Home Assistant Start - Check if any lights are ON
conditions:
- condition: trigger
id: t7
sequence:
- choose:
- alias: Check if any lights are on
conditions:
- condition: state
entity_id: !input trigger_input
match: any
state: 'on'
sequence:
- alias: Check if the time helper is enabled
choose:
- conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Turn ON the timer helper
action: timer.start
target:
entity_id: "{{ timer_helper }}"
data:
duration: "{{ active_time_delay }}"
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait for the time that has been set in the time delay
delay: "{{ active_time_delay }}"
- alias: Turn OFF the entities
action: homeassistant.turn_off
target:
entity_id: '{{ trigger_entities_on }}'
# ENHANCED: COOLDOWN IMPLEMENTATION - APPLIED AT END
- variables:
trigger_id: "{{ trigger.id }}"
# Motion cooldown - applies after motion triggers
- if:
condition: and
conditions:
- condition: template
value_template: "{{ enable_motion_cooldown }}"
- condition: template
value_template: "{{ trigger_id in ['t0_motion_trigger', 't4_motion_delay'] }}"
then:
- delay: "{{ motion_cooldown_time }}"
- alias: Debug - Motion cooldown applied
if:
condition: template
value_template: "{{ enable_debug }}"
then:
- action: persistent_notification.create
data:
notification_id: "{{ state_attr(this.entity_id, 'friendly_name') }}_cooldown"
title: "{{ state_attr(this.entity_id, 'friendly_name') }} Cooldown"
message: |
**Motion Cooldown Applied**
**Duration:** {{ motion_cooldown_time }}
**Trigger:** {{ trigger_id }}
**Time:** {{ now() }}
# Device cooldown - applies after device triggers
- if:
condition: and
conditions:
- condition: template
value_template: "{{ enable_device_cooldown }}"
- condition: template
value_template: "{{ trigger_id in ['t1', 't1a', 't2', 't5_on', 't5_off', 't5_stop', 't6_on', 't6_off', 't6_stop'] }}"
then:
- delay: "{{ device_cooldown_time }}"
- alias: Debug - Device cooldown applied
if:
condition: template
value_template: "{{ enable_debug }}"
then:
- action: persistent_notification.create
data:
notification_id: "{{ state_attr(this.entity_id, 'friendly_name') }}_cooldown"
title: "{{ state_attr(this.entity_id, 'friendly_name') }} Cooldown"
message: |
**Device Cooldown Applied**
**Duration:** {{ device_cooldown_time }}
**Trigger:** {{ trigger_id }}
**Time:** {{ now() }}

Comments are disabled for this gist.