Triggering automation when true for set amount of time

Hey all

I’m trying to use device_tracker to turn all lights off when no one is home.
However, I use nmap for presence detection, so I don’t want all the lights to go off if someone’s phone just happens to disconnect from the network.

I’m wondering whether it’s possible to add some sort of timer to the state check to see whether the state is still the same for that whole period, and if so, only then turn the lights off.

This is what I have so far with no form of time awareness.

- alias: "No one home -> lights off"
  initial_state: False
    platform: state
    entity_id: group.devices
    to: 'not home'
  # if still true after 15 minutes
    - service: light.turn_off
      entity_id: group.all_lights

You can use the for: option with state triggers and then specify a time. Example given is from the docs:

    platform: state
    entity_id: device_tracker.paulus, device_tracker.anne_therese
    # Optional 
    from: 'not_home'
    to: 'home'

    # Alias for 'to'
    state: 'home'

    # If given, will trigger when state has been the to state for X time.
      hours: 1
      minutes: 10
      seconds: 5

Awesome, I didn’t give the “for” option. Thank you!

I can’t figure out what the “state: ‘home’” line is though?

State: home can be used instead of from: not_home to: home