Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdeweerd/3fa53af84c4034913c84171dae77b8d9 to your computer and use it in GitHub Desktop.
Save mdeweerd/3fa53af84c4034913c84171dae77b8d9 to your computer and use it in GitHub Desktop.
Homeassistant blueprint for motion-activated light scene with sun elevation sensor
blueprint:
name: Motion-activated light scene with optional ambient scene with sun elevation sensor
description: Turn on a light scene when motion is detected and the sun is below given threshold. Four different scenes can be defined depending on time of day.
domain: automation
source_url: https://gist.github.com/Martinnygaard/7645dcee2ca03d18c7a9523aa592605b
input:
motion_entity:
name: Motion Sensor
description: Choose which motion sensor to use. If multiple motion sensors should trigger this automation, then group them in a template sensor or regular group.
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
below_elevation:
name: Below sun elevation
description: Solar elevation. This is the angle between the sun and the horizon.
Negative values mean the sun is below the horizon.
default: 3
selector:
number:
min: -90.0
max: 90.0
unit_of_measurement: degrees
step: 1.0
mode: slider
scene_ambient:
name: Ambient Scene (Optional)
description: Scene for ambient state. Will be activated when no motion is detected and light level is under threshold. Default value = scene.none
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:
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
mode: restart
max_exceeded: silent
variables:
scene_ambient: !input scene_ambient
below_elevation: !input 'below_elevation'
condition:
- '{{ state_attr(''sun.sun'',''elevation'') <= (below_elevation | float)}}'
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
## condition for illumination has to be checked for every scece and not global. reason: action should be also triggered if no lights should be enabled to switch off ambient scene if it is to bright
action:
- choose:
- conditions:
- condition: time
after: !input time_scene_morning
before: !input time_scene_day
sequence:
- scene: !input scene_morning
- conditions:
- condition: time
after: !input time_scene_day
before: !input time_scene_evening
sequence:
- scene: !input scene_day
- conditions:
- condition: time
after: !input time_scene_evening
before: !input time_scene_night
sequence:
- scene: !input scene_evening
- conditions:
- condition: time
after: !input time_scene_night
before: !input time_scene_morning
sequence:
- scene: !input scene_night
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- delay: !input no_motion_wait
- choose:
- conditions:
- "{{ scene_ambient != 'scene.none'}}"
- condition: time
after: !input time_scene_ambient_start
before: !input time_scene_ambient_end
sequence:
- scene: !input scene_ambient
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