Last active
March 7, 2024 23:19
-
-
Save DefenestrateIT/826c0fdf0040305df5d6972f65e52a82 to your computer and use it in GitHub Desktop.
Another Light Blueprint Automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Optional_Motion Light Switch Blueprint Automation | |
description: "# Optional_Motion Light Switch Blueprint Automation V:1.3\n | |
Is my take on Light Profiles with Automations. This version has the following profiles;\n | |
- Bright - (For Day time & Events, I need to be Awake; Bright eyed & bushy tailed).\n | |
- Dimmed - (For after sunset & before sunrise when i'm (still) thinking about bed, but I will want to be able to read the Funny pages).\n | |
- Night-Light - (For bed/sleep time, & you don't want to wake everyone else up, but you still want to see in an emergency; how to get to the Fridge)\n | |
- Colour-Loop - (Was to be Aurora-Australis, but colour-loop is easier to remember).\n | |
- Circadian - (For the rest of the house at night, & to get everyone in sync @ night with you).\n | |
- Adaptive - (This works really well with a bed/sleep input_boolean).\n | |
- Random - (A Sorely missed replacement to the light effect).\n | |
- Custom - (Used for applying custom colour effects, it only has the Transition effect).\n | |
- Themed - (Theme different rooms, with different colours; with a change every so often).\n | |
- Aurora - (My Aurora-Australis that I wanted, when I first started this project).\n | |
- Flash - (works great in conjunction with Alarm Panel Automations).\n | |
- None - (Utilise this when using scenes & if you need to disable the light.turn_on Service Call).\n | |
- '.' - (for advanced users to halt this script).\n\n | |
\ - A [PREREQUISITE] of an input_select { Dropdown } with the desired above Profile/s (words) added is required { recommend one for each instance of this Automation }. \n | |
\ - A [PREREQUISITE] of another input_select { Dropdown } with the (words) 'On' 'Off' & 'Auto' ( 'Auto' if you include a motion sensor ) added is required { recommend one for each instance of this Automation }. \n | |
\ - A [OPTIONAL] binary_sensor, Device_class: motion. Is Available for the 'Auto' Switch feature { or at-least I am trying to make it so }.\n | |
\ - A [OPTIONAL] sensor, Device_class: illuminance. Is Available for activating the Adaptive Bright Profile.\n | |
\ - A [OPTIONAL] input_boolean { Toggle } is Available for Adaptive Profile Night-Light to work { recommend just the one, that will do }.\n | |
\ - A [OPTIONAL] input_boolean { Toggle } is Available for Global Automations Off { Because I like to have A global Automations off switch }.\n | |
\ - I'm assuming you already have some Lights that you wanted to add.\n\n | |
Go to Settings > Devices & Services > Helpers > Create Helper > { Dropdown } &or { Toggle }.\n | |
Replace 'Optional_Motion' in the name of this script with the name of room/area/device/entity ( E.g. Office ) light/s, this script is intended to turn on & off [for convenience]." | |
source_url: https://gist.github.com/DefenestrateIT/826c0fdf0040305df5d6972f65e52a82 | |
domain: automation | |
input: | |
target_lights: | |
name: Targeted Lights ( Required ) | |
description: "[PREREQUISITE] Lights this Script is Targeted at." | |
selector: | |
target: | |
entity: | |
domain: light | |
select_profile: | |
name: Profile input_select ( Required ) | |
description: "[PREREQUISITE] Profile 'input_select' { Dropdown } the Targeted Light/s will conform to E.g. 'Bright', 'Dimmed', 'Night-Light' ect..." | |
selector: | |
entity: | |
domain: input_select | |
multiple: false | |
pole_switch: | |
name: Light Switch ( Required ) | |
description: "[PREREQUISITE] 'On', 'Off', 'Auto' 'input_select' { Dropdown } Switch." | |
selector: | |
entity: | |
domain: input_select | |
multiple: false | |
motion_sensor: | |
name: Motion Sensor ( Optional ) | |
description: "[Optional] Motion Sensor that trigger's the lights 'Auto' option on the avove 'Light Switch' is selection." | |
default: | |
selector: | |
entity: | |
domain: binary_sensor | |
device_class: motion | |
multiple: false | |
motion_cleared: | |
name: Motion Cleared delay Time | |
description: The Clear Delay Time ( minutes ). | |
default: 15 | |
selector: | |
number: | |
min: 0.0 | |
max: 99.0 | |
mode: slider | |
step: 1.0 | |
lux_sensor: | |
name: Illuminance Sensor ( Optional ) | |
description: "[Optional] Illuminance (lux) Sensor that trigger's the 'Adaptive' - 'Profile' selection between 'Bright' & 'Dimmed'." | |
default: | |
selector: | |
entity: | |
domain: sensor | |
device_class: illuminance | |
multiple: false | |
lux_value: | |
name: Illuminance value | |
description: Illuminance triggering Bright setting for - Adaptive - Profile. | |
default: 50 | |
selector: | |
number: | |
min: 1.0 | |
max: 1000.0 | |
mode: slider | |
step: 10.0 | |
adaptive_input_switch: | |
name: Adaptive - Profile - input_boolean ( Optional ) | |
description: "[OPTIONAL] Adaptive Profile Night-Light 'input_boolean' { Toggle } Switch, is used to switch the Night-Light profile on like a sleep/bed-time switch." | |
default: | |
selector: | |
entity: | |
domain: input_boolean | |
multiple: false | |
automations_off: | |
name: Automations Off ( Optional ) | |
description: "[OPTIONAL] Because I like to have A global Automations off, Requires A 'input_boolean' { Toggle } Switch." | |
default: | |
selector: | |
entity: | |
domain: input_boolean | |
multiple: false | |
sun_before_offset: | |
name: Sunrise - Offset | |
description: Offset the sunrise time. | |
default: "1:00:00" | |
selector: | |
time: {} | |
sun_after_offset: | |
name: Sunset - Offset | |
description: Offset the sunset time. | |
default: "-1:00:00" | |
selector: | |
time: {} | |
bed_time: | |
name: Circadian - Profile - Bed Time | |
description: The Circadian Profile Night-Light Time, is used as a time to transition to Night Light. | |
default: "22:30:00" | |
selector: | |
time: {} | |
wake_up_time: | |
name: Circadian - Profile - Wake Up Time | |
description: The Circadian Profile Wake Up Time, is used as a time to transition to Dimmed or Bright Light; depending on Sunrise time. | |
default: "6:30:00" | |
selector: | |
time: {} | |
transition_on: | |
name: Turn On Light Transition Time | |
description: The Light.Turn_On Transition Time, for when a Light is off & is being turned on. | |
default: 0 | |
selector: | |
number: | |
min: 0.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
transition_off: | |
name: Turn Off Light Transition Time | |
description: The Light.Turn_Off Transition Time. | |
default: 4 | |
selector: | |
number: | |
min: 0.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
transition_change: | |
name: Change Light Transition Time | |
description: The Light.Turn_On Transition Time, is used when the lights are already on & the profile is being changed. | |
default: 8 | |
selector: | |
number: | |
min: 0.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
transition_override: | |
name: Lights switch instantly | |
description: The Lights switch instantly (transition) when using the Switch { dropdown } (mainly for testing). | |
default: false | |
selector: | |
boolean: {} | |
aurora_transition: | |
name: Aurora - Profile - Transition Time | |
description: The Colour Loop Profile Light.Turn_On Transition Time between colour changes. | |
default: 16 | |
selector: | |
number: | |
min: 1.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
loop_transition: | |
name: Colour Loop - Profile - Transition Time | |
description: The Colour Loop Profile Light.Turn_On Transition Time between colour changes. | |
default: 2 | |
selector: | |
number: | |
min: 1.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
hue_gain: | |
name: Colour Loop - Profile - Hue Gain | |
description: The Colour Loop Hue Gain, or how much colour changes between repeat loops (recomend using A number that 360 can be divided by, to keep cycles uniform). | |
default: 30 | |
selector: | |
number: | |
min: 2.0 | |
max: 120.0 | |
mode: slider | |
step: 1.0 | |
flash_repeat: | |
name: Flash - Profile - Repeat Time | |
description: The Light.Turn_On Transition Time between Flashes (Not as good as i would like but uses the Flash effect to protect lights). | |
default: 2 | |
selector: | |
number: | |
min: 2.0 | |
max: 300.0 | |
mode: slider | |
step: 1.0 | |
bright_colour_temp: | |
name: Bright - Profile - Colour Temperature | |
description: The Bright Profile light Colour-Temperature. | |
default: 153 | |
selector: | |
color_temp: {} | |
bright_brightness: | |
name: Bright - Profile - brightness | |
description: The Bright Profile light brightness. | |
default: 255 | |
selector: | |
number: | |
min: 0.0 | |
max: 255.0 | |
mode: slider | |
step: 1.0 | |
dimmed_colour_temp: | |
name: Dimmed - Profile - Colour Temperature | |
description: The Dimmed Profile light Colour-Temperature. | |
default: 400 | |
selector: | |
color_temp: {} | |
dimmed_brightness: | |
name: Dimmed - Profile - Brightness | |
description: The Dimmed Profile light brightness. | |
default: 175 | |
selector: | |
number: | |
min: 0.0 | |
max: 255.0 | |
mode: slider | |
step: 1.0 | |
sleep_colour_temp: | |
name: Night Light - Profile - Colour Temperature | |
description: The Night Light Profile light Colour-Temperature. | |
default: 500 | |
selector: | |
color_temp: {} | |
sleep_brightness: | |
name: Night Light - Profile - Brightness | |
description: The Night Light Profile light brightness. | |
default: 25 | |
selector: | |
number: | |
min: 0.0 | |
max: 255.0 | |
mode: slider | |
step: 1.0 | |
variables: | |
version: Hello World | |
hue_gain: !input hue_gain | |
target: !input target_lights | |
transition_on: !input transition_on | |
transition_off: !input transition_off | |
automations_off: !input automations_off | |
transition_change: !input transition_change | |
transition_override: !input transition_override | |
select_profile: !input select_profile | |
entities: > | |
{%- set ns = namespace(ret=[]) %} | |
{%- for key in ['device_id', 'area_id', 'entity_id'] %} | |
{%- set items = target.get(key, [] ) %} | |
{%- if items %} {#@petroUlegend#} | |
{%- set items = [ items ] if items is string else items %} | |
{%- set filt = key.split('_') | first %} | |
{%- set items = items if filt == 'entity' else items | map(filt ~ '_entities') | sum ( start = [] ) %} | |
{%- set ns.ret = ns.ret + [ items ] %} | |
{%- endif %} | |
{%- endfor %} | |
{{ ns.ret | sum(start=[]) }} | |
expanded: "{{ [] if target.entity_id is undefined else expand ( target.entity_id ) | map ( attribute = 'entity_id' ) | list }}" | |
filtered: "{{ entities | select( 'search' , '^light' ) | list }}" | |
lights: "{{ filtered + expanded }}" | |
lights_on: "{{ lights | select('is_state', 'on') | list }}" | |
lights_test: "{{ lights_on | count > 0 }}" | |
transitions: "{{ transition_change if lights_test else transition_on }}" | |
trigger_variables: | |
lux_value: !input lux_value | |
lux_sensor: !input lux_sensor | |
motion_sensor: !input motion_sensor | |
adaptive_input_switch: !input adaptive_input_switch | |
transition: "{{ 0 if transition_override and is_state ( trigger.id , 'Input-Change' ) else transitions }}" | |
transition_off: "{{ 0 if transition_override and is_state ( trigger.id , 'Input-Change' ) else transition_off }}" | |
trigger: | |
- platform: template | |
value_template: "{{ expand ( lights_on ) | selectattr('attributes.color_mode','not','color_temp') }}" | |
id: Change-Profile | |
- platform: homeassistant | |
event: start | |
- platform: template | |
value_template: "{{ states ( lux_sensor ) | int > lux_value }}" | |
- platform: template | |
value_template: "{{ states ( lux_sensor ) | int < lux_value }}" | |
- platform: template | |
value_template: "{{ is_state ( adaptive_input_switch , 'on' ) }}" | |
id: Input-Change | |
- platform: template | |
value_template: "{{ is_state ( adaptive_input_switch , 'off' ) }}" | |
id: Input-Change | |
- platform: template | |
value_template: "{{ is_state ( motion_sensor , 'on' ) }}" | |
id: Motion-Detected | |
- platform: sun | |
event: sunrise | |
offset: !input sun_after_offset | |
id: Sunrise | |
- platform: sun | |
event: sunset | |
offset: !input sun_before_offset | |
id: Sunset | |
- platform: state | |
entity_id: | |
- !input pole_switch | |
- !input select_profile | |
id: Input-Change | |
- platform: template | |
value_template: "{{ is_state ( motion_sensor , 'off' ) }}" | |
id: Motion-Cleared | |
for: | |
hours: 0 | |
minutes: !input motion_cleared | |
seconds: 0 | |
condition: | |
- condition: template | |
value_template: "{{ true if automations_off == none else is_state ( automations_off , 'off' ) }}" | |
- condition: not | |
conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: . | |
- condition: template | |
value_template: "{{ is_state ( select_profile , none ) }}" | |
action: | |
- variables: | |
transition: "{{ transition | float ( default = 0 ) }}" | |
transition_off: "{{ transition_off | float ( default = 0 ) }}" | |
- choose: | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: !input pole_switch | |
state: "Off" | |
- condition: and | |
conditions: | |
- condition: state | |
entity_id: !input pole_switch | |
state: Auto | |
- condition: trigger | |
id: Motion-Cleared | |
sequence: | |
- service: light.turn_off | |
data: | |
transition: "{{ transition_off }}" | |
target: !input target_lights | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: !input pole_switch | |
state: "On" | |
- condition: and | |
conditions: | |
- condition: state | |
entity_id: !input pole_switch | |
state: Auto | |
- condition: template | |
value_template: "{{ lights_test }}" | |
- condition: and | |
conditions: | |
- condition: trigger | |
id: Input-Change | |
- condition: template | |
value_template: "{{ lights_test }}" | |
- condition: and | |
conditions: | |
- condition: state | |
entity_id: !input pole_switch | |
state: Auto | |
- condition: trigger | |
id: Motion-Detected | |
sequence: | |
- choose: | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: input_select.office_light_profile | |
state: . | |
- condition: state | |
entity_id: input_select.office_light_profile | |
state: None | |
- condition: template | |
value_template: "{{ is_state ( select_profile , none ) }}" | |
sequence: [] | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Custom | |
sequence: | |
- service: light.turn_on | |
data: | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Bright | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input bright_colour_temp | |
brightness: !input bright_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Dimmed | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input dimmed_colour_temp | |
brightness: !input dimmed_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Night-Light | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input sleep_colour_temp | |
brightness: !input sleep_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Random | |
- condition: state | |
entity_id: !input select_profile | |
state: Aurora | |
sequence: | |
- variables: | |
light_bulb: "{{ lights | reject ( 'in' , integration_entities ( 'group' ) ) | list }}" | |
- repeat: | |
for_each: "{{ light_bulb }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
hs_color: | |
- "{{ range ( 360 ) | random }}" | |
- "{{ range ( 80 , 100 ) | random }}" | |
brightness_pct: 100 | |
transition: "{{ transition }}" | |
target: | |
entity_id: "{{ repeat.item }}" | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: "{{ transition }}" | |
milliseconds: 0 | |
- repeat: | |
sequence: | |
- repeat: | |
for_each: "{{ light_bulb }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
hs_color: | |
- "{{ range ( 360 ) | random }}" | |
- "{{ range ( 80 , 100 ) | random }}" | |
brightness_pct: 100 | |
transition: !input aurora_transition | |
target: | |
entity_id: "{{ repeat.item }}" | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: !input aurora_transition | |
milliseconds: 0 | |
while: | |
- condition: template | |
value_template: "{{ lights_test }}" | |
- condition: state | |
entity_id: !input select_profile | |
state: Aurora | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Colour-Loop | |
- condition: state | |
entity_id: !input select_profile | |
state: Themed | |
sequence: | |
- service: light.turn_on | |
data: | |
hs_color: | |
- "{{ range ( 360 ) | random }}" | |
- "{{ range ( 75 , 100 ) | random }}" | |
brightness_pct: 100 | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: "{{ transition }}" | |
milliseconds: 0 | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ lights_test }}" | |
- condition: state | |
entity_id: !input select_profile | |
state: Colour-Loop | |
sequence: | |
- service: light.turn_on | |
data: | |
hs_color: | |
- "{{ ( hue_gain + ( repeat.index * hue_gain ) ) % 360 }}" | |
- 100 | |
brightness_pct: 100 | |
transition: !input loop_transition | |
target: !input target_lights | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: !input loop_transition | |
milliseconds: 0 | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Flash | |
sequence: | |
- service: light.turn_on | |
data: | |
transition: !input transition_on | |
target: !input target_lights | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ lights_test }}" | |
- condition: state | |
entity_id: !input select_profile | |
state: Flash | |
sequence: | |
- service: light.turn_on | |
data: | |
flash: short | |
target: !input target_lights | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: !input flash_repeat | |
milliseconds: 0 | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Circadian | |
sequence: | |
- choose: | |
- conditions: | |
- condition: time | |
after: !input bed_time | |
before: !input wake_up_time | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input sleep_colour_temp | |
brightness: !input sleep_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: sun | |
before: sunset | |
after: sunrise | |
before_offset: !input sun_before_offset | |
after_offset: !input sun_after_offset | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input bright_colour_temp | |
brightness: !input bright_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
default: | |
- service: light.turn_on | |
data: | |
color_temp: !input dimmed_colour_temp | |
brightness: !input dimmed_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: state | |
entity_id: !input select_profile | |
state: Adaptive | |
sequence: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ false if adaptive_input_switch is none or is_state ( adaptive_input_switch , 'off' ) else true }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input sleep_colour_temp | |
brightness: !input sleep_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: sun | |
before: sunset | |
after: sunrise | |
before_offset: !input sun_before_offset | |
after_offset: !input sun_after_offset | |
- condition: template | |
value_template: "{{ states ( lux_sensor ) | int > lux_value }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
color_temp: !input bright_colour_temp | |
brightness: !input bright_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
default: | |
- service: light.turn_on | |
data: | |
color_temp: !input dimmed_colour_temp | |
brightness: !input dimmed_brightness | |
transition: "{{ transition }}" | |
target: !input target_lights | |
default: | |
- service: light.turn_on | |
data: {} | |
target: !input target_lights | |
mode: restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
latest version?