Skip to content

Instantly share code, notes, and snippets.

@Mrtenz
Last active July 28, 2022 19:38
Show Gist options
  • Save Mrtenz/b602e57c706289110b5ffa53bf6d86fb to your computer and use it in GitHub Desktop.
Save Mrtenz/b602e57c706289110b5ffa53bf6d86fb to your computer and use it in GitHub Desktop.
blueprint:
name: Motion Light
description: >
Turn on a light when motion is detected, and the luminance in the room is
below the specified value. Keeps the light on for a specified amount of
time, before dimming it, and eventually turning it off.
domain: automation
input:
motion_sensor:
name: Motion Sensor
description: The sensor that will trigger the automation.
selector:
entity:
domain: binary_sensor
device_class: motion
motion_sensor_illuminance:
name: Illuminance Sensor
description: The illuminance of the motion sensor.
selector:
entity:
domain: sensor
device_class: illuminance
target_light:
name: Light(s)
description: The light(s) to turn on.
selector:
target:
entity:
domain: light
max_illuminance:
name: Max Illuminance
description: The light will only turn on if the illuminance is below the specified illuminance here.
default: 30
selector:
number:
min: 0
max: 100
mode: slider
unit_of_measurement: lx
initial_brightness:
name: Brightness
description: The brightness to set the lights to when motion is detected.
default: 100
selector:
number:
min: 0
max: 100
mode: slider
unit_of_measurement: "%"
dim_brightness:
name: Dim Brightness
description: The brightness to set the light to after the dim delay.
default: 50
selector:
number:
min: 0
max: 100
mode: slider
unit_of_measurement: "%"
dim_delay:
name: Dim Delay
description: Time to leave the light at full brightness before dimming.
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
mode: box
turn_off_delay:
name: Turn Off Delay
description: Time to leave the light on after last motion is detected.
default: 60
selector:
number:
min: 0
max: 3600
mode: box
unit_of_measurement: seconds
transition:
name: Transition Time
description: Time that the light should take to transition to the new state.
default: 0.5
selector:
number:
min: 0
max: 10
mode: box
unit_of_measurement: seconds
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input motion_sensor
to: "on"
condition:
condition: or
conditions:
- condition: numeric_state
entity_id: !input motion_sensor_illuminance
below: !input max_illuminance
- condition: state
entity_id: !input motion_sensor
state: "on"
action:
- service: light.turn_on
target: !input target_light
data:
transition: !input transition
brightness_pct: !input initial_brightness
- wait_for_trigger:
platform: state
entity_id: !input motion_sensor
from: "on"
to: "off"
- delay: !input dim_delay
- service: light.turn_on
target: !input target_light
data:
transition: !input transition
brightness_pct: !input dim_brightness
- delay: !input turn_off_delay
- service: light.turn_off
target: !input target_light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment