Created
June 30, 2021 07:41
-
-
Save WizBangCrash/6a49fe213e703105bd70c3b1f9856c96 to your computer and use it in GitHub Desktop.
Control the a set of main lights and a set of ambient lights based on the state of the TV, the room occupancy and the illumination levels
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
# | |
# Determine what to do with the lounge lights based on TV, illumination, | |
# occupancy and the light switch | |
# | |
# | |
blueprint: | |
name: Media Room Lighting Control | |
description: > | |
Control the a set of main lights and a set of ambient lights | |
based on the state of the TV, the room occupancy and the illumination levels | |
domain: automation | |
input: | |
main_light: | |
name: Main Light | |
description: "The main room light" | |
selector: | |
entity: | |
domain: light | |
main_light_on_attributes: | |
name: Main Light On Attributes | |
description: "Set the attributes to use when turning on the light" | |
selector: | |
object: | |
default: | |
transition: 5 | |
main_light_off_attributes: | |
name: Main Light Off Attributes | |
description: "Set the attributes to use when turning off the light" | |
selector: | |
object: | |
default: | |
transition: 5 | |
ambient_lights: | |
name: Ambient lighting | |
description: "The lights to use when the TV is on" | |
selector: | |
target: | |
entity: | |
domain: light | |
ambient_light_on_attributes: | |
name: Ambient Light On Object | |
description: "Set the attributes to use when turning on the light" | |
selector: | |
object: | |
default: | |
rgb_color: [100, 80, 255] | |
brightness: 200 | |
ambient_light_off_attributes: | |
name: Ambient Light Off Object | |
description: "Set the attributes to use when turning off the light" | |
selector: | |
object: | |
default: | |
transition: 5 | |
occupancy_entity: | |
name: Room Occupancy Sensor | |
description: "The occupancy sensor for the room" | |
selector: | |
entity: | |
domain: binary_sensor | |
device_class: occupancy | |
illumination_entity: | |
name: Room Illuminance Sensor | |
description: "The illuminance sensor for the room" | |
selector: | |
entity: | |
domain: sensor | |
device_class: illuminance | |
media_player_entity: | |
name: Media Player | |
description: "The TV in the room" | |
selector: | |
entity: | |
domain: media_player | |
occupancy_killswitch: | |
name: Occupancy Sensor Killswitch | |
description: > | |
If the input_boolean is in the 'on' state | |
then the occupancy sensor will be disabled | |
default: "none" | |
selector: | |
entity: | |
domain: input_boolean | |
luminance_value: | |
name: Light Trigger Level | |
description: "Anything darker than this will turn on the light" | |
default: 20 | |
selector: | |
number: | |
min: 2 | |
max: 3000 | |
mode: box | |
unit_of_measurement: "lx" | |
# Variables | |
# | |
variables: | |
main_light: !input main_light | |
main_light_on_attributes: !input main_light_on_attributes | |
main_light_off_attributes: !input main_light_off_attributes | |
occupancy_entity: !input occupancy_entity | |
occupancy_killswitch: !input occupancy_killswitch | |
illumination_entity: !input illumination_entity | |
luminance_value: !input luminance_value | |
media_player_entity: !input media_player_entity | |
mode: queued | |
# Triggers | |
# | |
trigger: | |
- platform: sun | |
event: sunset | |
offset: "00:15:00" | |
- platform: state | |
entity_id: !input media_player_entity | |
to: | |
- "on" | |
- "off" | |
- platform: numeric_state | |
entity_id: !input illumination_entity | |
below: !input luminance_value | |
- platform: state | |
entity_id: !input occupancy_killswitch | |
# Conditions | |
# | |
condition: [] | |
# Actions | |
# | |
action: | |
- alias: "Ambient Lights" | |
choose: | |
- alias: "If media turned on & dark enough" | |
conditions: | |
- "{{ is_state(media_player_entity, 'on') }}" | |
- "{{ states(illumination_entity)|int <= luminance_value }}" | |
sequence: | |
- alias: "Turn on ambient lights" | |
service: light.turn_on | |
target: !input ambient_lights | |
data: !input ambient_light_on_attributes | |
- alias: "If media turned off" | |
conditions: | |
- "{{ is_state(media_player_entity, 'off') }}" | |
sequence: | |
- alias: "Turn off ambient lights" | |
service: light.turn_off | |
target: !input ambient_lights | |
data: !input ambient_light_off_attributes | |
default: [] | |
- alias: "Main Lights" | |
choose: | |
- alias: "If media turn on and killswitch off" | |
conditions: | |
- "{{ trigger.platform == 'state' and trigger.entity_id == media_player_entity and trigger.to_state.state == 'on' }}" | |
- "{{ occupancy_killswitch != 'none' and is_state(occupancy_killswitch, 'off') }}" | |
sequence: | |
- alias: "Turn off main lights" | |
service: light.turn_off | |
target: | |
entity_id: !input main_light | |
data: !input main_light_off_attributes | |
- alias: "Enable occupancy killswitch if available" | |
condition: template | |
value_template: "{{ occupancy_killswitch != 'none' and is_state(occupancy_killswitch, 'off') }}" | |
- alias: "Turn on killswitch to keep main light off" | |
service: input_boolean.turn_on | |
target: | |
entity_id: !input occupancy_killswitch | |
# - alias: "If media turned off and main light on then do nothing" | |
- alias: "If media turned off and main light off" | |
conditions: | |
- "{{ trigger.platform == 'state' and trigger.entity_id == media_player_entity and trigger.to_state.state == 'off' }}" | |
- "{{ is_state(main_light, 'off') }}" | |
sequence: | |
- alias: "Turn off occupancy killswitch" | |
choose: | |
- alias: "Only if killswitch exists" | |
conditions: | |
- "{{ occupancy_killswitch != 'none' and is_state(occupancy_killswitch, 'on') }}" | |
sequence: | |
service: input_boolean.turn_off | |
target: | |
entity_id: !input occupancy_killswitch | |
default: [] | |
- alias: "If occupied and dark enough" | |
condition: template | |
value_template: "{{ is_state(occupancy_entity, 'on') and states(illumination_entity)|int <= luminance_value }}" | |
- alias: "Turn on the main light" | |
service: light.turn_on | |
target: | |
entity_id: !input main_light | |
data: !input main_light_on_attributes | |
default: [] | |
- alias: "Occupancy killswitch" | |
condition: template | |
value_template: "{{ trigger.platform == 'state' and trigger.entity_id == occupancy_killswitch }}" | |
- alias: "Determine state of media player" | |
variables: | |
killswitch_state: "{{ 'off' if is_state(media_player_entity, 'off') else 'on' }}" | |
- alias: "Set killswitch to media player state" | |
service: input_boolean.turn_{{killswitch_state}} | |
target: | |
entity_id: !input occupancy_killswitch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment