Wait for trigger automation

Hi, I want to know how to make a condition check when an automation is triggered. So if my binary sensor 1 goes “off”, I notify the telegram on the condition that sensor 2 does not change in the next 30 seconds. I have tried the para and the telegram notification notifies me when the sensor goes from the “on” state to the “off” state. What I want is for sensor 1 to turn off, wait 30 seconds to verify that sensor two has not changed in 30 seconds.
I need to use the new wait for trigger function implemented in the new home assistant 0.115 update. If anyone knows how to adapt my proposal to the code I would greatly appreciate it.

I don’t think it is the wait_for_trigger that you want if I’m reading your requirements correctly.

Please confirm that your scenario is this…

Binary sensor 1 goes off

Binary sensor 2 goes off within 30 seconds

Send notification

?

1 Like

Binary sensor1 goes “on” to “off”

If binary sensor2 does not go from “off” to “on” in the next 30 seconds

Send notification

automation:
  alias: The mf_social solution 
  trigger:
    platform: state
    entity_id: binary_sensor.1
    to: 'on' 
  condition:
    condition: state
    entity_id: binary_sensor.2
    state: 'on'
  action:
    - wait_template: "{{ is_state('binary_sensor.2', 'on') }}"
      timeout:
        seconds: 30
      continue_on_timeout: false 
    - service: notify.you 
      data:
        message: "It happened" 

As you have explained to me, it does not work for me, maybe I raised the question wrong.

Binary sensor1 goes “on” to “off”

If binary sensor2 does not go from “off” to “on” in the next 30 seconds (remains on off)

If no motion was detected on binary sensor2:Send notification

Of course, sorry, I misread your last post and thought the states were just flipped between the binary sensors.

So, just to be clear, the logic is:

Binary_sensor.1 goes off and in the next 30 seconds binary_sensor.2 does change, nothing should happen.

But if during that 30 seconds it doesn’t change, send the notification.

?

EXACTLY!!!

Please stop posting your issues multiple times, it’s the third topic you opened on this issue! I’ll reply in your first topic in a minute.

Yeah, with you now, my apologies, you’re correct that it needs the wait_for_trigger. I think this will do it but I can’t test it so if you can give it a go and let me know what happens…

automation:
  alias: The mf_social solution 
  trigger:
    platform: state
    entity_id: binary_sensor.1
    to: 'on' 
  action:
    - wait_for_trigger:
      - platform: state 
        entity_id: binary_sensor.2
        to: 'on' 
      timeout:
        seconds: 30
    - condition: template
      value_template: "{{ not wait.completed }}" 
    - service: notify.you 
      data:
        message: "It happened"
2 Likes

That looks more elegant than my solution here.

Just as a reference, there’s a third topic with the same question here.

1 Like

When sensor 2 does not detect movement, it waits for 30 seconds, but when it detects movement it sends the message instantly. What I want is that it does not notify me when it detects movement.

wait.completed doesn’t exist for a wait_for_trigger, just checked the docs and this only exists for the wait_template, see here.