Skip to content

Instantly share code, notes, and snippets.

@Blackshome
Last active October 8, 2024 09:28
Show Gist options
  • Save Blackshome/5aac0fe94d23a71154aee5ba8d1375bc to your computer and use it in GitHub Desktop.
Save Blackshome/5aac0fe94d23a71154aee5ba8d1375bc to your computer and use it in GitHub Desktop.
closet-pantry-cupboard-lighting.yaml
blueprint:
name: Closet, Pantry, and Cupboard Lighting
description: >
# 🚪 Closet, Pantry, and Cupboard Lighting
**Version: 1.3**
'Open Sesame'🪄 Lighting Magic! 💡🚪
**If you like my blueprints, and would like to show your support or just say thank you?** [Click Here](https://www.paypal.com/donate/?hosted_button_id=WAZS3QSDTPGA8) 🙂
<details>
<summary><b>The Automation Process:</b> 👈</summary>
- **Trigger:**
- The trigger sensor is specifically designed to integrate seamlessly with a door contact sensor but you can choose any [binary sensors](https://www.home-assistant.io/integrations/binary_sensor/) to trigger the automation.
- When activated, a trigger sensor such as a door contact sensor will turn ON the lights and switches.
- **Light - Switches:**
- Enter any lights or switches that will be activated by the trigger sensor/s.
- **Light Control Options:**
- Utilize "Light Control" to adjust brightness, colour temperature, colour, and transition times.
- **Night Lights Mode:**
- Enable 'Night Lights' for softer illumination during night time activities, automatically enabled based on conditions.
- **Timer Option:**
- You have the option to use a timer, which determines how long the lights remain ON after the trigger sensor is activated. It will then automatically turn OFF the 'Lights - Switches' when the timer expires.
- **Motion Sensor Option:**
- You have the option to use a motion sensor that will reset the timer. If the timer has turned OFF the lights and the trigger remains active, the motion sensor will turn the lights back ON when detecting motion.
- **HA Restart Safeguards:**
- Benefit from built-in safeguards for Home Assistant restarts.
- **Blueprint Integration:**
- 💡Sensor Light - Motion activated lighting. [Click Here](https://community.home-assistant.io/t/481048) to learn more.
</details>
Need help?
- FAQ: [Click Here](https://community.home-assistant.io/t/697688/2?u=blacky)
- Community Support Including Updates: [Click Here](https://community.home-assistant.io/t/697688?u=blacky)
Required = *
domain: automation
input:
triggers:
name: "Triggers *"
icon: mdi:cog-outline
collapsed: true
input:
trigger_entity:
name: Trigger Sensor - Binary Sensors*
description: The trigger sensor is specifically designed to integrate seamlessly with a **contact sensor** and will be responsible for turning ON the lights and switches.
When using multiple trigger sensors, it's advisable to group them together using a group helper.
This ensures smoother automation execution and prevents conflicts.
For more information on grouping your trigger sensors [Click Here](https://community.home-assistant.io/t/697688/3?u=blacky)
default: []
selector:
entity:
filter:
domain:
- binary_sensor
multiple: true
include_timer:
name: Use The Timer Option (Optional)
description: Choose whether to activate the timer.
The timer determines how long the lights will remain ON when the trigger sensor is activated.
Once the timer expires, the lights will automatically turn OFF.
default: disable_timer
selector:
select:
options:
- label: Enable timer
value: "enable_timer"
- label: Disable timer
value: "disable_timer"
timer:
name: Timer
description: Enter the desired duration for the timer.
default: 00:00:00
selector:
duration:
include_motion_trigger:
name: Use The Motion Sensor Option (Optional)
description: Use this option only when the timer is enabled to utilize the motion sensor.
The motion sensor pauses the timer when motion is detected and automatically resets it once motion is cleared.
Additionally, if the timer has turned OFF the lights and the trigger remains active, the motion sensor will turn the lights back ON upon detecting motion.
default: disable_motion_trigger
selector:
select:
options:
- label: Enable the motion sensor option
value: "enable_motion_trigger"
- label: Disable the motion sensor option
value: "disable_motion_trigger"
motion_trigger:
name: Motion Sensor - Binary Sensors
description: Select a motion sensor or any binary sensors you would like to use.
If you plan to use multiple sensors, it is recommended to group them together using a group helper.
This ensures smoother automation execution and helps prevent conflicts.
For more information on grouping your motion sensors [Click Here](https://community.home-assistant.io/t/697688/3?u=blacky)
default: []
selector:
entity:
filter:
domain:
- binary_sensor
lights:
name: "Lights *"
icon: mdi:lightbulb-outline
collapsed: true
input:
light_switch:
name: Lights - Switches *
description: The lights and switches that will be activated by the trigger sensor.
**NOTE** - You can only use entities. Areas, devices and labels are not supported.
default: []
selector:
target:
entity:
domain:
- light
- switch
- scene
- script
lights_settings:
name: "Light Control"
icon: mdi:lightbulb-on-outline
collapsed: true
input:
include_light_control:
name: Use The Light Control Options (Optional)
description: Select if you would like to use brightness or transition.
These settings will only affect a 'light' entity that supports each selected option.
The settings for brightness and transition are provided below.
default: []
selector:
select:
multiple: true
options:
- label: Use Brightness
value: "use_brightness"
- label: Use Transition
value: "use_transition"
light_brightness:
name: Brightness
description: The brightness setting for the lights when they are turned ON.
default: 100
selector:
number:
min: 1
max: 100
mode: slider
step: 1
unit_of_measurement: '%'
light_transition_on:
name: Transition - ON
description: The transition setting for the lights when they are turned ON.
default: 1
selector:
number:
min: 0
max: 5
mode: slider
step: 0.5
unit_of_measurement: seconds
light_transition_off:
name: Transition - OFF
description: The transition setting for the lights when they are turned OFF.
default: 1
selector:
number:
min: 0
max: 30
mode: slider
step: 1
unit_of_measurement: seconds
include_light_colour_control:
name: Use The Light Colour Control Options (Optional)
description: Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour.
These settings will only affect a 'light' entity that supports each selected option.
The settings for colour temperature, RGB, RGBW and RGBWW colour are provided below.
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"
light_colour_temperature:
name: Colour Temperature
description: The colour temperature setting for the lights when they are turned ON.
default: 5000
selector:
number:
min: 2000
max: 8000
mode: slider
step: 100
unit_of_measurement: 'kelvin'
light_rgb_colour:
name: RGB Colour
description: The RGB colour setting for the lights when they are turned ON.
default: [255, 255, 255]
selector:
color_rgb:
light_rgbw_colour:
name: RGBW Colour
description: The RGBW colour setting for the lights when they are turned ON.
Enter four integers between 0 and 255 to define the values for Red, Green, Blue, and White.
default: [255, 255, 255, 255]
selector:
object:
light_rgbww_colour:
name: RGBWW Colour
description: The RGBWW colour setting for the lights when they are turned ON.
Enter five integers between 0 and 255 to define the values for Red, Green, Blue, Cold White and Warm White.
default: [255, 255, 255, 255, 255]
selector:
object:
night_lights_trigger_settings:
name: "Night Lights Settings"
icon: mdi:weather-night
collapsed: true
input:
include_night_lights:
name: Use The Night Lights Options (Optional)
description: Enabling the night lights option allows for separate and customizable lighting control when night light conditions are met.
Night light condition options include entity state, time, or sun elevation.
Please choose the condition option you would like to use below.
This feature is particularly beneficial for creating a soothing ambiance with softer lighting at night.
The flexibility of these options allows for personalized adjustments, enhancing your nighttime ambiance and comfort, especially when moving around during the night.
default: night_lights_disabled
selector:
select:
options:
- label: Enable the night lights options
value: "night_lights_enabled"
- label: Disable the night lights options
value: "night_lights_disabled"
night_lights_conditions:
name: Night Lights Conditions (Required For Night Lights)
description: Select any night light condition from the options provided.
Ensure you've enabled **Use the night lights options** in the section above and choose at least one **Night Lights Condition** for night lights to operate.
Settings for each option are provided below.
default: []
selector:
select:
multiple: true
options:
- label: Enable entity state option
value: "entity_state_enabled"
- label: Enable time option
value: "time_enabled"
- label: Enable sun elevation option
value: "sun_enabled"
night_lights_entity_state:
name: Night Lights - Entity State
description: Select an entity that will trigger the activation of night lights when turned ON.
This could be your phone on **Do Not Disturb**, a helper, a bed sensor, etc.
Please note that the selected entity cannot be included in the **Lights - Switches** or **Night Lights** selections.
default: []
selector:
entity:
multiple: true
night_lights_after_time:
name: Night Lights - Start Time
description: Set the start time.
default: 00:00:00
selector:
time:
night_lights_before_time:
name: Night Lights - End Time
description: Set the end time.
default: 00:00:00
selector:
time:
night_lights_sun_elevation:
name: Night Lights - Sun Elevation Falling
description: The sun elevation falling refers to the angle between the sun and the horizon when the sun is setting.
A negative value indicates that the sun is BELOW the horizon. For example, a setting guide of -1.5 corresponds to dusk.
default: -1.5
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
night_lights_sun_elevation_rising:
name: Night Lights - Sun Elevation Rising
description: The sun elevation rising refers to the angle between the sun and the horizon during sunrise.
A negative value indicates that the sun is BELOW the horizon. For example, a setting guide of -4.0 corresponds to dawn.
default: -4.0
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
night_include_timer:
name: Use The Night Timer Option (Optional)
description: Choose whether to activate the timer.
It determines the duration for which the night lights can remain ON when the trigger sensor is activated. It will then automatically turn OFF the 'Night Lights' when the timer expires.
default: disable_night_timer
selector:
select:
options:
- label: Enable timer
value: "enable_night_timer"
- label: Disable timer
value: "disable_night_timer"
night_timer:
name: Night Lights - Night Timer
description: Enter the desired duration for the timer.
default: 00:00:00
selector:
duration:
night_lights_settings:
name: "Night Lights"
icon: mdi:lightbulb-night-outline
collapsed: true
input:
night_lights:
name: Night Lights
description: The night lights and switches that will be activated by the trigger sensor.
**NOTE** - You can only use entities. Areas, devices and labels are not supported.
default: {}
selector:
target:
entity:
domain:
- light
- switch
- scene
- script
night_lights_light_control_settings:
name: "Night Light Control"
icon: mdi:lightbulb-on-80
collapsed: true
input:
include_night_light_control:
name: Night Lights - Use The Light Control Options (Optional)
description: Select if you would like to use brightness or transition.
These settings will only affect a 'light' entity that supports each selected option.
The settings for brightness and transition are provided below.
Selecting **If lights are ON, adjust the lights when crossing over** option ensures that the light control settings will be applied to any lights that are already ON during the transition from normal lights to night lights and vice versa.
default: []
selector:
select:
multiple: true
options:
- label: Use brightness
value: "use_brightness"
- label: Use transition
value: "use_transition"
- label: If lights are ON, adjust the lights when crossing over
value: "if_lights_are_on_adjust_when_crossing_over"
night_light_brightness:
name: Night Lights - Brightness
description: The brightness setting of the night lights when they are turned ON.
default: 20
selector:
number:
min: 1
max: 100
mode: slider
step: 1
unit_of_measurement: '%'
night_light_transition_on:
name: Night Lights - Transition - ON
description: The transition of the night lights when they are turned ON.
default: 1
selector:
number:
min: 0
max: 5
mode: slider
step: 0.5
unit_of_measurement: seconds
night_light_transition_off:
name: Night Lights - Transition - OFF
description: The transition of the night lights when they are turned OFF.
default: 1
selector:
number:
min: 0
max: 30
mode: slider
step: 1
unit_of_measurement: seconds
include_night_light_colour_control:
name: Use The Night Light Colour Control Options (Optional)
description: Select if you would like to use colour temperature, RGB, RGBW or RGBWW colour.
These settings will only affect a 'light' entity that supports each selected option.
The settings for colour temperature, RGB, RGBW and RGBWW colour are provided below
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"
night_light_colour_temperature:
name: Night Lights - Colour Temperature
description: The colour temperature setting for the night lights when they are turned ON.
default: 5000
selector:
number:
min: 2000
max: 8000
mode: slider
step: 100
unit_of_measurement: 'kelvin'
night_light_rgb_colour:
name: Night Lights - RGB Colour
description: The RGB colour setting for the lights when they are turned ON.
default: [255, 255, 255]
selector:
color_rgb:
night_light_rgbw_colour:
name: Night Lights - RGBW Colour
description: The RGBW colour setting for the lights when they are turned ON.
Enter four integers between 0 and 255 to define the values for Red, Green, Blue, and White.
default: [255, 255, 255, 255]
selector:
object:
night_light_rgbww_colour:
name: Night Lights - RGBWW Colour
description: The RGBWW colour setting for the lights when they are turned ON.
Enter five integers between 0 and 255 to define the values for Red, Green, Blue, Cold White and Warm White.
default: [255, 255, 255, 255, 255]
selector:
object:
mode: restart
max_exceeded: silent
variables:
trigger_entity: !input trigger_entity
include_timer: !input include_timer
timer: !input timer
include_motion_trigger: !input include_motion_trigger
motion_trigger: !input motion_trigger
light_switch: !input light_switch
include_light_control: !input include_light_control
light_brightness: !input light_brightness
light_transition_on: !input light_transition_on
light_transition_off: !input light_transition_off
include_light_colour_control: !input include_light_colour_control
light_colour_temperature: !input light_colour_temperature
light_rgb_colour: !input light_rgb_colour
light_rgbw_colour: !input light_rgbw_colour
light_rgbww_colour: !input light_rgbww_colour
include_night_lights: !input include_night_lights
night_lights_conditions: !input night_lights_conditions
night_lights_entity_state: !input night_lights_entity_state
night_lights_after_time: !input night_lights_after_time
night_lights_before_time: !input night_lights_before_time
night_lights_sun_elevation: !input night_lights_sun_elevation
night_lights_sun_elevation_rising: !input night_lights_sun_elevation_rising
night_include_timer: !input night_include_timer
night_timer: !input night_timer
night_lights: !input night_lights
include_night_light_control: !input include_night_light_control
night_light_brightness: !input night_light_brightness
night_light_transition_on: !input night_light_transition_on
night_light_transition_off: !input night_light_transition_off
include_night_light_colour_control: !input include_night_light_colour_control
night_light_colour_temperature: !input night_light_colour_temperature
night_light_rgb_colour: !input night_light_rgb_colour
night_light_rgbw_colour: !input night_light_rgbw_colour
night_light_rgbww_colour: !input night_light_rgbww_colour
# Split domains for light switch targets and check the entities are OFF
light_entities_off: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}"
switch_entities_off: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}"
# Split domains for light switch targets
light_entities: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}"
switch_entities: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }}"
# For light control - Light data
light_data: >-
{% set light = namespace(data={}) %}
{% if 'use_transition' in include_light_control %}
{% set light.data = dict(light.data, **{ 'transition': light_transition_on }) %}
{% endif %}
{% if 'use_brightness' in include_light_control %}
{% set light.data = dict(light.data, **{ 'brightness_pct': light_brightness }) %}
{% endif %}
{% if include_light_colour_control == 'use_colour_temperature' %}
{% set light.data = dict(light.data, **{ 'color_temp_kelvin': light_colour_temperature }) %}
{% endif %}
{% if include_light_colour_control == 'use_rgb_colour' %}
{% set light.data = dict(light.data, **{ 'rgb_color': light_rgb_colour }) %}
{% endif %}
{% if include_light_colour_control == 'use_rgbw_colour' %}
{% set light.data = dict(light.data, **{ 'rgbw_color': light_rgbw_colour }) %}
{% endif %}
{% if include_light_colour_control == 'use_rgbww_colour' %}
{% set light.data = dict(light.data, **{ 'rgbww_color': light_rgbww_colour }) %}
{% endif %}
{{ light.data }}
# Split domains for night light targets and check the entities are OFF
night_light_entities_off: >-
{% set b = night_lights and night_lights.entity_id %}
{% if b %}
{{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
night_switch_entities_off: >-
{% set b = night_lights and night_lights.entity_id %}
{% if b %}
{{ expand(b) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
# Split domains for night light switch targets
night_light_entities: >-
{% set b = night_lights and night_lights.entity_id %}
{% if b %}
{{ expand(b) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
night_switch_entities: >-
{% set b = night_lights and night_lights.entity_id %}
{% if b %}
{{ expand(b) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
# For night light control - Light data
night_light_data: >-
{% set light = namespace(data={}) %}
{% if 'use_transition' in include_night_light_control %}
{% set light.data = dict(light.data, **{ 'transition': night_light_transition_on }) %}
{% endif %}
{% if 'use_brightness' in include_night_light_control %}
{% set light.data = dict(light.data, **{ 'brightness_pct': night_light_brightness }) %}
{% endif %}
{% if include_night_light_colour_control == 'use_colour_temperature' %}
{% set light.data = dict(light.data, **{ 'color_temp_kelvin': night_light_colour_temperature }) %}
{% endif %}
{% if include_night_light_colour_control == 'use_rgb_colour' %}
{% set light.data = dict(light.data, **{ 'rgb_color': night_light_rgb_colour }) %}
{% endif %}
{% if include_night_light_colour_control == 'use_rgbw_colour' %}
{% set light.data = dict(light.data, **{ 'rgbw_color': night_light_rgbw_colour }) %}
{% endif %}
{% if include_night_light_colour_control == 'use_rgbww_colour' %}
{% set light.data = dict(light.data, **{ 'rgbww_color': night_light_rgbww_colour }) %}
{% endif %}
{{ light.data }}
# Set up crossover lights for T5, T6 & t7 trigger. This is to stop the light flicker
crossover_lights_light: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(a) | reject('in', expand(b)) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
crossover_lights_switch: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(a) | reject('in', expand(b)) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
crossover_night_lights_light_on: >-
{% set b = night_lights and night_lights.entity_id %}
{% if b %}
{{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
# Set up crossover lights for t8, t9 & t10 trigger. This is to stop the light flicker
crossover_night_lights_light: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | reject('in', expand(a)) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
crossover_night_lights_switch: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | reject('in', expand(a)) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
crossover_lights_light_on: >-
{% set a = light_switch.entity_id %}
{% if a %}
{{ expand(a) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
trigger:
- platform: state
entity_id: !input trigger_entity
to: "on"
id: 't0'
- platform: state
entity_id: !input trigger_entity
to: "on"
id: 't1'
- platform: state
entity_id: !input trigger_entity
to: "off"
id: 't2'
- platform: state
id: "t3"
entity_id: !input motion_trigger
from: "off"
to: "on"
- platform: state
id: "t4"
entity_id: !input motion_trigger
from: "on"
to: "off"
- platform: state
id: "t5"
entity_id: !input night_lights_entity_state
from: "off"
to: "on"
- platform: time
id: "t6"
at: !input night_lights_after_time
- platform: numeric_state
id: "t7"
entity_id: sun.sun
attribute: elevation
below: !input night_lights_sun_elevation
- platform: state
id: "t8"
entity_id: !input night_lights_entity_state
from: "on"
to: "off"
- platform: time
id: "t9"
at: !input night_lights_before_time
- platform: numeric_state
id: "t10"
entity_id: sun.sun
attribute: elevation
above: !input night_lights_sun_elevation_rising
- platform: homeassistant
id: "t11"
event: start
# All Conditions
condition:
#Trigger conditions
- condition: or
conditions:
- condition: and # trigger for ON state
conditions:
- condition: trigger
id: 't0'
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- condition: or
conditions:
- condition: and
conditions:
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'off'
- "{{include_motion_trigger == 'disable_motion_trigger'}}"
- condition: and # trigger for ON state
conditions:
- condition: trigger
id: 't1'
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- condition: or
conditions:
- condition: and
conditions:
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'on'
- condition: and # trigger for OFF state
conditions:
- condition: trigger
id: 't2'
- condition: state
entity_id: !input trigger_entity
state: 'off'
- condition: and # trigger for ON state
conditions:
- condition: trigger
id: 't3'
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- condition: and # trigger for ON state
conditions:
- condition: trigger
id: 't4'
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- condition: and # trigger by the start of night light entity state & check if any lights are on
conditions:
- condition: trigger
id: 't5'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'entity_state_enabled' in night_lights_conditions }}"
- condition: state
entity_id: !input night_lights_entity_state
match: any
state: 'on'
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by the start of night lights time & check if any lights are on
conditions:
- condition: trigger
id: 't6'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'time_enabled' in night_lights_conditions }}"
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by the start of night lights sun elevation & check if any lights are on
conditions:
- condition: trigger
id: 't7'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'sun_enabled' in night_lights_conditions }}"
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by the end of night lights entity state & check if any lights are on
conditions:
- condition: trigger
id: 't8'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'entity_state_enabled' in night_lights_conditions }}"
- condition: state
entity_id: !input night_lights_entity_state
state: 'off'
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by the end of night lights time & check if any lights are on
conditions:
- condition: trigger
id: 't9'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'time_enabled' in night_lights_conditions }}"
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by the end of night lights sun elevation & check if any lights are on
conditions:
- condition: trigger
id: 't10'
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'sun_enabled' in night_lights_conditions }}"
- condition: or
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- condition: and # trigger by HA Restart, check if the timer helper is disabled & check if any triggers are on
conditions:
- condition: trigger
id: 't11'
- condition: or
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
action:
- choose:
- alias: "Check if night lights are enabled and within conditions"
conditions:
- condition: and
conditions:
- alias: "Check if night lights is enabled"
condition: or
conditions:
- "{{ 'night_lights_enabled' in include_night_lights }}"
- alias: "Check if night lights entity state is enabled"
condition: or
conditions:
- "{{ ('time_enabled' in night_lights_conditions) and not ('entity_state_enabled' in night_lights_conditions) }}"
- "{{ ('sun_enabled' in night_lights_conditions) and not ('entity_state_enabled' in night_lights_conditions) }}"
- condition: and
conditions:
- "{{ 'entity_state_enabled' in night_lights_conditions }}"
- condition: state
entity_id: !input night_lights_entity_state
state: 'on'
match: any
- alias: "Check if night lights time is enabled"
condition: or
conditions:
- "{{ ('entity_state_enabled' in night_lights_conditions) and not ('time_enabled' in night_lights_conditions) }}"
- "{{ ('sun_enabled' in night_lights_conditions) and not ('time_enabled' in night_lights_conditions) }}"
- condition: and
conditions:
- "{{ 'time_enabled' in night_lights_conditions }}"
- condition: time
after: !input night_lights_after_time
before: !input night_lights_before_time
- alias: "Check if night lights sun is enabled"
condition: or
conditions:
- "{{ ('entity_state_enabled' in night_lights_conditions) and not ('sun_enabled' in night_lights_conditions) }}"
- "{{ ('time_enabled' in night_lights_conditions) and not ('sun_enabled' in night_lights_conditions) }}"
- "{{ ('sun_enabled' in night_lights_conditions) and (((is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun','elevation') <= night_lights_sun_elevation | float(90))) or ((is_state_attr('sun.sun', 'rising', true)) and (state_attr('sun.sun','elevation') <= night_lights_sun_elevation_rising | float(90)))) }}"
sequence:
- choose:
- alias: "Turn off normal lights when trigger by start night lights conditions"
conditions:
- condition: trigger
id:
- 't5'
- 't6'
- 't7'
sequence:
- choose:
- alias: "light - switch - scene - script is ON"
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) or (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) or (is_state(boolean_scenes_scripts, 'on')) }}"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ crossover_lights_light }}"
data:
transition: "{{ light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ crossover_lights_light }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ crossover_lights_switch }}"
- choose:
- alias: "Adjust the lights settings when crossing over if lights are ON is selected in night light control"
conditions:
- condition: template
value_template: "{{ 'if_lights_are_on_adjust_when_crossing_over' in include_night_light_control }}"
sequence:
- alias: "Turn ON lights"
service: light.turn_on
target:
entity_id: "{{ crossover_night_lights_light_on }}"
data: "{{ night_light_data }}"
- choose:
- alias: "Night Lights"
conditions:
- condition: trigger
id:
- "t0"
- "t4"
- 't5'
- 't6'
- 't7'
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data: "{{ night_light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ night_switch_entities_off }}"
- choose:
- alias: "If night_timer is disabled"
conditions:
- condition: template
value_template: "{{ night_include_timer == 'disable_night_timer' }}"
sequence:
- stop: "Stop the automation"
- alias: "If night_timer is enabled"
conditions:
- condition: template
value_template: "{{ night_include_timer == 'enable_night_timer' }}"
sequence:
- alias: "Wait for trigger"
wait_for_trigger:
platform: state
entity_id: !input trigger_entity
to: "off"
timeout: !input night_timer
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
data:
transition: "{{ night_light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- alias: "Trigger turned OFF"
conditions:
- condition: trigger
id: "t2"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
data:
transition: "{{ night_light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- alias: "Motion sensor actions"
conditions:
- condition: trigger
id:
- "t1"
- "t3"
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data: "{{ night_light_data }}"
- alias: "Home Assistant Restart"
conditions:
- condition: trigger
id: "t11"
sequence:
- choose:
- alias: "If trigger is ON, light is ON, motion is enabled and motion is detected"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "If trigger is ON and light is ON"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data: "{{ night_light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ night_switch_entities_off }}"
- choose:
- alias: "If night_timer is disabled"
conditions:
- condition: template
value_template: "{{ night_include_timer == 'disable_night_timer' }}"
sequence:
- stop: "Stop the automation"
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ night_include_timer == 'enable_night_timer' }}"
sequence:
- alias: "Wait for trigger"
wait_for_trigger:
platform: state
entity_id: !input trigger_entity
to: "off"
timeout: !input night_timer
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
data:
transition: "{{ night_light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- alias: "If trigger is ON, light is OFF, motion is enabled and motion is detected"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count) == 0 }}"
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'on'
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data: "{{ night_light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ night_switch_entities_off }}"
- alias: "If trigger is ON and light is OFF"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count) == 0 }}"
sequence:
- stop: "Stop the automation"
- alias: "If trigger is OFF and light is ON"
conditions:
- condition: state
entity_id: !input trigger_entity
state: 'off'
- "{{ (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
data:
transition: "{{ night_light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ night_light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
default:
- choose:
- alias: "Turn off night lights when trigger by end night lights conditions"
conditions:
- condition: trigger
id:
- 't8'
- 't9'
- 't10'
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) or (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0) or (is_state(night_boolean_scenes_scripts, 'on')) }}"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ crossover_night_lights_light }}"
data:
transition: "{{ night_light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ crossover_night_lights_light }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ crossover_night_lights_switch }}"
- choose:
- alias: "Adjust the lights settings when crossing over if lights are ON is selected in night light control"
conditions:
- condition: template
value_template: "{{ 'if_lights_are_on_adjust_when_crossing_over' in include_night_light_control }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ crossover_lights_light_on }}"
data: "{{ light_data }}"
- choose:
- alias: "Default actions"
conditions:
- condition: trigger
id:
- "t0"
- "t4"
- 't8'
- 't9'
- 't10'
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data: "{{ light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ switch_entities_off }}"
- choose:
- alias: "If timer is disabled"
conditions:
- condition: template
value_template: "{{ include_timer == 'disable_timer' }}"
sequence:
- stop: "Stop the automation"
- alias: "If timer is enabled"
conditions:
- condition: template
value_template: "{{ include_timer == 'enable_timer' }}"
sequence:
- alias: "Wait for trigger"
wait_for_trigger:
platform: state
entity_id: !input trigger_entity
to: "off"
timeout: !input timer
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- alias: "Trigger turned OFF"
conditions:
- condition: trigger
id: "t2"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- alias: "Motion sensor actions"
conditions:
- condition: trigger
id:
- "t1"
- "t3"
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data: "{{ light_data }}"
- alias: "Home Assistant Restart"
conditions:
- condition: trigger
id: "t11"
sequence:
- choose:
- alias: "If trigger is ON, light is ON, motion is enabled and motion is detected"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "If trigger is ON and light is ON"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data: "{{ light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ switch_entities_off }}"
- choose:
- alias: "If timer is disabled"
conditions:
- condition: template
value_template: "{{ include_timer == 'disable_timer' }}"
sequence:
- stop: "Stop the automation"
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ include_timer == 'enable_timer' }}"
sequence:
- alias: "Wait for trigger"
wait_for_trigger:
platform: state
entity_id: !input trigger_entity
to: "off"
timeout: !input timer
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- alias: "If trigger is ON, light is OFF, motion is enabled and motion is detected"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count) == 0 }}"
- "{{include_motion_trigger == 'enable_motion_trigger'}}"
- condition: state
entity_id: !input motion_trigger
state: 'on'
sequence:
- alias: "Turn ON the lights"
service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data: "{{ light_data }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ switch_entities_off }}"
- alias: "If trigger is ON and light is OFF"
conditions:
- condition: state
entity_id: !input trigger_entity
match: any
state: 'on'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count) == 0 }}"
sequence:
- stop: "Stop the automation"
- alias: "If trigger is OFF and light is ON"
conditions:
- condition: state
entity_id: !input trigger_entity
state: 'off'
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
sequence:
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ light_transition_off }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn off the lights"
service: light.turn_off
target:
entity_id: "{{ light_entities }}"
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment