Bathroom fan automation issue

Ok so I needed to automate the Bathroom fan to come on when the Bathroom light is turned on (Presence detected). This turns on a Bathroom light timer helper set at 5 minutes. If the Bathroom light is switched off due to ‘No presence’ within the 5 minutes I need the Bathroom fan turned off as well. If the Bathroom light is turned off after 5 minutes then a second helper Bathroom fan timer starts counting down 20 minutes and then turns off Bathroom fan.
The idea is short stay in bathroom should result in immediate fan turn off cue the light. Long stay which usually means a fan to stay on for 20 minutes to exhaust humid air.
Using helpers to ensure timers are robust. Watched a video recently on how to set them up.

Everything else works perfectly except the turning off within 5 minutes

The issue is within this part:

condition: trigger
id:
  - Bathroom Light Off
condition: not
conditions:
  - condition: state
    entity_id: timer.bathroom_light_timer
    state: idle
type: turn_off
device_id: c64baab5b4e966fd414cdcdfbc5569de
entity_id: 6ba769696ca9b3f1e738649ebc45b1e3
domain: switch
service: timer.cancel
target:
  entity_id:
    - timer.bathroom_fan
data: {}

The entire automation:

alias: Bathroom Fan
description: ""
trigger:
  - platform: device
    type: turned_on
    device_id: c64baab5b4e966fd414cdcdfbc5569de
    entity_id: bd53073741dae02a5eaebcb48e1a3cef
    domain: switch
    id: Bathroom Light On
  - platform: device
    type: turned_off
    device_id: c64baab5b4e966fd414cdcdfbc5569de
    entity_id: bd53073741dae02a5eaebcb48e1a3cef
    domain: switch
    id: Bathroom Light Off
  - platform: state
    entity_id:
      - timer.bathroom_fan
    from: active
    to: idle
    id: Bathroom Fan Delay
  - platform: device
    type: turned_off
    device_id: c64baab5b4e966fd414cdcdfbc5569de
    entity_id: 6ba769696ca9b3f1e738649ebc45b1e3
    domain: switch
    id: Bathroom Fan turned off
condition: []
action:
  - service: notify.notify
    data:
      message: Aquarium Solonoid Off
      title: Alert
    enabled: false
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Bathroom Light On
        sequence:
          - type: turn_on
            device_id: c64baab5b4e966fd414cdcdfbc5569de
            entity_id: 6ba769696ca9b3f1e738649ebc45b1e3
            domain: switch
          - service: timer.cancel
            target:
              entity_id:
                - timer.bathroom_fan
            data: {}
          - service: timer.start
            data: {}
            target:
              entity_id: timer.bathroom_light_timer
      - conditions:
          - condition: trigger
            id:
              - Bathroom Light Off
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: timer.bathroom_fan
      - conditions:
          - condition: trigger
            id:
              - Bathroom Fan Delay
        sequence:
          - type: turn_off
            device_id: c64baab5b4e966fd414cdcdfbc5569de
            entity_id: 6ba769696ca9b3f1e738649ebc45b1e3
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - Bathroom Fan turned off
        sequence:
          - service: timer.cancel
            target:
              entity_id:
                - timer.bathroom_fan
                - timer.bathroom_light_timer
            data: {}
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Bathroom Light Off
              - condition: not
                conditions:
                  - condition: state
                    entity_id: timer.bathroom_light_timer
                    state: idle
        sequence:
          - type: turn_off
            device_id: c64baab5b4e966fd414cdcdfbc5569de
            entity_id: 6ba769696ca9b3f1e738649ebc45b1e3
            domain: switch
          - service: timer.cancel
            target:
              entity_id:
                - timer.bathroom_fan
            data: {}
mode: single

If I’m reading this right, then you need a new trigger for timer.bathroom_light_timer going to idle and that should be added to the conditional for your broken part.

The rule is only going to evaluate whether or not the timer is done when the light is turned off. So, if the light is turned off but that timer is still running, then that part of the rule will never run.

I could be missing something else and that might be a red herring though…that’s a pretty convoluted rule.

Yes I thought that too. I added it earlier while testing but removed it as it did not work. Will try it again. Do you think state, trigger or something else. The trigger to check really is the light being turned off so not sure.

Update:
I disabled the original problem code above and added
Bathroom Light Timer Ended as a trigger in triggers and tried this a few ways.

As per screenshot I used the 5 minute timer ending as the trigger and did a check on the light is off. It works yay but it does not work the other way. So If I take the trigger to be the light being turned off and check if the timer is Active or Idle it does not work. Looks like a problem with Automations…