I want this to fire a notification if door opened and no once at home
presence state is usually triggered few seconds (10-ish) after the door open, so every time I enter my house automation fires.
I would prefer to avoid adding a “for” statement to the trigger as this could prevent the automation to trigger when needed.
Is there a way to trigger the automation but test the condition after a certain amount of time?
Move the State Conditions that check if anyone is home to a wait_template in the automation’s action. Set its timeout value to slightly more than 10 seconds.
For example, if you set it to 12 the wait_template will wait for up to 12 seconds for its State Conditions to become true. If they don’t become true within 12 seconds, what the automation does next is your choice. Normally the automation will not continue because continue_on_timeout is set to false by default.
With both types of waits it is possible to set a timeout after which the script will continue its execution if the condition/event is not satisfied. Timeout has the same syntax as delay, and like delay, also accepts templates.
Maybe; this version doesn’t contain the first two State Conditions present in the original example. Do you now want to exclude them from the automation?
Here’s how your example will work with the wait_template.
When Porta Ventri Entrata is opened and left open for at least 5 seconds, the wait_template will begin to check for either person1 or person2 to be home. If neither is home, it will wait for up to 15 seconds for one of them to be home. If it happens within 15 seconds, the Automation sends a notification. If it doesn’t happen within 15 seconds, the automation ends (no notification is sent).
I think that behaves the way you wanted and demonstrates how a wait_template can be used to wait for something to happen.
now issue is that sometimes the “person at home binary sensor” triggers to ON after the door is opened.
So I would like the wait template to check the condition for 35s and carry on only if the condition remains TRUE for 35s.
This is not happening instead and I can’t understand which syntax I need to use based on this
- wait_template: "{{ (is_state('binary_person1_at_home', 'off'))and(is_state('binary_sensor.person2_at_home', 'off'))and(is_state('binary_sensor.persone3_at_home', 'off')) }}"
~~~~~~~~~~~~~~~~~~~~~~
^
|
What is this?
It's not an entity_id or a variable
Are you saying that it never worked since a month ago? Or it only recently failed to work after you added all of the conditions that weren’t present in your original example?
so that binary sensor is a bayesian which I use to build a more robust “at home” sensor.
It never worked I am afraid: I was convinced it did and marked “solved” to early.
Honestly I am afraid wait_template can’t do what I supposed it could do.
As far as I understand it waits for the template to render true until the timeout expires and then continue the automation.
If it does not render true you can decide to continue or not after the timeout.
What I need instead is a sort of delayed condition such that it checks for 35s that the condition is satisfied, if not satisfied it stops executing the automation
sorry I edited the automation in order to post it here and remove personal data and doing this misspelled the binary sensor: I can confirm that in my automation that is spelled correctly
I have a similar automation and had the same problem, the device_tracker state takes a few seconds after entering the appartment.
I solved with a simple delay and choose:
alias: Allarme apertura porte
initial_state: true
id: "1912291115001"
trigger:
- entity_id: binary_sensor.porta_vetri_entrata
from: "off"
platform: state
to: "on"
action:
- delay:
seconds: 10
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.someone_at_home
state: "off"
- condition: state
entity_id: input_boolean.security_alarm_status
state: "on"
- condition: state
entity_id: binary_sensor.xxx_at_home
state: "off"
- condition: state
entity_id: binary_sensor.yyy_at_home
state: "off"
sequence:
...
It will trigger when the door opens, waits the delay and then checks if the conditions are met. If yes it will continue (you have to add your actions under sequence), if not it will stop and do nothing.
You can use an if-then-else to test the wait.completed variable after the wait_template. If it’s true (meaning the wait_template evaluated to true during its timeout) you can stop the automation with stop. Otherwise, the else in the if-then-else proceeds to execute the remaining actions.