- wait_for_trigger:
platform: state
entity_id: !input motion_sensor
from: "on"
to: "off"
- delay:
minutes: '{{ states[no_motion_wait].state | int }}'
To:
- wait_for_trigger:
platform: state
entity_id: !input motion_sensor
from: "on"
to: "off"
for:
minutes: '{{ states[no_motion_wait].state | int }}'
This is a very small change but I believe the difference is the for in the wait_for_trigger is handled differently then a delay when this script is restarted.
I have just retested the blueprint, but I cannot reproduce the described errors of the light turning off after the automation has been retriggered. For me the automation restarts just fine with the lastest version of the blueprint (with the delay in it).
I am able to keep postponing the turning off of the entity by retriggering the motion sensor.
A possible reason for this not happening, is that some motion sensors stay in the ‘on’ state for a long time.
When you try to trigger it when it is still in the ‘on’ state, the automation will not restart and the light will turn off at the originally determined time.
You can only restart the automation by triggering the motion sensor so it’s state goes from ‘off’ to ‘on’. Then again the light should only turn of after a delay that is set when the motion sensor turns to the ‘off’ state again. I have tested retriggering the automation 3-4 times and every time it turns off at exactly x minutes after the motion sensor was last marked as ‘off’.
So in short, the blueprint works exactly as intended for me.
But if you still have problems with the latest version do let me know
For example, if the automation is triggered and the blocker entity is pressed in the middle of this phase, the automation will still completed. It would be nicer if the automation would actually reset to zero.
Working brilliantly with my Xmas Xiaomi Aqara motion sensor and hallway light! Thanks so much - I was just starting to dig in and thought to check the new blueprints contributions and there it was! The only thing I’m missing for total happiness is percent brightness and transition time variables for the target.
So I’m starting to have a bug now. I am using a simple setup, using a light group for 4 LIFX bulbs, using a ESP motion sensor that was being used previously in node red to do motion lights, I have a blocking entity for turning off the automation, and I’ve set the time to turn the light off after motion to 30 seconds.
My issue is no matter what time delay I set it as (5 seconds, 30 seconds, 5 minutes, etc), the lights will turn off after 3 seconds (which is the time it takes for the motion sensor to detected motion after its cool down). So in other words, the lights detects motion, turns on lights, then after 3 seconds the motion sensor registers that there is no more motion, so it turns the lights back off.
I think it’s best not to put this in my blueprint, since I expect this to be a requirement which not a lot of people want. I don’t want to incorporate every niche requirement with additional optional parameters. This makes the blueprint harder to maintain and test.
But you can of course edit the blueprint to add this functionality.
The blocker entity is there to prevent the target entity from turning on in the first place.
So what do you want to happen if the blocker entity is pressed in the wait time, to immediately turn off the entity?
I’m not sure thats possible, but I can look into it.
To turn on a light with a defined brightness and other attributes, you could define a scene or a script. If I would use separate inputs for all possible light attributes the blueprint becomes a mess. The problem is, in that case the light will not turn off, since turning off a light by the same script or scene that turned it on is not possible, I think.
A possible solution for this is that I define a separate ‘turn-off input’, that when defined is used to turn off this entity. That way you could turn on the entity by the target entity input, and turn off a different entity (like a light or group).
It seems like in this case the turn off delay is not properly used in your automation.
Can you post the generated automation that you created with this blueprint? And preferably also the input_number definition of your delay value?
The solution I added is a separate turn-off blocking entity.
If you define this (optional) entity, the target entity will not turn off when the state of the turn off entity is ‘on’. This should cover your usecase
Just dropping this here in case its valuable to anyone. I made a pretty similar blueprint (that I won’t share as it’s pretty much a lesser version of this one with some specific conditions that reflect my environment). But one thing I found useful was for the automation to not trigger a predefined scene in the case where I manually selected a different scene (e.g. a specific mood or holiday scene) or manually adjusted some lights. To circumvent this, I added the following choose condition at the top of my action:
This allows the automation to default to a scene depending to the time of day, but in the case manual changes have been made to the scene or another scene has been manually selected, the automation won’t override those choices by returning to the default scene upon detecting new motion.
thank you for this blueprint. I have afew questions/ request:
1- can you make the motion sensor input to select more than one motion sensor?
2-can the blocking entity input be also changed to select more than one entity?
I think that instead of using input you should use slider right at automation part, it is more convenient than example
no_motion_wait:
name: (OPTIONAL) Turn off wait time
description: Time to leave the light on after last motion is detected. If not used entity will not auto turn off. Only works for target_entity types light and switch.
default:
selector:
number:
min: 1
max: 1000
step: 1.0
mode: slider
There are 3 no_motion_wait inputs, for 3 animations, 1 second, 300 seconds and 900 seconds. For the one that has 1 second, I’ve tried any number here, the lights always turn off after 3 seconds.
The no_motion_wait input does not support hardcoded values (integers/numbers).
It expects an input_number entity, like I have stated in the documentation (see the Optional entities example YAML section).
You need to create this input_number entity yourself.
This is a choice I have made because I want to be able to change the value dynamically without editing the automation itself.