Skip to content

Instantly share code, notes, and snippets.

@FabianGabor
Forked from Blackshome/sensor-light.yaml
Last active November 17, 2023 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FabianGabor/0ebf8e03459c9f9251c9f3fe3edcbb8c to your computer and use it in GitHub Desktop.
Save FabianGabor/0ebf8e03459c9f9251c9f3fe3edcbb8c to your computer and use it in GitHub Desktop.
Home Assistant Sensor Light that can be used in Blueprints
blueprint:
name: Sensor Light
description: >
# Sensor Light
**Version: 5.0**
The most common automation used for a sensor light.
Let us know what you think of this blueprint and for community support including updates: [Click Here](https://community.home-assistant.io/t/481048)
**The Automation Process:**
- In this example we will use a motion sensor as the trigger, but you can use one or multiple [Binary Sensors](https://www.home-assistant.io/integrations/binary_sensor/) and or a [schedule](https://www.home-assistant.io/integrations/schedule/) as the trigger/s.
- Triggers on a motion sensor and turns the lights ON.
- When no motion is detected, a time delay is activated and turns the lights OFF Automatically.
- The lights will stay ON if the motion sensor detects motion before the time delay turns the lights OFF. It will then reset the time delay after last motion is detected.
- You have the option to select scenes. This allows you to turn ON a scene when motion is detected and turn OFF a scene when the time delay has ended.
- You have the option to use the "Light Control". This allows you to set a brightness level, colour temperature in kelvin and a transition time for your lights.
- You have the option to use the "Dynamic Lighting". It will dynamically adjust the brightness % to a floating lux value. When it gets darker your brightness will increase and as it gets lighter your brightness will decrease.
- You have the option to use the "By-pass Options". This allows you to add switches to manually By-pass the trigger sensor so you can use the lights as normal by turning them ON and OFF manually.
- You have the option to use the "Sun Elevation". This is used for adding a condition to only work when it is dark by setting the suns position to the horizon.
- You have the option to set an Ambient Light Sensor and set the LUX value. This is used for adding a condition to only work when it is dark or below the Ambient Light LUX Value.
- You have the option to set a start time, an end time and select weekdays. This will only allow the automation to run between the time periods.
- You have the option to use the "Device Tracker". This can be useful if you have pets triggering the trigger sensor turning your lights ON and OFF when no one is home.
- You have the option to use "Night Lights". It can be used for having lower softer lights come ON when going to the bathroom at night or having different lights come ON with an entity state, time or sun elevation.
- Safe guard built in for HA restart.
- Works with my Blueprint Add ON for media control [Click Here](https://community.home-assistant.io/t/591824)
**Sensor Light Add On:** We have an add on to this blueprint which allows you to have a movie light mode, alarm lights, smoke alarm lights + more. It is all controlled through an automation link via the bypass allowing both automations to work together. So be sure to check out our [Sensor Light Add On](https://community.home-assistant.io/t/591824/1)
Note: If you turn the light on manually and the motion sensor detects motion the light will turn off automatically. It is recommended to use the "Trigger Sensor By-pass" options if you would like to keep the lights ON or OFF for extended time periods.
Required = *
The Settings & Best Practice Guidelines: [Click Here](https://community.home-assistant.io/t/481048/345)
Need help? See our FAQ: [Click Here](https://community.home-assistant.io/t/481048/6)
**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) 🙂
domain: automation
input:
motion_trigger:
name: Trigger Sensor - Binary Sensors - Schedule *
description: The Sensor/s that turns the lights ON and OFF. The trigger can be any
[Binary Sensors](https://www.home-assistant.io/integrations/binary_sensor/) you like.
If you would rather a time based trigger, then you can also add a [schedule](https://www.home-assistant.io/integrations/schedule/) helper.
selector:
entity:
filter:
domain:
- binary_sensor
- schedule
multiple: true
light_switch:
name: Lights - Switches - Scenes *
description: The lights that get turned on by the trigger sensor/s. You can also add switches and scenes.
If adding a scene please read "Scenes To Turn OFF" below.
**NOTE** - You can only use entities. Areas and devices are not supported.
selector:
target:
entity:
domain:
- light
- switch
- scene
end_scenes:
name: Scenes To Turn OFF
description: If you have selected a scene to be turned ON above in "Lights - Switches - Scenes" or below in "Night Lights" and you would like it to be turned OFF after the time delay,
you must create another identical scene with everything OFF and select it here.
default: []
selector:
entity:
multiple: true
filter:
domain:
- scene
time_delay:
name: Time Delay
description: The delay time to leave the lights on after the last trigger is detected.
default: 5
selector:
number:
min: 0
max: 30
step: 0.5
unit_of_measurement: minutes
include_light_control:
name: Use The Light Control Options (Optional)
description: Select any option you would like to use. It will only control a "light" entity that supports each option you select.
The settings are below for each option.
default: []
selector:
select:
multiple: true
options:
- label: Use brightness
value: "use_brightness"
- label: Use colour temperature
value: "use_colour_temperature"
- 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_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_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_dynamic_lighting:
name: Use The Dynamic Lighting Option (Optional)
description: This will constantly adjust your lighting brightness % to a floating lux value.
Example - When it gets darker your brightness will increase and as it gets lighter your brightness will decrease.
This will only work for normal lights. Priority will be given to dynamic lighting option even
if you have selected to "Use brightness" above in the "Light Control Options".
For more information on dynamic lighting settings [Click Here](https://community.home-assistant.io/t/481048/837)
default: []
selector:
select:
multiple: true
options:
- label: Use Dynamic Lighting - Brightness
value: "enable_dynamic_lighting_brightness"
dynamic_lighting_lux_sensor:
name: Dynamic Lighting - Ambient Light Sensor
description: Select the ambient sensor to be used for your dynamic lighting.
default: []
selector:
entity:
filter:
domain: sensor
device_class: illuminance
dynamic_lighting_max_lux:
name: Dynamic Lighting - Max Lux Value
description: Set the maximum lux value. When the lux value is equal or above your set point the minimum brightness will be achieved.
This is the value you would like your lights to start coming ON or turn OFF.
selector:
entity:
filter:
domain: input_number
dynamic_lighting_min_lux:
name: Dynamic Lighting - Min Lux Value
description: Set the minimum lux value. When the lux value is equal or below your set point the maximum brightness will be achieved.
default: 40
selector:
number:
min: 0
max: 10
step: 1
unit_of_measurement: lux
dynamic_lighting_max_brightness:
name: Dynamic Lighting - Max Brightness Value
description: Set the maximum brightness value. This will be your maximum brightness for your lights.
default: 100
selector:
number:
min: 10
max: 100
step: 1
unit_of_measurement: '%'
dynamic_lighting_min_brightness:
name: Dynamic Lighting - Min Brightness Value
description: Set the minimum brightness value. This will be your minimum brightness for your lights.
If setting the brightness to 0% then the light will turn OFF.
default: 0
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: '%'
dynamic_lighting_heartbeat:
name: Dynamic Lighting - Heartbeat
description: Set the heartbeat rate. This is the speed it will run at.
At each heartbeat it will check your lux value and change the brightness if necessary.
default: 1
selector:
number:
min: 0.25
max: 10
step: 0.25
unit_of_measurement: minutes
include_bypass:
name: Use The By-pass Options (Optional)
description: Select enable or disable. All of the three enable options will allow manual control of your lights.
The three enable options are only for selecting what should happen when you turn the by-pass ON.
When enabling an option, please enter the by-pass switch into the corresponding input below.
default: []
selector:
select:
options:
- label: 1 - Enable the By-pass - Turn lights ON
value: "bypass_enabled_turn_on"
- label: 2 - Enable the By-pass - Turn lights OFF
value: "bypass_enabled_turn_off"
- label: 3 - Enable the By-pass - Keep the lights current state
value: "bypass_enabled_stop"
multiple: true
motion_bypass_lights_on:
name: By-pass Switch - Turn lights ON
description: Select the switches that will turn your lights ON, By-pass the trigger sensor and make your lights function as normal.
The entity cannot be included in, "Lights - Switches - Scenes" and or "Night Lights" selections.
default: []
selector:
entity:
multiple: true
motion_bypass_lights_off:
name: By-pass Switch - Turn lights OFF
description: Select the switches that will turn your lights OFF, By-pass the trigger sensor and make your lights function as normal.
The entity cannot be included in, "Lights - Switches - Scenes" and or "Night Lights" selections.
default: []
selector:
entity:
multiple: true
motion_bypass_lights_stop:
name: By-pass Switch - Keep The Lights Current State
description: Select the switches that will pause your lights, By-pass the trigger sensor and make your lights function as normal.
The entity cannot be included in, "Lights - Switches - Scenes" and or "Night Lights" selections.
default: []
selector:
entity:
multiple: true
bypass_time_delay:
name: By-pass - Time Delay
description: This is only used in two by-pass scenarios, when the lights are already ON and when the automation turns the lights OFF.
The first scenario is when you have selected option 2 above to "Enable the By-pass - Turn lights OFF".
And the second scenario is when you turn the by-pass OFF, the trigger sensor is OFF and your lights are ON.
In both scenarios the automation will turn your lights OFF after the set time delay.
default: 0
selector:
number:
min: 0
max: 10
step: 0.25
unit_of_measurement: minutes
include_bypass_auto_off:
name: Use The By-pass Auto OFF Option (Optional)
description: This is used when you turn the by-pass ON and you would like the by-pass to automatically turn OFF in a set time delay.
It can also be used as a timer to turn the lights ON and then OFF if you have chosen to use "Enable the By-pass - Turn lights ON" above.
default: []
selector:
select:
options:
- label: Enable the by-pass auto off - Turn lights ON option
value: "bypass_auto_off_enabled_on"
- label: Enable the by-pass auto off - Turn lights OFF option
value: "bypass_auto_off_enabled_off"
- label: Enable the by-pass auto off - Keep the lights current state
value: "bypass_auto_off_enabled_stop"
multiple: true
bypass_auto_off_delay:
name: By-pass Auto OFF - Time Delay
description: Set the by-pass auto OFF time delay. The time delay starts from the last by-pass that was turned ON.
default: 60
selector:
number:
min: 1
max: 240
step: 1
unit_of_measurement: minutes
include_sun:
name: Use The Sun Option (Optional)
description: This is used for adding a condition to only work when it is dark or below the "Sun Elevation" setting.
This sun option is a global condition and can work alongside with the other options.
You don't need to enable this option for night lights sun elevation condition to work.
default: sun_disabled
selector:
select:
options:
- label: Enable the sun option
value: "sun_enabled"
- label: Disable the sun option
value: "sun_disabled"
sun_elevation:
name: Sun Elevation Falling
description: This is the angle between the sun and the horizon.
A negative value mean the sun is BELOW the horizon. Guide is -1.5 dusk.
default: -1.5
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
sun_elevation_rising:
name: Sun Elevation Rising
description: This is the angle between the sun and the horizon.
A negative value mean the sun is BELOW the horizon. Guide is -4.0 dawn.
default: -4.0
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
include_ambient:
name: Use The Ambient Options (Optional)
description: This is used for adding a condition to only work when it is dark or below the "Ambient Light LUX Value".
default: ambient_disabled
selector:
select:
options:
- label: Enable the ambient options
value: "ambient_enabled"
- label: Disable the ambient options
value: "ambient_disabled"
ambient_light_sensor:
name: Ambient Light Sensor
description: Select the ambient sensor to be used.
default: []
selector:
entity:
filter:
domain: sensor
device_class: illuminance
ambient_light_options:
name: Ambient Light Sensor - Site Conditions
description: In some cases when your lights turn ON, your ambient light sensor is affected, increasing its LUX value.
This can cause the lights to go OFF prematurely. Please select an option that best suits your installation.
**NOTE** - If using an offset between the high and low lux value, then please select NO.
default: ambient_light_option_disabled
selector:
select:
options:
- label: YES - My Ambient Light Sensor is affected by the Lights
value: "ambient_light_option_enabled"
- label: NO - My Ambient Light Sensor is not affected by the Lights
value: "ambient_light_option_disabled"
ambient_light_value:
name: Ambient Light - Low Lux Value
description: Set the Ambient Light Low Lux Value. The light will turn ON when the lux level is below the set value.
This value must be equal or lower than the "High Lux Value" below. Guide is 20 lux (dusk).
default: 20
selector:
number:
min: 0
max: 500
step: 10
unit_of_measurement: lux
ambient_light_high_value:
name: Ambient Light - High Lux Value
description: Set the Ambient Light High Lux Value. The light will turn OFF when the lux level is above the set value.
This value must be equal or higher than the "Low Lux Value" above.
Setting a value higher than the low value allows for an offset. Guide is 80 lux (dawn).
default: 80
selector:
number:
min: 0
max: 1000
step: 10
unit_of_measurement: lux
include_time:
name: Use The Time Options (Optional)
description: Use the "Start Time", "End Time" and "Weekdays" values to only run the automation between the time periods.
All the time settings are a global condition and can work alongside with the other options. You don't need to enable this option
for night lights time condition to work. For more information on time settings [Click Here](https://community.home-assistant.io/t/481048/310)
default: time_disabled
selector:
select:
options:
- label: Enable the time options
value: "time_enabled"
- label: Disable the time options
value: "time_disabled"
after_time:
name: Start Time
description: Set the start time.
default: 00:00:00
selector:
time:
before_time:
name: End Time
description: Set the end time.
default: 00:00:00
selector:
time:
weekday_options:
name: Weekdays
description: Select the days of the week you would like the automation to run. You must select "Enable the time options" above for the weekdays selections to work.
default:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
selector:
select:
multiple: true
mode: list
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"
include_device_tracker:
name: Use The Device Tracker Options (Optional)
description: Home Assistant can track your devices (mobile phones, etc) location to a set zone via the mobile app device tracker.
You must set up a zone and your devices (mobile phones, etc) to be tracked in Home Assistant for this option to work.
There are two enable options. "Zone" will track all devices in the zone and "Zone + People" will allow you to track the people in a zone.
This can be useful if you have pets triggering the trigger sensor turning your lights ON and OFF when no one is home.
default: device_tracker_disabled
selector:
select:
options:
- label: Enable the zone option
value: "zone_enabled"
- label: Enable the zone + people options
value: "zone_people_enabled"
- label: Disable the device tracker options
value: "device_tracker_disabled"
zone:
name: Device Tracker - Zone
description: Select the zone to track your devices and or people in.
default: []
selector:
entity:
filter:
domain: zone
people:
name: Device Tracker - People
description: Select the people you would like to track in the zone selected above. You must enter a zone above for this option to work.
default: []
selector:
entity:
multiple: true
filter:
domain:
- person
include_night_lights:
name: Use The Night Lights Options (Optional)
description: Enable the night lights options to only run between the "Night Lights Conditions".
This is useful for turning on different lights later in the night and / or setting a lower brightness level,
changing the colour setting or selecting a different scene. It can be used for having lower softer lights come ON
when going to the bathroom at night or having different lights come on when it is dark or below the sun elevation setting.
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:
name: Night Lights
description: The night lights that get turned on by the trigger sensor/s. You can also add switches and scenes.
If you have selected a scene and you would like it to be turned OFF after the time delay,
you must create another identical scene with everything OFF and enter it above in the "Scenes To Turn OFF".
**NOTE** - You can only use entities. Areas and devices are not supported.
default: {}
selector:
target:
entity:
domain:
- light
- switch
- scene
night_time_delay:
name: Night Lights - Time Delay
description: The delay time to leave the night lights on after the last trigger is detected.
default: 5
selector:
number:
min: 0
max: 30
step: 0.5
unit_of_measurement: minutes
include_night_light_control:
name: Night Lights - Use The Light Control Options (Optional)
description: Select any option you would like to use. It will only control a "light" entity that supports each option you select.
The settings are below for each option.
default: []
selector:
select:
multiple: true
options:
- label: Use brightness
value: "use_brightness"
- label: Use colour temperature
value: "use_colour_temperature"
- label: Use transition
value: "use_transition"
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_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_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
night_lights_conditions:
name: Night Lights Conditions (Required For Night Lights)
description: Select any option you would like to use to enable a night light condition.
You must select "Enable the night lights options" in "Use The Night Lights Options" above and at least one
"Night Lights Condition" for night lights to work. The settings are below for each option.
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 be ON for night lights to work. This can be your phone on "Do Not Disturb", a helper, a bed sensor etc.
The entity cannot be included in, "Lights - Switches - Scenes" and or "Night Lights" selections. For more information [Click Here](https://community.home-assistant.io/t/481048/663)
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: This is the angle between the sun and the horizon.
A negative value mean the sun is BELOW the horizon. Guide is -1.5 is 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: This is the angle between the sun and the horizon.
A negative value mean the sun is BELOW the horizon. Guide is -4.0 is dawn.
default: -4.0
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
# If motion sensor turns ON again within the time delay, it will restart the script.
mode: restart
max_exceeded: silent
variables:
motion_trigger: !input motion_trigger
light_switch: !input light_switch
end_scenes: !input end_scenes
time_delay: !input time_delay
include_light_control: !input include_light_control
light_brightness: !input light_brightness
brightness_value: "{{ iif ('use_brightness' in include_light_control , light_brightness, ) }}"
light_colour_temperature: !input light_colour_temperature
temperature_value: "{{ iif ('use_colour_temperature' in include_light_control , light_colour_temperature, [] ) }}"
light_transition_on: !input light_transition_on
light_transition_off: !input light_transition_off
transition_on_value: "{{ iif ('use_transition' in include_light_control, light_transition_on, ) }}"
transition_off_value: "{{ iif ('use_transition' in include_light_control, light_transition_off, ) }}"
include_dynamic_lighting: !input include_dynamic_lighting
dynamic_lighting_lux_sensor: !input dynamic_lighting_lux_sensor
dynamic_lighting_max_lux: !input dynamic_lighting_max_lux
dynamic_lighting_min_lux: !input dynamic_lighting_min_lux
dynamic_lighting_max_brightness: !input dynamic_lighting_max_brightness
dynamic_lighting_min_brightness: !input dynamic_lighting_min_brightness
dynamic_lighting_heartbeat: !input dynamic_lighting_heartbeat
include_bypass: !input include_bypass
motion_bypass_lights_on: !input motion_bypass_lights_on
motion_bypass_lights_off: !input motion_bypass_lights_off
motion_bypass_lights_stop: !input motion_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
include_sun: !input include_sun
sun_elevation: !input sun_elevation
sun_elevation_rising: !input sun_elevation_rising
include_ambient: !input include_ambient
ambient_light_sensor: !input ambient_light_sensor
ambient_light_options: !input ambient_light_options
ambient_light_value: !input ambient_light_value
ambient_light_high_value: !input ambient_light_high_value
include_time: !input include_time
after_time: !input after_time
before_time: !input before_time
weekday_options: !input weekday_options
include_device_tracker: !input include_device_tracker
zone: !input zone
people: !input people
include_night_lights: !input include_night_lights
night_lights: !input night_lights
night_time_delay: !input night_time_delay
include_night_light_control: !input include_night_light_control
night_light_brightness: !input night_light_brightness
night_brightness_value: "{{ iif ('use_brightness' in include_night_light_control , night_light_brightness, ) }}"
night_light_colour_temperature: !input night_light_colour_temperature
night_temperature_value: "{{ iif ('use_colour_temperature' in include_night_light_control , night_light_colour_temperature, [] ) }}"
night_light_transition_on: !input night_light_transition_on
night_light_transition_off: !input night_light_transition_off
night_transition_on_value: "{{ iif ('use_transition' in include_night_light_control, night_light_transition_on, ) }}"
night_transition_off_value: "{{ iif ('use_transition' in include_night_light_control, night_light_transition_off, ) }}"
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
# Split domains for light switch targets and check entities are OFF - exclude scenes as they have no off state
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 }}"
scene_entities: "{{ expand(light_switch.entity_id) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }}"
# Split domains for night lights target and check entities are OFF - exclude scenes as they have no off state
night_light_entities_off: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | selectattr('domain', 'eq', 'light') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
night_switch_entities_off: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | selectattr('domain', 'eq', 'switch') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
# Split domains for night lights target
night_light_entities: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | selectattr('domain', 'eq', 'light') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
night_switch_entities: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
night_scene_entities: >-
{% set a = light_switch.entity_id %}
{% set b = night_lights and night_lights.entity_id %}
{% if a and b %}
{{ expand(b) | selectattr('domain', 'eq', 'scene') | map(attribute='entity_id') | list }}
{% else %}
[]
{% endif %}
# Set up crossover lights for t6 trigger. This is to stop the light flicker & turn off entities not required in each domain, light & switches - only works for entities
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 %}
# Set up crossover lights for t9 trigger. This is to stop the light flicker & turn off entities not required in each domain, light & switches - only works for entities
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 %}
trigger:
- platform: state
id: "t0"
entity_id: !input motion_trigger
from: "off"
to: "on"
- platform: numeric_state
id: "t1"
entity_id: sun.sun
attribute: elevation
below: !input sun_elevation
- platform: numeric_state
id: "t2"
entity_id: !input ambient_light_sensor
below: !input ambient_light_value
- platform: time
id: "t3"
at: !input after_time
- platform: state
id: "t4"
entity_id: !input night_lights_entity_state
from: "off"
to: "on"
- platform: time
id: "t5"
at: !input night_lights_after_time
- platform: numeric_state
id: "t6"
entity_id: sun.sun
attribute: elevation
below: !input night_lights_sun_elevation
- platform: state
id: "t7_on"
entity_id: !input motion_bypass_lights_on
from: "off"
to: "on"
- platform: state
id: "t7_off"
entity_id: !input motion_bypass_lights_off
from: "off"
to: "on"
- platform: state
id: "t7_stop"
entity_id: !input motion_bypass_lights_stop
from: "off"
to: "on"
- platform: state
id: "t8_on"
entity_id: !input motion_bypass_lights_on
from: "on"
to: "off"
- platform: state
id: "t8_off"
entity_id: !input motion_bypass_lights_off
from: "on"
to: "off"
- platform: state
id: "t8_stop"
entity_id: !input motion_bypass_lights_stop
from: "on"
to: "off"
- platform: numeric_state
id: "t9"
entity_id: sun.sun
attribute: elevation
above: !input sun_elevation_rising
- platform: numeric_state
id: "t10"
entity_id: !input ambient_light_sensor
above: !input ambient_light_high_value
- platform: time
id: "t11"
at: !input before_time
- platform: state
id: "t12"
entity_id: !input night_lights_entity_state
from: "on"
to: "off"
- platform: time
id: "t13"
at: !input night_lights_before_time
- platform: numeric_state
id: "t14"
entity_id: sun.sun
attribute: elevation
above: !input night_lights_sun_elevation_rising
- platform: homeassistant
id: "t15"
event: start
# All Conditions
condition:
#Trigger conditions
- condition: or
conditions:
- condition: and # trigger from off to on
conditions:
- condition: state
entity_id: !input motion_trigger
match: any
state: 'on'
- condition: trigger
id: 't0'
- condition: and # trigger by sun & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_sun == 'sun_enabled' }}"
- condition: trigger
id: 't1'
- condition: and # trigger by ambient & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_ambient == 'ambient_enabled' }}"
- condition: trigger
id: 't2'
- condition: and # trigger by time & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_time == 'time_enabled' }}"
- condition: trigger
id: 't3'
- condition: and # trigger by the start of night light entity state & check if any lights are on
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'entity_state_enabled' in night_lights_conditions }}"
- "{{ expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: state
entity_id: !input night_lights_entity_state
match: any
state: 'on'
- condition: trigger
id: 't4'
- condition: and # trigger by the start of night lights time & check if any lights are on
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'time_enabled' in night_lights_conditions }}"
- "{{ expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: trigger
id: 't5'
- condition: or # trigger by the start of night lights sun elevation & check if any lights are on
conditions:
- condition: and
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'sun_enabled' in night_lights_conditions }}"
- "{{ expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: trigger
id: 't6'
- condition: and # trigger by by-pass turning on
conditions:
- condition: trigger
id: 't7_on'
- "{{ 'bypass_enabled_turn_on' in include_bypass }}"
- condition: and # trigger by by-pass turning off
conditions:
- condition: trigger
id: 't7_off'
- "{{ 'bypass_enabled_turn_off' in include_bypass }}"
- condition: and # trigger by by-pass stop
conditions:
- condition: trigger
id: 't7_stop'
- "{{ 'bypass_enabled_stop' in include_bypass }}"
- condition: and # trigger by by-pass turning on
conditions:
- condition: trigger
id: 't8_on'
- "{{ 'bypass_enabled_turn_on' in include_bypass }}"
- condition: and # trigger by by-pass turning off
conditions:
- condition: trigger
id: 't8_off'
- "{{ 'bypass_enabled_turn_off' in include_bypass }}"
- condition: and # trigger by by-pass stop
conditions:
- condition: trigger
id: 't8_stop'
- "{{ 'bypass_enabled_stop' in include_bypass }}"
- condition: and # trigger by rise sun & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_sun == 'sun_enabled' }}"
- condition: trigger
id: 't9'
- condition: and # trigger by rise ambient, site condition set to NO & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_ambient == 'ambient_enabled' }}"
- "{{ ambient_light_options == 'ambient_light_option_disabled' }}"
- condition: trigger
id: 't10'
- condition: and # trigger by time & check motion trigger is on
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
- "{{ include_time == 'time_enabled' }}"
- condition: trigger
id: 't11'
- condition: and # trigger by the end of night lights entity state & check if any lights are on
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'entity_state_enabled' in night_lights_conditions }}"
- "{{ expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: state
entity_id: !input night_lights_entity_state
state: 'off'
- condition: trigger
id: 't12'
- condition: and # trigger by the end of night lights time & check if any lights are on
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'time_enabled' in night_lights_conditions }}"
- "{{ expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: trigger
id: 't13'
- condition: or # trigger by the end of night lights sun elevation & check if any lights are on
conditions:
- condition: and
conditions:
- "{{ include_night_lights == 'night_lights_enabled' }}"
- "{{ 'sun_enabled' in night_lights_conditions }}"
- "{{ expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0 }}"
- condition: trigger
id: 't14'
- condition: and # trigger by HA Restart & check if any lights are on
conditions:
- "{{ (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) or ((include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0)) }}"
- condition: trigger
id: 't15'
- condition: and # trigger by HA Restart & check if any triggers are on
conditions:
- condition: state
entity_id: !input motion_trigger
match: any
state: 'on'
- condition: trigger
id: 't15'
- condition: and # trigger by HA Restart & check if by-pass auto off is enabled and any by-passes are on
conditions:
- "{{ ('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: trigger
id: 't15'
- condition: or
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
# Check Motion Sensor Manual By-pass
- 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 motion_bypass_lights_on
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_off
state: 'off'
- condition: state
entity_id: !input motion_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 motion_bypass_lights_on
state: 'off'
- condition: state
entity_id: !input motion_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 motion_bypass_lights_on
state: 'off'
- condition: state
entity_id: !input motion_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 motion_bypass_lights_off
state: 'off'
- condition: state
entity_id: !input motion_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 motion_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 motion_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 motion_bypass_lights_stop
state: 'off'
- condition: trigger
id:
- 't7_on'
- 't7_off'
- 't7_stop'
- 't8_on'
- 't8_off'
- 't8_stop'
- 't15'
# Check Sun Elevation
- condition: or
conditions:
- "{{ include_sun == 'sun_disabled' }}"
- "{{ include_sun == 'sun_enabled_night_lights' }}"
- "{{ (include_sun == 'sun_enabled') and (is_state_attr('sun.sun', 'rising', false)) and (state_attr('sun.sun','elevation') <= sun_elevation | float(90)) }}"
- "{{ (include_sun == 'sun_enabled') and (is_state_attr('sun.sun', 'rising', true)) and (state_attr('sun.sun','elevation') <= sun_elevation_rising | float(90)) }}"
- condition: trigger
id:
- 't7_on'
- 't7_off'
- 't7_stop'
- 't8_on'
- 't8_off'
- 't8_stop'
- 't9'
# Check Ambient Light Sensor
- condition: or
conditions:
- "{{ include_ambient == 'ambient_disabled' }}"
- "{{ ambient_light_sensor == [] }}"
- "{{ (include_ambient == 'ambient_enabled') and (states[ambient_light_sensor].state | int < ambient_light_value | int) }}"
- "{{ (include_ambient == 'ambient_enabled') and (states[ambient_light_sensor].state | int < ambient_light_high_value | int) and (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (include_ambient == 'ambient_enabled') and (states[ambient_light_sensor].state | int < ambient_light_high_value | int) and ((include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0)) }}"
- "{{ (ambient_light_options == 'ambient_light_option_enabled') and (expand(light_switch.entity_id) | selectattr('state', '==', 'on') | list | count > 0) }}"
- "{{ (ambient_light_options == 'ambient_light_option_enabled') and ((include_night_lights == 'night_lights_enabled') and (expand(night_lights.entity_id) | selectattr('state', '==', 'on') | list | count > 0)) }}"
- condition: trigger
id:
- 't7_on'
- 't7_off'
- 't7_stop'
- 't8_on'
- 't8_off'
- 't8_stop'
- 't10'
# Check The Time Options
- condition: or
conditions:
- "{{ include_time == 'time_disabled' }}"
- condition: and
conditions:
- condition: time
after: !input after_time
before: !input before_time
weekday: !input weekday_options
- "{{ include_time == 'time_enabled' }}"
- condition: and
conditions:
- condition: time
weekday: !input weekday_options
- condition: trigger
id: 't11'
- condition: trigger
id:
- 't7_on'
- 't7_off'
- 't7_stop'
- 't8_on'
- 't8_off'
- 't8_stop'
# Check the Device Tracker Options
- condition: or
conditions:
- "{{ include_device_tracker == 'device_tracker_disabled' }}"
- condition: and
conditions:
- condition: numeric_state
entity_id: !input zone
above: 0
- "{{ include_device_tracker == 'zone_enabled' }}"
- condition: and
conditions:
- "{{ (state_attr(zone, 'persons') + people) | count != dict.fromkeys(state_attr(zone, 'persons') + people) | count }}"
- "{{ include_device_tracker == 'zone_people_enabled' }}"
- condition: trigger
id:
- 't7_on'
- 't7_off'
- 't7_stop'
- 't8_on'
- 't8_off'
- 't8_stop'
action:
- choose:
- alias: "Check if the night lights are enabled and within the night lights 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: "By-pass is turned on & check by-pass option - turn lights off"
conditions:
- condition: trigger
id: 't7_off'
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "By-pass is turned on & check by-pass option - Keep the current lights state"
conditions:
- condition: trigger
id: 't7_stop'
sequence:
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "By-pass is turned off & check if the motion trigger is off"
conditions:
- condition: trigger
id:
- 't8_on'
- 't8_off'
- 't8_stop'
- condition: state
entity_id: !input motion_trigger
match: all
state: 'off'
sequence:
- choose:
- alias: "Check all by-pass are off"
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_off
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: all
state: 'off'
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- stop: "Stop the automation"
- alias: "Motion trigger is off and check if any by-passes are on"
conditions:
- condition: or
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "By-pass is turned off & check if the motion trigger is on"
conditions:
- condition: trigger
id:
- 't8_on'
- 't8_off'
- 't8_stop'
- condition: state
entity_id: !input motion_trigger
match: any
state: 'on'
sequence:
- choose:
- alias: "Check all by-pass are off and check conditions if enabled "
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_off
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: all
state: 'off'
- condition: or
conditions:
- "{{ (include_sun == 'sun_enabled') and (state_attr('sun.sun','elevation') >= sun_elevation | float(90)) }}"
- "{{ (include_ambient == 'ambient_enabled') and (ambient_light_options == 'ambient_light_option_disabled') and (states[ambient_light_sensor].state | int > ambient_light_value | int) }}"
- "{{ (include_ambient == 'ambient_enabled') and (ambient_light_options == 'ambient_light_option_enabled') and (states[ambient_light_sensor].state | int > ambient_light_value | int) and (expand(night_lights.entity_id) | selectattr('state', '==', 'off') | list | count > 0) }}"
- condition: and
conditions:
- condition: time
after: !input before_time
before: !input after_time
- "{{ include_time == 'time_enabled' }}"
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- stop: "Stop the automation"
- alias: "Motion trigger is on and check if any by-passes are on"
conditions:
- condition: or
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "Sun, Ambient Light Sensor & time above setting to turn off"
conditions:
- condition: trigger
id:
- 't9'
- 't10'
- 't11'
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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- stop: "Stop the automation"
- alias: "Turn off normal lights when trigger by start night lights conditions"
conditions:
- condition: trigger
id:
- 't4'
- 't5'
- 't6'
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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ crossover_lights_switch }}"
- alias: "Safe Guard when HA restarts"
conditions:
- condition: trigger
id: 't15'
sequence:
- alias: "Check automation and preform the correct action"
if:
- alias: "Check if the motion trigger is on"
condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
then:
- alias: "We need something here for the IF to continue"
delay:
seconds: 1
- choose:
- alias: "Check if the by-pass auto off is enabled and by-pass is ON"
conditions:
- condition: template
value_template: "{{ ('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 motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- choose:
- alias: "Check if the by-pass auto off is enabled and by-pass is ON"
conditions:
- condition: template
value_template: "{{ ('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 motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
- alias: "Wait the number of minutes set in the night lights time delay"
delay:
minutes: !input night_time_delay
- 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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
- stop: "Stop the automation"
- choose:
- alias: "Set the transition for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_night_light_control) and ('use_brightness' not in include_night_light_control) and ('use_colour_temperature' not in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
transition: "{{ night_transition_on_value }}"
- alias: "Set the transition and brightness for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_night_light_control) and ('use_brightness' in include_night_light_control) and ('use_colour_temperature' not in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
transition: "{{ night_transition_on_value }}"
brightness_pct: "{{ night_brightness_value }}"
- alias: "Set the transition and colour temperature for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_night_light_control) and ('use_brightness' not in include_night_light_control) and ('use_colour_temperature' in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
transition: "{{ night_transition_on_value }}"
kelvin: "{{ night_temperature_value }}"
- alias: "Set the transition, brightness and colour temperature for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_night_light_control) and ('use_brightness' in include_night_light_control) and ('use_colour_temperature' in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
transition: "{{ night_transition_on_value }}"
brightness_pct: "{{ night_brightness_value }}"
kelvin: "{{ night_temperature_value }}"
- alias: "Set the brightness for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_night_light_control) and ('use_brightness' in include_night_light_control) and ('use_colour_temperature' not in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
brightness_pct: "{{ night_brightness_value }}"
- alias: "Set the colour temperature for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_night_light_control) and ('use_brightness' not in include_night_light_control) and ('use_colour_temperature' in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
kelvin: "{{ night_temperature_value }}"
- alias: "Set the brightness and colour temperature for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_night_light_control) and ('use_brightness' in include_night_light_control) and ('use_colour_temperature' in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
data:
brightness_pct: "{{ night_brightness_value }}"
kelvin: "{{ night_temperature_value }}"
- alias: "Set the default for the night lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_night_light_control) and ('use_brightness' not in include_night_light_control) and ('use_colour_temperature' not in include_night_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ night_light_entities_off }}"
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_night_light_control }}"
sequence:
- alias: "Turn on the scenes"
service: scene.turn_on
target:
entity_id: "{{ night_scene_entities }}"
data:
transition: "{{ night_transition_on_value }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_night_light_control }}"
sequence:
- alias: "Turn on the scenes"
service: scene.turn_on
target:
entity_id: "{{ night_scene_entities }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ night_switch_entities_off }}"
- choose:
- alias: "By-pass is enabled & check by-pass option - turn lights on"
conditions:
- condition: trigger
id: 't7_on'
sequence:
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "Check if the trigger is on and wait for it to go off"
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
sequence:
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes set in the night lights time delay"
delay:
minutes: !input night_time_delay
- 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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ night_switch_entities }}"
default:
- choose:
- alias: "By-pass is turned on & check by-pass option - turn lights off"
conditions:
- condition: trigger
id: 't7_off'
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "By-pass is turned on & check by-pass option - Keep the current lights state"
conditions:
- condition: trigger
id: 't7_stop'
sequence:
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "By-pass is turned off & check if the motion trigger is off"
conditions:
- condition: trigger
id:
- 't8_on'
- 't8_off'
- 't8_stop'
- condition: state
entity_id: !input motion_trigger
match: all
state: 'off'
sequence:
- choose:
- alias: "Check all by-pass are off"
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_off
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: all
state: 'off'
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- stop: "Stop the automation"
- alias: "Motion trigger is off and check if any by-passes are on"
conditions:
- condition: or
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "By-pass is turned off & check if the motion trigger is on"
conditions:
- condition: trigger
id:
- 't8_on'
- 't8_off'
- 't8_stop'
- condition: state
entity_id: !input motion_trigger
match: any
state: 'on'
sequence:
- choose:
- alias: "Check all by-pass are off and check conditions if enabled "
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_off
match: all
state: 'off'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: all
state: 'off'
- condition: or
conditions:
- "{{ (include_sun == 'sun_enabled') and (state_attr('sun.sun','elevation') >= sun_elevation | float(90)) }}"
- "{{ (include_ambient == 'ambient_enabled') and (ambient_light_options == 'ambient_light_option_disabled') and (states[ambient_light_sensor].state | int > ambient_light_value | int) }}"
- "{{ (include_ambient == 'ambient_enabled') and (ambient_light_options == 'ambient_light_option_enabled') and (states[ambient_light_sensor].state | int > ambient_light_value | int) and (expand(light_switch.entity_id) | selectattr('state', '==', 'off') | list | count > 0) }}"
- condition: and
conditions:
- condition: time
after: !input before_time
before: !input after_time
- "{{ include_time == 'time_enabled' }}"
sequence:
- alias: "Wait the number of minutes set in the by-pass time delay"
delay:
minutes: !input bypass_time_delay
- 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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- stop: "Stop the automation"
- alias: "Motion trigger is on and check if any by-passes are on"
conditions:
- condition: or
conditions:
- condition: state
entity_id: !input motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- stop: "Stop the automation"
- alias: "Sun, Ambient Light Sensor & time above setting to turn off"
conditions:
- condition: trigger
id:
- 't9'
- 't10'
- 't11'
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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- stop: "Stop the automation"
- alias: "Turn off night lights when trigger by end night lights conditions"
conditions:
- condition: trigger
id:
- 't12'
- 't13'
- 't14'
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_transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ night_transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ crossover_night_lights_switch }}"
- alias: "Safe Guard when HA restarts"
conditions:
- condition: trigger
id: 't15'
sequence:
- alias: "Check automation and preform the correct action"
if:
- alias: "Check if the motion trigger is on"
condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
then:
- alias: "We need something here for the IF to continue"
delay:
seconds: 1
- choose:
- alias: "Check if the by-pass auto off is enabled and by-pass is ON"
conditions:
- condition: template
value_template: "{{ ('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: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- choose:
- alias: "Check if the by-pass auto off is enabled and by-pass is ON"
conditions:
- condition: template
value_template: "{{ ('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 motion_bypass_lights_on
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_off
match: any
state: 'on'
- condition: state
entity_id: !input motion_bypass_lights_stop
match: any
state: 'on'
sequence:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
- alias: "Wait the number of minutes set in the normal lights time delay"
delay:
minutes: !input time_delay
- 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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- alias: "Turn off the switches"
service: switch.turn_off
target:
entity_id: "{{ switch_entities }}"
- stop: "Stop the automation"
- alias: "Parallel Actions for dynamic lighting"
parallel:
- sequence:
- alias: "Check if the dynamic lighting is enabled"
condition: and
conditions:
- condition: template
value_template: "{{'enable_dynamic_lighting_brightness' in include_dynamic_lighting}}"
- alias: "Dynamic Lighting Control"
repeat:
until: "{{ expand(light_switch.entity_id) | selectattr('state', '==', 'off') | list | count > 0 }}"
sequence:
- choose:
- alias: "Set the transition and dynamic lighting brightness for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('enable_dynamic_lighting_brightness' in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ transition_on_value }}"
brightness_pct: >
{% set lux = states(dynamic_lighting_lux_sensor) | float %}
{% set slop = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux - dynamic_lighting_min_lux) %}
{% set ak = (( slop * dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness %}
{% if lux <= dynamic_lighting_min_lux %}
{{ dynamic_lighting_max_brightness }}
{% elif lux >= dynamic_lighting_max_lux %}
{{ dynamic_lighting_min_brightness }}
{% else %}
{{ ((slop * lux) + ak) | round(1) }}
{% endif %}
- alias: "Dynamic lighting heartbeat"
delay:
minutes: !input dynamic_lighting_heartbeat
- alias: "Set the transition, dynamic lighting brightness and colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('enable_dynamic_lighting_brightness' in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities }}"
data:
transition: "{{ transition_on_value }}"
brightness_pct: >
{% set lux = states(dynamic_lighting_lux_sensor) | float %}
{% set slop = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux - dynamic_lighting_min_lux) %}
{% set ak = (( slop * dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness %}
{% if lux <= dynamic_lighting_min_lux %}
{{ dynamic_lighting_max_brightness }}
{% elif lux >= dynamic_lighting_max_lux %}
{{ dynamic_lighting_min_brightness }}
{% else %}
{{ ((slop * lux) + ak) | round(1) }}
{% endif %}
kelvin: "{{temperature_value}}"
- alias: "Dynamic lighting heartbeat"
delay:
minutes: !input dynamic_lighting_heartbeat
- alias: "Set the dynamic lighting brightness for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('enable_dynamic_lighting_brightness' in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities }}"
data:
brightness_pct: >
{% set lux = states(dynamic_lighting_lux_sensor) | float %}
{% set slop = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux - dynamic_lighting_min_lux) %}
{% set ak = (( slop * dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness %}
{% if lux <= dynamic_lighting_min_lux %}
{{ dynamic_lighting_max_brightness }}
{% elif lux >= dynamic_lighting_max_lux %}
{{ dynamic_lighting_min_brightness }}
{% else %}
{{ ((slop * lux) + ak) | round(1) }}
{% endif %}
- alias: "Dynamic lighting heartbeat"
delay:
minutes: !input dynamic_lighting_heartbeat
- alias: "Set the dynamic lighting brightness and colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('enable_dynamic_lighting_brightness' in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities }}"
data:
brightness_pct: >
{% set lux = states(dynamic_lighting_lux_sensor) | float %}
{% set slop = (dynamic_lighting_min_brightness - dynamic_lighting_max_brightness) / (dynamic_lighting_max_lux - dynamic_lighting_min_lux) %}
{% set ak = (( slop * dynamic_lighting_min_lux) * -1) + dynamic_lighting_max_brightness %}
{% if lux <= dynamic_lighting_min_lux %}
{{ dynamic_lighting_max_brightness }}
{% elif lux >= dynamic_lighting_max_lux %}
{{ dynamic_lighting_min_brightness }}
{% else %}
{{ ((slop * lux) + ak) | round(1) }}
{% endif %}
kelvin: "{{temperature_value}}"
- alias: "Dynamic lighting heartbeat"
delay:
minutes: !input dynamic_lighting_heartbeat
- stop: "Stop the automation"
- sequence:
- choose:
- alias: "Set the transition for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('use_brightness' not in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
transition: "{{ transition_on_value }}"
- alias: "Set the transition and brightness for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('use_brightness' in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
transition: "{{ transition_on_value }}"
brightness_pct: "{{ brightness_value }}"
- alias: "Set the transition and colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('use_brightness' not in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
transition: "{{ transition_on_value }}"
kelvin: "{{temperature_value}}"
- alias: "Set the transition, brightness and colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' in include_light_control) and ('use_brightness' in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
transition: "{{ transition_on_value }}"
brightness_pct: "{{ brightness_value }}"
kelvin: "{{temperature_value}}"
- alias: "Set the brightness for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('use_brightness' in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
brightness_pct: "{{ brightness_value }}"
- alias: "Set the colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('use_brightness' not in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
kelvin: "{{temperature_value}}"
- alias: "Set the brightness and colour temperature for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('use_brightness' in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
data:
brightness_pct: "{{ brightness_value }}"
kelvin: "{{temperature_value}}"
- alias: "Set the default for the normal lights switch"
conditions:
- condition: template
value_template: "{{ ('use_transition' not in include_light_control) and ('use_brightness' not in include_light_control) and ('enable_dynamic_lighting_brightness' not in include_dynamic_lighting) and ('use_colour_temperature' not in include_light_control) }}"
sequence:
- service: light.turn_on
target:
entity_id: "{{ light_entities_off }}"
- choose:
- alias: "If transition is selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' in include_light_control }}"
sequence:
- alias: "Turn on the scenes"
service: scene.turn_on
target:
entity_id: "{{ scene_entities }}"
data:
transition: "{{ transition_on_value }}"
- alias: "If transition is not selected"
conditions:
- condition: template
value_template: "{{ 'use_transition' not in include_light_control }}"
sequence:
- alias: "Turn on the scenes"
service: scene.turn_on
target:
entity_id: "{{ scene_entities }}"
- alias: "Turn on the switches"
service: switch.turn_on
target:
entity_id: "{{ switch_entities_off }}"
- choose:
- alias: "By-pass is enabled & check by-pass option - turn lights on"
conditions:
- condition: trigger
id: 't7_on'
sequence:
- alias: "Check by-pass settings and preform the correct action"
if:
- alias: "Check if the by-pass auto off is enabled"
condition: template
value_template: "{{ ('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) }}"
then:
- alias: "Wait the number of minutes set in the by-pass auto off time delay"
delay:
minutes: !input bypass_auto_off_delay
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_on
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_off
- 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 by-pass"
service: homeassistant.turn_off
entity_id: !input motion_bypass_lights_stop
- stop: "Stop the automation"
else:
- stop: "Stop the automation"
- choose:
- alias: "Check if the trigger is on and wait for it to go off"
conditions:
- condition: state
entity_id: !input motion_trigger
state: 'on'
match: any
sequence:
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes set in the normal lights time delay"
delay:
minutes: !input time_delay
- 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: "{{ transition_off_value }}"
- alias: "Turn off the scenes"
service: scene.turn_on
entity_id: !input end_scenes
data:
transition: "{{ transition_off_value }}"
- 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 scenes"
service: scene.turn_on
entity_id: !input end_scenes
- 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