Trigger automation with two events with X time between them

Hey, I can’t seem to work this out.

I want to fire an automation when one or more events have triggered, but there will be X amount of time between the events.

The specific example:

The house occupancy changes from “not home” to “home”

The front door motion sensor detects that somone has opened the door

Automation fires and stuff happens.

I need to have both triggers as I cant just trigger from the occupancy changing as that is done with geo fencing/nest occupancy, which will change whenever I enter the geofence. But I may not have come through the door yet, so I want the second.

I cant seem to get this to work with anything, as I can’t figure out how to sit in what I effectively see as a while loop?

Sorry if this is dumb!

Matt

I would use both triggers in the same automation, but add 2 conditions that the entity was changed in the last xxx sec…

  condition:
    - condition: template
      value_template: '{{ (as_timestamp(now()) - as_timestamp(states.entity_name.attributes.last_updated | default(0)) | int < 120)}}'

Hello lolouk44, I am looking for a way to link two triggers for an automation that will open my garage.
I come with the train but sometimes with the car, when I come with the train I would like that HA realizes that:

  • I leave the train station zone and enter my home zone within 6 min (what it takes me to move from one zone to the other with the bike.
  • If I do it with the two triggers it will take always the entering the home zone and will open the garage every time I come home…

I believe is something like what you suggest above but I am having difficulties to figure out “states.entity_name.attributes.last_updated”…

The zones I would like to linke together:

platform: zone
entity_id: device_tracker.ls_mrn
zone: zone.bahnhof_boswil
event: leave

platform: zone
entity_id: device_tracker.ls_mrn
zone: zone.home
event: enter

Thaks for any suggestion :slight_smile:
Regards

The easiest is a trigger when you leave the station (your first trigger), then in your actions a wait template to check that you arrive home within 6 min, something like this:


    - wait_template: '{{ states("device_tracker.ls_mrn") == 'home' }}'
      timeout: '00:06:00'
      continue_on_timeout: false