Help with automation condition

I have this simple automation:

-  alias: Cancello Giulietta
   trigger:
       platform: state
       entity_id: device_tracker.giulietta
       to: "home"
   condition: 
   - condition: state
     entity_id: 'cover.garage_door'
     state: 'closed'
   action:
   - service: cover.open_cover
     entity_id: cover.garage_door

I need a condition like this: if X sensor is “not_home” or is “home” from 20 seconds

Thanks

- alias: Cancello Giulietta
  trigger:
    platform: state
    entity_id: device_tracker.giulietta
    to: "home"
  condition: 
  - condition: state
    entity_id: 'cover.garage_door'
    state: 'closed'
  - condition: or
    conditions:
    - condition: state
      entity_id: sensor.x
      state: "not_home"
    - condition: state
      entity_id: sensor.x
      state: "home"
      for:
        seconds: 20
  action:
  - service: cover.open_cover
    entity_id: cover.garage_door

i wasn’t clear enough… from 20 seconds i mean “the sensor have changed status maximum 20 seconds ago” and not “at least 20 seconds”

- alias: Cancello Giulietta
  trigger:
    platform: state
    entity_id: device_tracker.giulietta
    to: "home"
  condition: 
  - condition: state
    entity_id: 'cover.garage_door'
    state: 'closed'
  - condition: or
    conditions:
    - condition: state
      entity_id: sensor.x
      state: "not_home"
    - condition: template
      value_template: "{{ is_state('sensor.x', 'home') and ( as_timestamp(now()) - as_timestamp(states.sensor.x.last_changed)|int < 20 ) }}"
  action:
  - service: cover.open_cover
    entity_id: cover.garage_door

i have to try that, but i think that you saved my life :slight_smile: