When does an event trigger

I want to trigger my garage door to close if
a. it is open
b. no one is home based on all_mobile_devices group which has device_tracker objects in it

here is my question, what triggers the event and how often does it run?

Do I trigger on a garage door state of open and have a condition that everyone is gone
or
do I trigger on everyone being gone and have a condition that the garage door is open?

There are the following test cases.

  1. The last person in the house leaves the garage door open when they leave for the day.
  2. Someone who is not tracked by all_mobile_devices group opens the garage door (my oldest son and his girl friend who live out of town, but come in occasionally for example).

So in test case 1 the trigger would be based on the person leaving. But in test case 2, it’s based on the door opening? If I code the trigger to look for the last person leaving, how often will the trigger check to see if the garage door is opening, because there isn’t a state change in the members of all_mobile_devices?

Trigger on both: when door state becomes open and when the groups is “away”. Then filter with conditions if needed.

The event will trigger as soon as either trigger becomes true.

You’ll likely want a delay so that you don’t ever close the door as soon as it’s open. You can use notation like this:

- platform: state
      entity_id: lock.front_door_deadbolt
      state: 'unlocked'
      for:
        minutes: 5

I relock my front door if it’s been unlocked for 5 min (that automation has conditions to make sure the door is closed, too)

So I’ll have two automations for this, one to trigger on the garage door being open, and one to trigger on the house becoming empty. Not a problem, just making sure I can’t do it with one automation.

No - I was suggesting a single automation with two triggers.

I’ve never seen that, can you show me a quick example of one.

Sure. I use multiple triggers often. In this example, it’s essentially the same trigger three times, you get the syntax.

What it does: lock my front door after 5 min. But I had cases where someone might be standing with the door open for more than 5 min, so I have backups at 10 and 15. Each time, it checks to make sure that the door is closed first.

- alias: Auto Lock Front Door
  trigger:
    - platform: state
      entity_id: lock.front_door_deadbolt
      state: 'unlocked'
      for:
        minutes: 5
    - platform: state
      entity_id: lock.front_door_deadbolt
      state: 'unlocked'
      for:
        minutes: 10
    - platform: state
      entity_id: lock.front_door_deadbolt
      state: 'unlocked'
      for:
        minutes: 15
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.front_door
        state: 'off'
      - condition: state
        entity_id: input_boolean.house_guest
        state: 'off'
  action:
    - service: lock.lock
      entity_id: lock.front_door_deadbolt
1 Like

Here’s another example that’s close to what you’re trying:

that makes things a lot easier on some other triggers too. Thanks

You can check out https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/automation/watchdog.yaml#L47-L87 as well. I don’t close the door, I just notify on it. (then I manually close it if appropriate)