Files
hass-blueprints/motion_activated_scene.yaml
2026-03-02 17:11:37 +01:00

126 lines
3.5 KiB
YAML

blueprint:
name: Motion activated scene
description: Activates different scenes for daytime/nighttime on detecting motion and returns to an off-scene after a configurable timeout or exceeded illuminace threshold.
domain: automation
author: Florian Klemenz
input:
motion_sensors:
name: Motion Sensor
selector:
entity:
multiple: true
filter:
- domain: binary_sensor
device_class: motion
- domain: binary_sensor
device_class: occupancy
- domain: binary_sensor
device_class: presence
no_motion_wait:
name: Wait time
description: Time to leave the scene on after last motion is detected.
default: 120
selector:
number:
min: 0
max: 300
unit_of_measurement: seconds
illuminance_sensors:
name: Illuminance sensor
description: The illuminance sensor to get lux data.
selector:
entity:
multiple: true
filter:
domain: sensor
device_class: illuminance
illuminance_cutoff:
name: Illuminance threshold
description: Lux above this threshold will activate the "off" scene.
default: 10
selector:
number:
min: 0
max: 100
unit_of_measurement: lx
daytime_trigger:
name: Daytime
description: Binary sensor (TimeOfDay) or schedule to indicate when it is daytime
selector:
entity:
filter:
- integration: tod
domain: binary_sensor
- domain: schedule
daytime_scene:
name: Daytime scene
selector:
entity:
filter:
domain: scene
nighttime_scene:
name: Nighttime scene
selector:
entity:
filter:
domain: scene
off_scene:
name: Off scene
selector:
entity:
filter:
domain: scene
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input motion_sensors
from: "off"
to: "on"
action:
- choose:
# "Activate off-scene if illuminance is above threshold"
- conditions:
- condition: numeric_state
entity_id: !input illuminance_sensors
above: !input illuminance_cutoff
sequence:
- service: scene.turn_on
target:
entity_id: !input off_scene
- conditions: []
sequence:
# "Activate day-/-night scene depending on time of day"
- choose:
- conditions:
- condition: state
alias: "Check for daytime"
entity_id: !input daytime_trigger
state: 'on'
sequence:
- service: scene.turn_on
target:
entity_id: !input daytime_scene
- conditions: []
sequence:
- service: scene.turn_on
target:
entity_id: !input nighttime_scene
- alias: "Wait until there is no motion from device"
wait_for_trigger:
platform: state
entity_id: !input motion_sensors
from: "on"
to: "off"
- alias: "Wait the number of seconds that has been set"
delay: !input no_motion_wait
- alias: "Activate off scene"
service: scene.turn_on
target:
entity_id: !input off_scene