88 lines
2.4 KiB
YAML
88 lines
2.4 KiB
YAML
blueprint:
|
|
name: Smart Motion Light with Optional Lux and Time-Based Dimming
|
|
description: Turns on a light when motion is detected or when lux falls below a threshold (optional), and dims based on time of day. Turns off when no motion is detected.
|
|
domain: automation
|
|
input:
|
|
motion_entity:
|
|
name: Motion Sensor
|
|
selector:
|
|
entity:
|
|
filter:
|
|
- domain: binary_sensor
|
|
device_class: motion
|
|
- domain: binary_sensor
|
|
device_class: occupancy
|
|
light_target:
|
|
name: Light
|
|
selector:
|
|
target:
|
|
entity:
|
|
domain: light
|
|
lux_entity:
|
|
name: Lux Sensor (optional)
|
|
default: null
|
|
selector:
|
|
entity:
|
|
domain: sensor
|
|
device_class: illuminance
|
|
lux_threshold:
|
|
name: Lux Threshold
|
|
description: Only turn on the light if lux is below this value (if sensor is defined).
|
|
default: 50
|
|
selector:
|
|
number:
|
|
min: 0
|
|
max: 1000
|
|
unit_of_measurement: lx
|
|
no_motion_wait:
|
|
name: Wait Time After Motion Stops
|
|
default: 120
|
|
selector:
|
|
number:
|
|
min: 0
|
|
max: 3600
|
|
unit_of_measurement: seconds
|
|
|
|
mode: restart
|
|
max_exceeded: silent
|
|
|
|
trigger:
|
|
- platform: state
|
|
entity_id: !input motion_entity
|
|
from: "off"
|
|
to: "on"
|
|
- platform: numeric_state
|
|
entity_id: !input lux_entity
|
|
below: !input lux_threshold
|
|
|
|
condition:
|
|
- alias: "Optional lux check and recent motion"
|
|
condition: template
|
|
value_template: >
|
|
{% set last_motion = states(!input.motion_entity) %}
|
|
{% set recent_motion = (last_motion == 'on') or (as_timestamp(now()) - as_timestamp(last_motion)) < 300 %}
|
|
{% if lux_entity %}
|
|
{% set lux_value = states(lux_entity) | float(0) %}
|
|
{{ recent_motion and lux_value < lux_threshold }}
|
|
{% else %}
|
|
{{ recent_motion }}
|
|
{% endif %}
|
|
|
|
action:
|
|
- alias: "Turn on the light with calculated brightness"
|
|
service: light.turn_on
|
|
target: !input.light_target
|
|
data:
|
|
brightness: "{{ brightness }}"
|
|
- alias: "Wait until motion stops"
|
|
wait_for_trigger:
|
|
- platform: state
|
|
entity_id: !input.motion_entity
|
|
from: "on"
|
|
to: "off"
|
|
- alias: "Wait the configured delay"
|
|
delay: !input.no_motion_wait
|
|
- alias: "Turn off the light"
|
|
service: light.turn_off
|
|
target: !input.light_target
|