I have a Blueprint that has a motion sensor as the trigger. I also have a input that I can select a action that I use for a notification to be sent. see below.
input:
motion_trigger:
name: Motion Sensor
description: The Motion Sensor that turns the lights ON and OFF
selector:
entity:
domain: binary_sensor
device_class: motion
light_switch:
name: Lights
description: The lights that get turned on by the motion sensor
selector:
target:
entity:
domain: light
time_delay:
name: Time Delay
description: Time to leave the light on after last motion is detected.
default: 5
selector:
number:
min: 0
max: 30
step: 0.5
unit_of_measurement: minutes
notify_actions:
name: Notification Actions (Optional)
description: Only select Notifications
selector:
action: {}
the trigger
trigger:
platform: state
id: "trigger_off_state"
entity_id: !input motion_trigger
from: "off"
to: "on"
in the action I have
action:
- alias: "Send Notifications"
choose: []
default: !input notify_actions
- alias: "Turn on the light"
service: homeassistant.turn_on
target: !input light_switch
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes that has been set"
delay:
minutes: !input time_delay
- alias: "Turn off the lights"
service: homeassistant.turn_off
target: !input light_switch
It all works and sends the notification to my phone, all is good BUT every trigger of the motion sensor will send another notification . The light can stay on for a time set in the blueprint using “time_delay” and say it was set for 10m in this time you could get a lot of motion notifications.
Is there a way to send the first notification and then wait until the lights are turned off at the end of the action?
If you click on the 3 dots in the top right hand corner of the automation editor, and choose “Change mode”, which mode is selected? Try “single”, if it’s not already set to that.
I can see why you’ve done it as restart - but that is the reason why you’re getting multiple notifications. I don’t personally use blueprints so I’m not sure how much flexibility you have to modify the automation, but you could add a condition which checks if the light is either off or has been on for more than 4:30, for example.
A template condition for this would like something like: {{ states("light.bedroom_lights_switch") == "off" or as_timestamp(states.light.bedroom_lights_switch.last_changed)+269 < as_timestamp(now()) }}
You would still get multiple notifications this way, but only one every 4 1/2 minutes which would probably be an improvement!
Hi @EKC I tried it but couldn’t get it to work. I am also thinking that putting a condition to stop/pause the automation then really just defeats the time delay in the action.
In the action the step are,
Motion detected trigger action.
Check sun setting if used.
Notify
Turn the light ON
Wait until motion goes to OFF state
Then wait for the time delay… but at this point if the motion is triggered again then we start at notify. this is my problem heaps of messages.
If no motion then turn off lights.
trigger:
platform: state
id: "trigger_off_state"
entity_id: !input motion_trigger
from: "off"
to: "on"
# All Conditions
condition:
# Check if Light Switch Manual By-pass (Optional)
# Check sun elevation input
- condition: template
value_template: "{{ (sun_elevation == none) or (state_attr('sun.sun','elevation') <= sun_elevation | float(90)) }}"
# Check Ambient Light Sensor input
# Notification delay to stop multiple notifications
action:
- alias: "Send Notifications"
choose: []
default: !input notify_actions
- alias: "Turn on the light"
service: homeassistant.turn_on
target: !input light_switch
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes that has been set"
delay:
minutes: !input time_delay
- alias: "Turn off the lights"
service: homeassistant.turn_off
target: !input light_switch
if I move the notify to last step I get one notify but that is after the fact so that’s no good see below.
action:
- alias: "Turn on the light"
service: homeassistant.turn_on
target: !input light_switch
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes that has been set"
delay:
minutes: !input time_delay
- alias: "Turn off the lights"
service: homeassistant.turn_off
target: !input light_switch
- alias: "Send Notifications"
choose: []
default: !input notify_actions
I am not sure if I can get a condition to work here… really need 2 actions (parallel) but in blueprint I just cant get it to work.