Turn bathroom light off if door is open, and someone didn't turn the light back on

I tried to code even with ChatGDP help I still can get it to work right.
I was trying to get to that so if the door is open turn the light off after 6 mins, but only if someone didn’t turn the light back on during that time.

- id: turn_off_bathroom_light
  alias: Turn off bathroom light
  trigger:
    - platform: state
      entity_id: binary_sensor.bathroom_door
      to: 'on'
      for:
        minutes: 6
  condition:
    - condition: template
      value_template: '{{ is_state("switch.bathroom_light_switch", "off") }}'
  action:
    - service: switch.turn_off
      entity_id: switch.bathroom_light_switch

What you are describing doesn’t make sense.

the light is on…

someone opens the door…

the light is still on…

6 minutes after the door is opened the light should turn off…

Why would someone need to turn the light back on during that time? it’s already still on…

Rather than turning off with a trigger, when the light turns on you could start a timer. When the timer finishes, turn off the light. If somebody physically turns the switch on, cancel the timer which will prevent it from turning off the light.

I have a similar situation where:

  • A motion sensor turns the light on and starts a timer for 5 minutes
  • If somebody hits the Hue dimmer, they’re saying “I want the light to stay on until I turn it off”
  • If the light has turned on and the door is closed, leave the light on until the door is opened again and then turn the light off after 5 minutes (it’s a bit more complex than this due to closing the door as you exit)

I will give that a try, thank you