Skip to content

Instantly share code, notes, and snippets.

@networkingcat
Last active December 27, 2020 15:08
Show Gist options
  • Save networkingcat/c767ae0086738cb922fbfc19a17ff308 to your computer and use it in GitHub Desktop.
Save networkingcat/c767ae0086738cb922fbfc19a17ff308 to your computer and use it in GitHub Desktop.
ha_test_gist
blueprint:
name: Test Gist
description: Test Gist
domain: automation
source_url: https://gist.github.com/networkingcat/c767ae0086738cb922fbfc19a17ff308
homeassistant:
min_version: 2021.2.0
input:
motion_entity:
name: Motion Sensor
description: Motion Sensor or a group with Motion Sensors (But can be anything switching between "on" and "off")
selector:
entity:
light_target:
name: Light
selector:
target:
entity:
domain: light
automation_blocker:
name: Automation Blocker (Optional)
description: Only run if this boolean is true
default:
selector:
entity:
domain: input_boolean
elevation_check:
name: Sun elevation check (Optional)
description: This is the angle between the sun and the horizon. Negative values mean the sun is BELOW the horizon.
default:
selector:
number:
min: -90
max: 90
unit_of_measurement: degrees
scene_ambient:
name: Ambient Scene (Optional)
description: Scene for ambient state. Will be activated when no motion is detected.
default: scene.none
selector:
entity:
domain: scene
time_scene_ambient_start:
name: Ambient time frame start
description: Time from which on ambient scene will be activated
default: "00:00:00"
selector:
time:
time_scene_ambient_end:
name: Ambient time frame end
description: Time from which on ambient scene will be not activated
default: "00:00:00"
selector:
time:
scene_morning:
name: Scene for the morning
default: scene.none
selector:
entity:
domain: scene
time_scene_morning:
name: Time for the morning scene
description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
default: "00:00:00"
selector:
time:
scene_day:
name: Scene for the bright day
default: scene.none
selector:
entity:
domain: scene
time_scene_day:
name: Time for the day scene
description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
default: "00:00:00"
selector:
time:
scene_evening:
name: Scene for the evening
default: scene.none
selector:
entity:
domain: scene
time_scene_evening:
name: Time for the evening scene
description: A time input which defines the time from which on the scene will be activated if motion is detected. Default value = scene.none
default: "00:00:00"
selector:
time:
scene_night:
name: Scene for the dark night
default: scene.none
selector:
entity:
domain: scene
time_scene_night:
name: Time for the night scene
description: A time input which defines the time from which on the scene will be activated if motion is detectedd. Default value = scene.none
default: "00:00:00"
selector:
time:
scene_no_motion:
name: Default scene for no motion (Optional)
description: Set this Scene if you want to activate a scene if motion stops
default: scene.none
selector:
entity:
domain: scene
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
boolean_offset:
name: Turn on offset for non working days (Optional)
description: Turn on offset for non working days in your country
default: false
selector:
boolean:
mode: restart
max_exceeded: silent
variables:
scene_ambient: !input scene_ambient
scene_morning: !input scene_morning
scene_day: !input scene_day
scene_evening: !input scene_evening
scene_night: !input scene_night
automation_blocker: !input automation_blocker
elevation_check: !input elevation_check
scene_no_motion: !input scene_no_motion
boolean_offset: !input boolean_offset
time_scene_morning: !input time_scene_morning
# time_scene_morning_cheked: {% if boolean_offset == false %} time_scene_morning
# Ha, Paulus is home!
#{% else %}
# Paulus is at {{ states('device_tracker.paulus') }}.
#{% endif %}
time_scene_day: !input time_scene_day
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
condition:
# Check if automation blocker exist and if yes if it is on, otherwise do not run
- condition: template
value_template: "{{ (automation_blocker == none) or (states[automation_blocker].state == 'on') }}"
# Check if elevation input exist and if yes it is below desired value, otherwise do not run
- condition: template
value_template: "{{ (elevation_check == none) or (state_attr('sun.sun','elevation') <= elevation_check | float) }}"
#- condition: template
# value_template: "{{ boolean_offset }}"
action:
- choose:
- conditions:
- "{{ scene_morning != 'scene.none'}}"
- condition: time
after: !input time_scene_morning
before: !input time_scene_day
sequence:
- scene: !input scene_morning
- conditions:
- "{{ scene_day != 'scene.none'}}"
- condition: time
after: !input time_scene_day
before: !input time_scene_evening
sequence:
- scene: !input scene_day
- conditions:
- "{{ scene_evening != 'scene.none'}}"
- condition: time
after: !input time_scene_evening
before: !input time_scene_night
sequence:
- scene: !input scene_evening
- conditions:
- "{{ scene_night != 'scene.none'}}"
- condition: time
after: !input time_scene_night
before: !input time_scene_morning
sequence:
- scene: !input scene_night
default:
- service: light.turn_on
target: !input light_target
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- delay: !input no_motion_wait
- choose:
# Used if ambient scene is true and in ambient scene time frame
- conditions:
- "{{ scene_ambient != 'scene.none' }}"
- condition: time
after: !input time_scene_ambient_start
before: !input time_scene_ambient_end
sequence:
- scene: !input scene_ambient
# Used if default no motion scene is set
- conditions:
- "{{ scene_no_motion != 'scene.none' }}"
sequence:
- scene: !input scene_no_motion
# Default to turn lights off
default:
- service: light.turn_off
target: !input light_target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment