Automation triggered by two (or more) events within a time span?

Is there a way to have an automation triggered by detecting two or more events happening within a certain amount of time?

I’m trying to write an automation to have my foyer lights turn on when somebody opens the front door, but it was also triggering when somebody left…didn’t think of that previously :expressionless: As you all know, presence detection isn’t always timely, so I’m trying to come up with a solution that involves the front door opening and somebody’s presence detection going from ‘off’ to ‘on’ within a minute or two of each other.

I can probably hack something together with input_booleans that unset themselves after a time, but I’m trying to find a more elegant solution.

Any ideas?

can you list the sensor states and what action you want to see?
e.g.

  • door = open AND presence = home and sensor.presence.last_updated - binary_sensor.door.last_updated <= 60sec ==> light on