I’ve modified the built-in motion activated light blueprint to work with an outdoors light I have. The main thing I’ve done is added a 10 second delay after the light turns back off before the automation is allowed to run again. The reason for this is because I’m using a camera for the motion detection, and when the light turns off, it causes the motion detection to see motion (due to the large scale lighting change). So without this 10 second delay, it will keep being reactivated by itself infinitely.
My problem is that if legitimate motion occurs within this 10 second window, the light will not turn back on again until the motion stops, stays stopped for a period of time, then starts again. I believe this is because the automation trigger only works when the state changes. So, when my trigger is looking for motion_entity to have state “on”, it has to change to on from something else. If it’s already on to begin with then the trigger won’t work.
How can I fix this? Is there a way to make it check the trigger e.g. once every second, rather than only when it changes?
blueprint:
name: Motion-activated Light (Outdoors)
description: Turn on a light when motion is detected.
domain: automation
author: Home Assistant
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
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: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
light_off_wait:
name: Light off wait time
description: Time to leave the light off before allowing it to be triggered again.
default: 10
selector:
number:
min: 0
max: 60
unit_of_measurement: seconds
sun_entity:
name: Sun entity
description: This is normally "sun.sun".
default: sun.sun
selector:
entity:
domain: sun
# If motion is detected within the delay,
# we restart the script.
mode: single
max_exceeded: silent
trigger:
platform: state
entity_id: !input motion_entity
#from: "off"
to: "on"
condition:
# Only run between sunset and sunrise
- condition: numeric_state
entity_id: !input sun_entity
attribute: elevation
below: 0
action:
- alias: "Turn on the light"
service: light.turn_on
target: !input light_target
- alias: "Wait until there is no motion from device"
wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- alias: "Wait the number of seconds that has been set"
delay: !input no_motion_wait
- alias: "Turn off the light"
service: light.turn_off
target: !input light_target
- alias: "Wait the number of seconds that has been set for light off wait"
delay: !input light_off_wait