Skip to content

Instantly share code, notes, and snippets.

@DefenestrateIT
Last active December 11, 2022 02:12
Show Gist options
  • Save DefenestrateIT/444d1ceca1cf0eaa68b731b39caa154f to your computer and use it in GitHub Desktop.
Save DefenestrateIT/444d1ceca1cf0eaa68b731b39caa154f to your computer and use it in GitHub Desktop.
blueprint:
name: Another [HAssNic's] Trigger Automation
domain: automation
source_url: https://gist.github.com/DefenestrateIT/444d1ceca1cf0eaa68b731b39caa154f
description: >
#Another [HAssNic's] Trigger Automation V.1
This blueprint will pass the following variables to sub-scripts:
v_target: - The target selected for the Lights
v_lights: - The entity id's for the lights selected
v_profile: - The Profile currently selected
v_lights_on: - The entity id's for Light's current on
v_light_switch: - The Pole-Switch currently selection
v_trans_off: - true or false designed to override to transition: 0
input:
input_area_id:
name: Area
description: "The 'area this Script is Targeted at (designed to make this script quick & easy to set up)."
default:
selector:
area:
light_automation:
name: lights
description: Activate Lights Automations
default: true
selector:
boolean: {}
override_trans:
name: Lights switch instantly
description: The Lights switch instantly (transition) when using the Switch { dropdown } (mainly for testing).
default: false
selector:
boolean: {}
input_light_switch:
name: Light Switch
description: "Looking for A 'input_select' { Dropdown } containing 'On', 'Off', 'Auto'."
selector:
entity:
domain: input_select
multiple: false
input_light_profile:
name: Profile input_select
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
lights_on_suffix:
name: lights on sciprt suffix
description: if you use {hAssNic's] system the suffix appendid to the script effect name E.g. script.[bright]_hassnics_light_effect_profile
default: _hassnics_light_effect_profile
selector:
text:
lights_on_script:
name: Lights Turn On Script
description: "Script to turn Lights on."
default:
selector:
entity:
domain: script
lights_off_script:
name: Lights Turn Off Script
description: "Script to turn Lights off."
default:
selector:
entity:
domain: script
target_lights:
name: Targeted Lights
description: "override Lights this Script is Targeted at."
default:
selector:
target:
entity:
domain: light
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
sunet_time:
name: Sunset - Offset - time
description: Offset the sunset time.
default: "-1:00:00"
selector:
time: {}
sunet_angle:
name: Sunset - Offset - angle
description: Offset the sunset time.
default: 0
selector:
number:
min: -12.0
max: 12.0
mode: slider
step: 0.1
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: {}
input_inbed_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
sunrise_angle:
name: Sunrise - Offset - angle
description: Offset the sunrise time.
default: 0
selector:
number:
min: -12.0
max: 12.0
mode: slider
step: 1.0
sunrise_time:
name: Sunrise - Offset - time
description: Offset the sunrise time.
default: "-1:00:00"
selector:
time: {}
climate_automation:
name: Climate Control
description: Activate Lights Automations
default: false
selector:
boolean: {}
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
variables:
lights_on_suffix: !input lights_on_suffix
input_inbed_switch: !input input_inbed_switch
input_light_switch: !input input_light_switch
input_light_profile: !input input_light_profile
version: Hello World
target: !input target_lights
light: !input light_automation
climate: !input climate_automation
override_trans: !input override_trans
automations_off: !input automations_off
lights_on_script: !input lights_on_script
lights_off_script: !input lights_off_script
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 }}"
trans_off: "{{ true if trans_off and is_state ( trigger.id , 'Input-Change' ) else false }}"
filtered: "{{ entities | select( 'search' , '^light' ) | list }}"
suffix: "{{ '' if lights_on_suffix | lower == 'none' or lights_on_suffix == none else lights_on_suffix }}"
light_profile: "{{ states ( input_light_profile ) | lower | string }}"
light_script: "{{ 'script.' + light_profile + suffix }}"
lights_on: "{{ lights | select('is_state', 'on') | list }}"
light_switch: "{{ states ( input_light_switch ) | lower }}"
lights_test: "{{ lights_on | count > 0 }}"
lights: "{{ filtered + expanded }}"
trigger_variables:
lux_value: !input lux_value
lux_sensor: !input lux_sensor
motion_sensor: !input motion_sensor
trigger:
- 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 ( input_inbed_switch , 'on' ) }}"
id: Input-Change
- platform: template
value_template: "{{ is_state ( input_inbed_switch , 'off' ) }}"
id: Input-Change
- platform: template
value_template: "{{ is_state ( motion_sensor , 'on' ) }}"
id: Motion-Detected
- platform: sun
event: sunrise
offset: !input sunet_time
id: Sunrise
- platform: sun
event: sunset
offset: !input sunrise_time
id: Sunset
- platform: state
entity_id:
- !input input_light_switch
- !input input_light_profile
id: Input-Change
- platform: template
value_template: "{{ is_state ( motion_sensor , 'off' ) }}"
id: Motion
- 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 input_light_profile
state: .
- condition: template
value_template: "{{ is_state ( input_light_profile , none ) }}"
action:
- parallel:
- if:
- condition: template
value_template: "{{ light }}"
then:
- choose:
- conditions:
- condition: or
conditions:
- condition: state
entity_id: !input input_light_switch
state: "Off"
- condition: and
conditions:
- condition: state
entity_id: !input input_light_switch
state: Auto
- condition: trigger
id: Motion-Cleared
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ lights_off_script is defined }}"
sequence:
- service: "{{ lights_off_script }}"
data:
v_sunrise_angle: "{{ sunrise_angle }}"
v_light_profile: "{{ light_profile }}"
v_sunrise_time: "{{ sunrise_time }}"
v_wake_up_time: "{{ wake_up_time }}"
v_light_switch: "{{ light_switch }}"
v_sunet_angle: "{{ sunet_angle }}"
v_trigger_id: "{{ trigger.id }}"
v_sunet_time: "{{ sunet_time }}"
v_trans_off: "{{ trans_off }}"
v_lights_on: "{{ lights_on }}"
v_bed_time: "{{ bed_time }}"
v_target: "{{ target }}"
v_lights: "{{ lights }}"
default:
- service: light.turn_off
data: {}
target: "{{ target }}"
- conditions:
- condition: or
conditions:
- condition: state
entity_id: !input input_light_switch
state: "On"
- condition: and
conditions:
- condition: state
entity_id: !input input_light_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 input_light_switch
state: Auto
- condition: trigger
id: Motion-Detected
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ lights_on_script is defined }}"
sequence:
- service: "{{ lights_on_script }}"
data:
v_sunrise_angle: "{{ sunrise_angle }}"
v_light_profile: "{{ light_profile }}"
v_sunrise_time: "{{ sunrise_time }}"
v_wake_up_time: "{{ wake_up_time }}"
v_light_switch: "{{ light_switch }}"
v_sunet_angle: "{{ sunet_angle }}"
v_trigger_id: "{{ trigger.id }}"
v_sunet_time: "{{ sunet_time }}"
v_trans_off: "{{ trans_off }}"
v_lights_on: "{{ lights_on }}"
v_bed_time: "{{ bed_time }}"
v_target: "{{ target }}"
v_lights: "{{ lights }}"
- conditions:
- condition: template
value_template: "{{ states ( light_script ) != 'unknown' }}"
sequence:
- service: "{{ light_script }}"
data:
v_sunrise_angle: "{{ sunrise_angle }}"
v_light_profile: "{{ light_profile }}"
v_sunrise_time: "{{ sunrise_time }}"
v_wake_up_time: "{{ wake_up_time }}"
v_light_switch: "{{ light_switch }}"
v_sunet_angle: "{{ sunet_angle }}"
v_trigger_id: "{{ trigger.id }}"
v_sunet_time: "{{ sunet_time }}"
v_trans_off: "{{ trans_off }}"
v_lights_on: "{{ lights_on }}"
v_bed_time: "{{ bed_time }}"
v_target: "{{ target }}"
v_lights: "{{ lights }}"
default:
- service: light.turn_on
data: {}
target: "{{ target }}"
- if:
- condition: template
value_template: "{{ climate }}"
then:
- choose:
- conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ lights_script is defined }}"
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ lights_off_script is defined }}"
sequence:
- service: "{{ lights_off_script }}"
data:
v_sunrise_angle: "{{ sunrise_angle }}"
v_light_profile: "{{ light_profile }}"
v_sunrise_time: "{{ sunrise_time }}"
v_wake_up_time: "{{ wake_up_time }}"
v_light_switch: "{{ light_switch }}"
v_sunet_angle: "{{ sunet_angle }}"
v_trigger_id: "{{ trigger.id }}"
v_sunet_time: "{{ sunet_time }}"
v_trans_off: "{{ trans_off }}"
v_lights_on: "{{ lights_on }}"
v_bed_time: "{{ bed_time }}"
v_target: "{{ target }}"
v_lights: "{{ lights }}"
default:
- service: light.turn_off
data: {}
target: "{{ target }}"
mode: restart
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment