Files
Home-Assistant-Configs/blueprints/automation/Twanne/the_everything_light.yaml

431 lines
15 KiB
YAML

blueprint:
name: The Everything Light
author: AntonH
description: "**Version 2.5**\nThe Everything Light: select any trigger and turn
on your light in multiple ways:\n - just turn the light on in it's default state\n
\ - turn it on with a set brightness, color and/or temperature value\n - turn
it on dynamically with a brightness value that changes according to an ambient
light sensor\n\nThe blueprint also allows you to turn the light off again in 3
ways:\n - at a set time\n - with 1 or more triggers\n - with a staircase function
(turn off the light after a set time has passed)\n\n Conditions can be set to
prevent both turn on and turn off functions.\n\n**The dynamic lighting logic is
based of the Smart Lux Dimmer Blueprint:**\n - [Find it on the Home Assistant
Community forums:](https://community.home-assistant.io/t/smart-lux-dimmer-adjust-light-brightness-depending-on-light-sensor-value/403646)\n
\ - [See the source on Github:](https://gist.github.com/Twanne/02dfb154084a8b9bf927c29160df4af3)\n"
source_url: https://gist.github.com/Twanne/8003f5d00da69ae3260e9a69864e5ff5
domain: automation
input:
triggers:
name: Triggers
description: Choose what turns your light on
default: []
selector:
trigger: {}
run_conditions:
name: Conditions
description: Only turn the light on when these conditions are met.
default:
- condition: time
alias: Run only at these times ( - Remove me if not needed - )
selector:
condition: {}
target_light:
name: Target lights
description: "Which lights do you want to control?\n\nSupported entity types
are:\n - light\n - switch (Only **DEFAULT** & **TOGGLE** modes are supported)\n"
default: []
selector:
target:
entity:
- domain:
- light
- switch
mode:
name: Mode
description: 'How do you want the light to turn on?
- **DEFAULT MODE:**
The light will turn on at it''s default setting.
- **TOGGLE MODE:**
Toggle the light.
- **FIXED MODE: **
The light will turn on at a set brightness percentage, optionally color or
temperature can be set.
- **DYNAMIC MODE**
The light will be assigned a brightness value based on the value of a ambient
light sensor, optionally color or temperature can be set.
'
default: default
selector:
select:
mode: dropdown
options:
- label: DEFAULT MODE
value: default
- label: TOGGLE
value: toggle
- label: FIXED MODE
value: fixed
- label: DYNAMIC MODE
value: dynamic
multiple: false
sort: false
custom_value: false
transition_time:
name: Transition time (FIXED & DYNAMIC MODE)
description: "The time it takes for the light to transition to the assigned
value when it's triggered.\n\nWARNING!: \n This can smoothen the transition,
but your light needs to support it.\n Leave at 0 if you don't need it or
if your light doesn't support it.\n"
default: 0
selector:
number:
min: 0.0
max: 300.0
step: 1.0
unit_of_measurement: s
mode: slider
include_color_or_temp:
name: Include color or temperature (FIXED & DYNAMIC MODE)
description: Do you want to set a color or temperature value for the light?
default: include_no_color_temp
selector:
select:
options:
- label: I don't want to set color or temperature
value: include_no_color_temp
- label: Set color
value: include_color
- label: Set temperature
value: include_temperature
multiple: false
sort: false
custom_value: false
light_color:
name: Light color (FIXED & DYNAMIC MODE)
description: Color of the light when between minimum and maximum ambient light
values.
default:
- 255
- 255
- 255
selector:
color_rgb: {}
light_temperature:
name: Light temperature (FIXED & DYNAMIC MODE)
description: Temperature of the light when between minimum and maximum ambient
light values.
default: 2000
selector:
color_temp: {}
brightness:
name: Brightness (FIXED BRIGHTNESS MODE)
description: Set the brightness value the light needs to turn on at
default: 0
selector:
number:
min: 0.0
max: 100.0
step: 1.0
mode: slider
unit_of_measurement: '%'
light_sensor_entity:
name: Light Sensor (DYNAMIC MODE)
description: Which light sensor do you want to use to measure the ambient light
value?
default:
selector:
entity:
filter:
- domain:
- sensor
device_class:
- illuminance
multiple: false
max_brightness_value:
name: Maximum ambient light value (DYNAMIC MODE)
description: Dynamically change the light so long as the ambient light stays
under this value.
default: 500
selector:
number:
min: 0.0
max: 1000.0
step: 10.0
unit_of_measurement: lx
mode: slider
min_brightness_value:
name: Minimum ambient light value (DYNAMIC MODE)
description: Dynamically change the light so long as the ambient light stays
above this value.
default: 0
selector:
number:
min: 0.0
max: 1000.0
step: 10.0
unit_of_measurement: lx
mode: slider
light_value_1:
name: Brightness at maximum light level (DYNAMIC MODE)
description: Brightness of the light at maximum ambient light.
default: 0
selector:
number:
min: 0.0
max: 100.0
step: 1.0
mode: slider
unit_of_measurement: '%'
light_value_2:
name: Brightness at minimum light level (DYNAMIC MODE)
description: Brightness of the light at minimum ambient light.
default: 100
selector:
number:
min: 0.0
max: 100.0
step: 1.0
mode: slider
unit_of_measurement: '%'
light_brightness_over_max:
name: Brightness when ambient light value over max (DYNAMIC MODE)
description: Brightness of the light when the ambient light is higher than the
set maximum value.
default: 0
selector:
number:
min: 0.0
max: 100.0
step: 1.0
mode: slider
unit_of_measurement: '%'
light_brightness_under_min:
name: Brightness when ambient light value under min (DYNAMIC MODE)
description: Brightness of the light when the ambient light is lower than the
set minimum value.
default: 100
selector:
number:
min: 0.0
max: 100.0
step: 1.0
mode: slider
unit_of_measurement: '%'
include_color_or_temp_over_under:
name: Include color or temperature values when outside range (DYNAMIC MODE)
description: 'Set a color or temperature value for the light when over maximum
or under minimum ambient light value?
*''Include values for under min and over max''* **MUST BE TRUE**
'
default: include_no_color_temp_outside_range
selector:
select:
options:
- label: I don't want to set color or temperature when outside range
value: include_no_color_temp_outside_range
- label: Set color when outside range
value: include_color_outside_range
- label: Set temperature when outside range
value: include_temp_outside_range
multiple: false
sort: false
custom_value: false
light_color_over_max:
name: Color when ambient light value over max (DYNAMIC MODE)
description: Color of the light when the ambient light is higher than the set
maximum value.
default:
- 255
- 255
- 255
selector:
color_rgb: {}
light_color_under_min:
name: Color when ambient light value under min (DYNAMIC MODE)
description: Color of the light when the ambient light is lower than the set
minimum value.
default:
- 255
- 255
- 255
selector:
color_rgb: {}
light_temp_over_max:
name: Temperature when ambient light value over max (DYNAMIC MODE)
description: Temperature of the light when the ambient light is higher than
the set maximum value.
default: 2000
selector:
color_temp: {}
light_temp_under_min:
name: Temperature when ambient light value under min (DYNAMIC MODE)
description: Temperature of the light when the ambient light is lower than the
set minimum value.
default: 2000
selector:
color_temp: {}
include_turn_off:
name: Include light turn off function
description: 'Select if the light needs to turn back off again and how you want
to do it.
(Multiple options are possible)
- **TURN OFF WITH TRIGGER:**
Select triggers that turn off the light.
- **STAIRCASE FUNCTION:**
Waits after the light has been turned on and then turns it back off after
the set duration.
'
default: []
selector:
select:
multiple: true
options:
- label: Turn off with trigger
value: trigger
- label: Staircase function
value: staircase
sort: false
custom_value: false
turn_off_triggers:
name: Turn off triggers
description: Triggers that turn the light off
default:
selector:
trigger: {}
staircase_duration:
name: Staircase light
description: Turns the light off again after a set time (staircase function).
default:
hours: 0
minutes: 0
seconds: 0
days: 0
selector:
duration:
enable_day: true
turn_off_conditions:
name: Turn off Conditions
description: 'Only turn the light off when these conditions are met.
(Only works with the turn off functions, DYNAMIC MODE is not impacted by this)
'
default: []
selector:
condition: {}
mode: restart
variables:
mode: !input mode
transition_time: !input transition_time
include_color_or_temp: !input include_color_or_temp
light_color: !input light_color
light_temperature: !input light_temperature
light_brightness: !input brightness
light_sensor: !input light_sensor_entity
maxB: !input max_brightness_value
minB: !input min_brightness_value
light1: !input light_value_1
light2: !input light_value_2
slope: '{{ ( light1 - light2 ) / ( maxB - minB ) }}'
constant: '{{ light1 - ( slope * maxB ) }}'
dynamic_brightness_pct: "{% if mode == \"dynamic\" %}\n {{ (( slope * states(light_sensor)|int
) + constant)|round }}\n{% else %}\n 0\n{% endif %}\n"
include_color_or_temp_over_under: !input include_color_or_temp_over_under
light_brightness_over_max: !input light_brightness_over_max
light_color_over_max: !input light_color_over_max
light_temp_over_max: !input light_temp_over_max
light_brightness_under_min: !input light_brightness_under_min
light_color_under_min: !input light_color_under_min
light_temp_under_min: !input light_temp_under_min
include_turn_off: !input include_turn_off
trigger: !input triggers
condition:
- condition: !input run_conditions
action:
- choose:
- conditions: '{{ mode == "toggle" }}'
sequence:
- service: homeassistant.toggle
target: !input target_light
- conditions: '{{ mode == "default" }}'
sequence:
- service: homeassistant.turn_on
target: !input target_light
- conditions: '{{ mode == "fixed" }}'
sequence:
- service: light.turn_on
data: "{% if include_color_or_temp == \"include_color\" %}\n {{ { \"transition\":
transition_time, \"brightness_pct\": light_brightness, \"rgb_color\": light_color
} }}\n{% elif include_color_or_temp == \"include_temperature\" %}\n {{ {
\"transition\": transition_time, \"brightness_pct\": light_brightness, \"color_temp\":
light_temperature } }}\n{% else %}\n {{ { \"transition\": transition_time,
\"brightness_pct\": light_brightness } }}\n{% endif %}\n"
target: !input target_light
- conditions: '{{ mode == "dynamic" }}'
sequence:
- service: light.turn_on
data: "{% if states(light_sensor)|int > maxB %}\n {% if include_color_or_temp_over_under
== \"include_color_outside_range\" %}\n {{ { \"transition\": transition_time,
\"brightness_pct\": light_brightness_over_max, \"rgb_color\": light_color_over_max
} }}\n {% elif include_color_or_temp_over_under == \"include_temp_outside_range\"
%}\n {{ { \"transition\": transition_time, \"brightness_pct\": light_brightness_over_max,
\"color_temp\": light_temp_over_max } }}\n {% else %}\n {{ { \"transition\":
transition_time, \"brightness_pct\": light_brightness_over_max } }}\n {%
endif %}\n{% elif states(light_sensor)|int < minB %}\n {% if include_color_or_temp_over_under
== \"include_color_outside_range\" %}\n {{ { \"transition\": transition_time,
\"brightness_pct\": light_brightness_under_min, \"rgb_color\": light_color_under_min
} }}\n {% elif include_color_or_temp_over_under == \"include_temp_outside_range\"
%}\n {{ { \"transition\": transition_time, \"brightness_pct\": light_brightness_under_min,
\"color_temp\": light_temp_under_min } }}\n {% else %}\n {{ { \"transition\":
transition_time, \"brightness_pct\": light_brightness_under_min } }}\n {%
endif %}\n{% else %}\n {% if include_color_or_temp == \"include_color\" %}\n
\ {{ { \"transition\": transition_time, \"brightness_pct\": light_brightness,
\"rgb_color\": light_color } }}\n {% elif include_color_or_temp == \"include_temperature\"
%}\n {{ { \"transition\": transition_time, \"brightness_pct\": dynamic_brightness_pct,
\"color_temp\": light_temperature } }}\n {% else %}\n {{ { \"transition\":
transition_time, \"brightness_pct\": dynamic_brightness_pct } }}\n {% endif
%}\n{% endif %}\n"
target: !input target_light
- if: !input turn_off_conditions
then:
- choose:
- conditions: '{{ "staircase" in include_turn_off }}'
sequence:
- if: '{{ "trigger" in include_turn_off }}'
then:
- wait_for_trigger: !input turn_off_triggers
timeout: !input staircase_duration
else:
- delay: !input staircase_duration
- service: homeassistant.turn_off
target: !input target_light
- conditions: '{{ "trigger" in include_turn_off and not "staircase" in include_turn_off
}}'
sequence:
- wait_for_trigger: !input turn_off_triggers
- service: homeassistant.turn_off
target: !input target_light