Skip to content

Instantly share code, notes, and snippets.

@Ltek
Last active January 25, 2026 00:23
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**
🚀 Version 2026.01.24.22d
Author: LTek
- NEW: Added Trigger Restrictions to each Profile to control which triggers can activate each profile
- FIXED: Profile's Additional Conditions, they were not working before.
**FEATURES**
🎯 4 Profiles with Trigger Restrictions - control which triggers activate each profile
🔅 Motion Grace Period that turns the light back on once with motion
⏱️ Configurable timeouts and schedules
️‍💥 Condition Selector to Profiles, allows for any condition, simple to complex.
‍🚧 Bypass system for temporary automation override for keep on, keep off, keep same
⌛ Timer Entity to survive system restarts (optional)
🧊 Configurable Cooldown timer (prevents rapid retriggering)
💫 Synchronize Trigger Entities (optional).... **only for Controlled Triggers** entities will all be sync/controlled based. So if you want any trigger to turn on all lights in the selection box, enable sync. If you want independent control, disable sync. Note: Motion triggers ALWAYS turn on all Controlled Triggers.
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.
Three Entity Categories...
- Controlled Triggers: Lights/switches that both trigger the automation AND are controlled by it
- Motion Triggers: Sensors that only trigger the automation (always turn on ALL controlled lights)
- Additional Triggers: Other entities that trigger but aren't controlled (locks, covers, etc.)
Intelligent Conflict Prevention and built-in safeguards...
- Debounce timing: 2-second delays prevent trigger loops
- Entity validation: Prevents using the same entity as both trigger and bypass
- State tracking: Keeps track of which entities are on/off
- Graceful handoff: Manual overrides don't interfere with scheduled turn-of
Up to 4 Profiles with Trigger Restrictions allowing enormous flexability to control entities (Lights, Switches, etc) using almost any combination of conditions to be mixed; entity state, motion, day/time, etc... but all in a very easy to understand and use interface.
NEW FEATURE - TRIGGER RESTRICTIONS:
Each profile can now specify which triggers it responds to. For example:
- Create a "Daytime" profile that only responds to manual switches (not motion)
- Create a "Night" profile that responds to motion and manual switches
- Create a "Guest" profile that only responds to bypass controls
- Create a "Vacation" profile that ignores all triggers
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.
NOTE >> the blueprint prevents using the same entity in both as a Trigger and as a Bypass; to avoid conflicts.
📖 Community Discussion, Help, and Details... https://community.home-assistant.io/
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_brightness:
name: Light Brightness (Motion/Additional Triggers only)
description: 'Set the brightness level (0-100%) when triggered by Motion Sensor or Additional Triggers. Only applicable for light entities.'
default: 100
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
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: {}
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_brightness:
name: Light Brightness (Motion/Additional Triggers only)
description: 'Set the brightness level (0-100%) when triggered by Motion Sensor or Additional Triggers. Only applicable for light entities.'
default: 100
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
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: {}
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_brightness:
name: Light Brightness (Motion/Additional Triggers only)
description: 'Set the brightness level (0-100%) when triggered by Motion Sensor or Additional Triggers. Only applicable for light entities.'
default: 100
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
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: {}
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_brightness:
name: Light Brightness (Motion/Additional Triggers only)
description: 'Set the brightness level (0-100%) when triggered by Motion Sensor or Additional Triggers. Only applicable for light entities.'
default: 100
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
mode: slider
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: {}
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
# MOVED: Advanced Timing Settings moved here (under Motion section)
advanced_timers:
name: Advanced Timing Controls
icon: mdi:timer-plus-outline
collapsed: true
input:
# MOVED: Timer Helper settings moved here
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
# Cooldown settings
enable_cooldown:
name: Enable Cooldown Timer
description: 'Prevents the automation from being retriggered too quickly after activation. Useful for avoiding multiple rapid triggers from the same source.'
default: false
selector:
boolean: {}
cooldown_time:
name: Cooldown Duration
description: 'How long to wait after the automation is triggered before allowing another trigger. Only applies when Cooldown is enabled.'
default:
days: 0
hours: 0
minutes: 0
seconds: 30
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: restart
max_exceeded: silent
variables:
# Cooldown variables - NOTE: Now moved to advanced_timers section
enable_cooldown: !input enable_cooldown
cooldown_time: !input cooldown_time
# Timer Helper variables - NOTE: Now moved to advanced_timers section
include_timer_helper: !input include_timer_helper
timer_helper: !input timer_helper
# 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
# 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_brightness: !input condition_1_brightness
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_brightness: !input condition_2_brightness
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_brightness: !input condition_3_brightness
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_brightness: !input condition_4_brightness
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 - hardcoded values since Default Settings section is removed
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 }}"
# Triggers remain the same as in your original blueprint
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 # 1 second debounce
# 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 # 2 second debounce for device triggers
- 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
enabled: "{{ include_trigger_sync == 'enable_trigger_sync' }}"
- trigger: state
entity_id: !input timer_helper
to: idle
id: t3
# Motion delay trigger - resets timer when motion is detected while lights are ON
- trigger: state
id: t4_motion_delay
entity_id: !input motion_trigger
from: 'off'
to: 'on'
for:
hours: 0
minutes: 0
seconds: 0
# Bypass triggers also need 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:
# Original conditions from your blueprint (keep these exactly as they were)
- 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: state
entity_id: !input grace_period_timer_helper
state: 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: state
entity_id: !input trigger_input
match: all
state: 'off'
- 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: Check if grace period is enabled
condition: or
conditions:
- 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: state
entity_id: !input grace_period_timer_helper
state: 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:
- t5_on
- t5_off
- t5_stop
- t6_on
- t6_off
- t6_stop
- t7
action:
# Debug notifications
- choose:
- conditions: "{{ enable_debug }}"
sequence:
- alias: Send Debug Notification
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 }}
**Current Profile:** {{ current_profile }}
# --------------------------------------------------------
# PROFILE EVALUATION - PROFESSIONAL SOLUTION
# --------------------------------------------------------
# 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_brightness }}"
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_brightness }}"
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_brightness }}"
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_brightness }}"
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 }}"
# 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 }}%
# 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 brightness to lights
action: homeassistant.turn_on
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
- 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
entity_id: !input 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: Lights turned ON - Start timer
conditions:
- condition: trigger
id:
- t1
- t1a
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: Turn ON the entities with brightness
action: homeassistant.turn_on
entity_id: !input trigger_input
data:
brightness_pct: "{{ active_brightness }}"
- 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
entity_id: !input 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: 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 the entities
action: homeassistant.turn_off
entity_id: !input trigger_input
- alias: Motion detected - Reset timer
conditions:
- condition: trigger
id: t4_motion_delay
sequence:
- 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
entity_id: !input 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: By-pass is turned on & check by-pass option - Turn lights on
conditions:
- condition: trigger
id: t5_on
sequence:
- choose:
- alias: If grace period is selected
conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: state
entity_id: !input grace_period_timer_helper
state: active
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input grace_period_timer_helper
- alias: Turn ON the entities
action: homeassistant.turn_on
entity_id: !input trigger_input
- alias: Check by-pass settings and preform the correct action
if:
- condition: or
conditions:
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_on'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_on
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_off'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_off
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_stop'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_stop
match: any
state: 'on'
then:
- 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
entity_id: !input timer_helper
data:
duration:
minutes: !input bypass_auto_off_delay
- alias: Wait the number of minutes set in the bypass auto off time delay
wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: !input timer_helper
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait the number of minutes set in the bypass auto off time delay
delay:
minutes: !input bypass_auto_off_delay
- alias: Parallel Actions for the bypass auto off
parallel:
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_on
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_off
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_stop'' in include_bypass) and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_stop
- stop: Stop the automation
else:
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input timer_helper
- stop: Stop the automation
- alias: bypass is turned on & check bypass option - Turn lights off
conditions:
- condition: trigger
id: t5_off
sequence:
- choose:
- alias: If grace period is selected
conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: state
entity_id: !input grace_period_timer_helper
state: active
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input grace_period_timer_helper
- choose:
- alias: Check if any lights are on
conditions:
- condition: state
entity_id: !input trigger_input
match: any
state: 'on'
sequence:
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Handle timer helper when set to 0
choose:
- conditions: '{{ bypass_time_delay | float == 0 }}'
sequence:
- alias: Cancel the timer if set to 0
action: timer.cancel
entity_id: !input timer_helper
default:
- alias: Start the timer with set minutes
action: timer.start
entity_id: !input timer_helper
data:
duration:
minutes: !input bypass_time_delay
- alias: Wait the number of minutes set in the bypass time delay
wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: !input timer_helper
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait the number of minutes set in the bypass time delay
delay:
minutes: !input bypass_time_delay
- alias: Turn OFF the entities
action: homeassistant.turn_off
entity_id: !input trigger_input
- alias: Check bypass settings and preform the correct action
if:
- condition: or
conditions:
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_on'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_on
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_off'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_off
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_stop'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_stop
match: any
state: 'on'
then:
- 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
entity_id: !input timer_helper
data:
duration:
minutes: !input bypass_auto_off_delay
- alias: Wait the number of minutes set in the bypass auto off time delay
wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: !input timer_helper
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait the number of minutes set in the bypass auto off time delay
delay:
minutes: !input bypass_auto_off_delay
- alias: Parallel Actions for the bypass auto off
parallel:
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_on
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_off
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_stop'' in include_bypass) and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_stop
- stop: Stop the automation
else:
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input timer_helper
- stop: Stop the automation
- alias: bypass is turned on & check bypass option - Keep the current lights state
conditions:
- condition: trigger
id: t5_stop
sequence:
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- choose:
- alias: If grace period is selected
conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: state
entity_id: !input grace_period_timer_helper
state: active
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input grace_period_timer_helper
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- choose:
- alias: If grace period is selected
conditions:
- condition: template
value_template: '{{include_grace_period == ''enable_grace_period''}}'
- condition: template
value_template: '{{include_motion_trigger == ''enable_motion_trigger''}}'
- condition: state
entity_id: !input grace_period_timer_helper
state: active
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input grace_period_timer_helper
- alias: Check bypass settings and preform the correct action
if:
- condition: or
conditions:
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_on'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_on
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_off'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_off
match: any
state: 'on'
- condition: and
conditions:
- alias: Check if the bypass auto off is enabled
condition: template
value_template: '{{ ''bypass_auto_off_enabled_stop'' in include_bypass_auto_off }}'
- condition: state
entity_id: !input bypass_lights_stop
match: any
state: 'on'
then:
- 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
entity_id: !input timer_helper
data:
duration:
minutes: !input bypass_auto_off_delay
- alias: Wait the number of minutes set in the bypass auto off time delay
wait_for_trigger:
- trigger: event
event_type: timer.finished
event_data:
entity_id: !input timer_helper
- alias: Check if the time helper is disabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''disable_timer_helper''}}'
sequence:
- alias: Wait the number of minutes set in the bypass auto off time delay
delay:
minutes: !input bypass_auto_off_delay
- alias: Parallel Actions for the bypass auto off
parallel:
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_on'' in include_bypass) and (''bypass_auto_off_enabled_on'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_on
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_turn_off'' in include_bypass) and (''bypass_auto_off_enabled_off'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_off
- sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ (''bypass_enabled_stop'' in include_bypass) and (''bypass_auto_off_enabled_stop'' in include_bypass_auto_off) }}'
sequence:
- alias: Turn off the bypass
action: homeassistant.turn_off
entity_id: !input bypass_lights_stop
- stop: Stop the automation
else:
- choose:
- alias: Check if the time helper is enabled
conditions:
- condition: template
value_template: '{{include_timer_helper == ''enable_timer_helper''}}'
sequence:
- alias: Cancel the timer helper
action: timer.cancel
entity_id: !input timer_helper
- 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
entity_id: !input 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
entity_id: !input 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 }}'
# Cooldown delay - prevents rapid retriggering - FIXED: Correct structure
- alias: Apply cooldown delay
choose:
- conditions:
- condition: template
value_template: '{{ enable_cooldown and trigger.id in ["t0_motion_trigger", "t1", "t1a", "t2", "t4_motion_delay"] }}'
sequence:
- delay: "{{ cooldown_time }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment