Automation with delay not firing action

Hi all, I’m trying to automate my bathroom fan by having it turn off automatically after 15 minutes when the bathroom light is turned off. However, the fan never seems to turn off. Would love a second pair of eyes on my automation to figure out what I’m doing wrong. Thanks!

- id: '1639712705795'
  alias: Master bathroom fan
  description: ''
  trigger:
  - platform: device
    type: turned_off
    device_id: 1
    entity_id: switch.master_bathroom_lights
    domain: switch
  condition:
  - condition: device
    type: is_on
    device_id: 2
    entity_id: switch.master_bathroom_fan
    domain: switch
  action:
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 2
    entity_id: switch.master_bathroom_fan
    domain: switch
  mode: single

Try this:

- id: '1639712705795'
  alias: Master bathroom fan
  trigger:
  - platform: state
    entity_id: switch.master_bathroom_lights
    from: 'on'
    to: 'off'
    for:
      minutes: 15
  condition:
  - condition: state
    entity_id: switch.master_bathroom_fan
    state: 'on'
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.master_bathroom_fan
  mode: single

You don’t really need the condition either as turning off a switch that is already off should do nothing.

Thanks for the response. Turns out the light switch wasn’t added correctly for some reason, so it wasn’t firing events. Fixed it by re-adding and now the automation works.

Great but do consider the version I posted as your version will fail if Home Assistant is restarted during the 15 minute delay, where as in my version the 15 minute timer is just reset during a restart but will still turn off the fan 15 minutes later.