Automation being triggered when toggling a input boolean

Hi,
I have an automation to turn on the lights when motion is detected, and I’m wanting to add a toggle to enable this automation. here’s what I’m trying to achieve:

input boolean is on:
the motion detector turns on the lights and they turn off after 15 minutes

input boolean is off:
the motion detector does not turn on the lights, however, the lights still turn off 15 minutes after motion is detected.

Ive setup the automation, however when the input boolean is turned off and then back on, something triggers light.lounge_lights and light.lounge_spanish_light to turn off, light.lounge_tree_light is not affected. I’m scratching my head as to why these lights are turning off.

here’s my automation:

alias: Auto Turn On Lounge Lights
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 89155ea325c74ec8b72be5ecd7b9c5a5
    entity_id: binary_sensor.lounge_motion_sensor
    domain: binary_sensor
condition: []
action:
  - if:
      - condition: state
        entity_id: input_boolean.auto_lounge_lights
        state: "on"
    then:
      - service: light.turn_on
        data: {}
        target:
          entity_id:
            - light.lounge_spanish_light
            - light.lounge_tree_light
      - if:
          - condition: time
            after: "22:30:00"
            before: "07:00:00"
        then:
          - service: light.turn_on
            data:
              brightness_pct: 10
            target:
              entity_id: light.lounge_lights
        else:
          - service: light.turn_on
            data:
              brightness_pct: 100
            target:
              entity_id: light.lounge_lights
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.lounge_lights
        - light.lounge_spanish_light
        - light.lounge_tree_light
mode: restart

It’s usually best to avoid long delays whenever possible, instead use a separate trigger for the ‘Off’ function.

alias: Auto Turn On Lounge Lights
description: ""
trigger:
  - platform: state
    id: Motion
    entity_id: binary_sensor.lounge_motion_sensor
    to: 'on'
    from: 'off'
  - platform: state
    id: No Motion
    entity_id: binary_sensor.lounge_motion_sensor
    to: 'off'
    from: 'on'
    for: '00:15:00'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: No Motion
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.lounge_lights
                - light.lounge_spanish_light
                - light.lounge_tree_light
      - conditions:
          - condition: trigger
            id: Motion
          - condition: state
            entity_id: input_boolean.auto_lounge_lights
            state: "on"
          - condition: time
            after: "22:30:00"
            before: "07:00:00"
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id:
                - light.lounge_spanish_light
                - light.lounge_tree_light
          - service: light.turn_on
            data:
              brightness_pct: 10
            target:
              entity_id: light.lounge_lights
    default:
          - condition: state
            entity_id: input_boolean.auto_lounge_lights
            state: "on"
          - service: light.turn_on
            data: {}
            target:
              entity_id:
                - light.lounge_spanish_light
                - light.lounge_tree_light
          - service: light.turn_on
            data:
              brightness_pct: 100
            target:
              entity_id: light.lounge_lights
mode: restart