Skip to content

Instantly share code, notes, and snippets.

@haberda
Last active October 20, 2022 15:04
Show Gist options
  • Save haberda/8b58b2e6113114727ce17a464aaf2e14 to your computer and use it in GitHub Desktop.
Save haberda/8b58b2e6113114727ce17a464aaf2e14 to your computer and use it in GitHub Desktop.
Motion light blueprint
blueprint:
name: Motion-activated Light with illuminance
description: Turn on a light when motion is detected and illuminance is below a set Lux level.
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
lux_entity:
name: Illuminance Sensor
selector:
entity:
domain: sensor
device_class: illuminance
lux_level:
name: Illuminance level
description: If lux is below this value and motion is detected, the light will turn on.
default: 15
selector:
number:
min: 0
max: 100
light_target:
name: Light
selector:
target:
entity:
domain: light
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 300
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
time_based:
name: "Restrict by time"
description: "Only turn on lights between the start and end times."
default: false
selector:
boolean: {}
start_time:
name: Start Time
default: "22:00"
selector:
time: {}
end_time:
name: End Time
default: "08:00"
selector:
time: {}
disable_entity:
name: Disable entity
description: Binary sensor or input boolean that when on disables the updating of lights.
selector:
entity:
fire_forget:
name: "Fire and forget"
description: "Only turn on lights, never turn them off."
default: false
selector:
boolean: {}
mode: single
max_exceeded: silent
variables:
time_based: !input time_based
fire_forget: !input fire_forget
trigger:
- platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
id: 'motion_on'
- platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
for: !input no_motion_wait
id: 'motion_off'
- platform: numeric_state
entity_id: !input lux_entity
below: !input lux_level
id: 'below_lux'
condition:
- condition: state
entity_id: !input disable_entity
state: "off"
- or:
- not:
- condition: template
value_template: '{{ time_based }}'
- and:
- condition: template
value_template: '{{ time_based }}'
- condition: time
after: !input start_time
before: !input end_time
action:
- if:
- or:
- and:
- condition: trigger
id: 'motion_on'
- condition: numeric_state
entity_id: !input lux_entity
below: !input lux_level
- and:
- condition: trigger
id: 'below_lux'
- condition: state
entity_id: !input motion_entity
state: 'on'
then:
- service: light.turn_on
target: !input light_target
else:
- condition: trigger
id: 'motion_off'
- not:
- condition: template
value_template: '{{ fire_forget }}'
- 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