Turning off lights which a Automation has started

Hi Guys,

I am fairly new to HomeAssistant, I have a small home lab going for my learning and media consumption in my house, and I have a bunch of Sonoff Mini’s around the house that is flashed with Tasmota’s and added to HomeAssistant.

I run automation that turns on all the lights in the house around sunset, this automation also needs to turn off all the lights it turned on after 15 minutes, leaving those that were either turned on manually or through HA already before the automation. e.g. If I am sitting in the living room it’s already getting dark i and I instruct HA to turn on the living room light but all other room lights are off, they turn on via the automation, After 15 minutes have passed I need all rooms except the living room to be turned off.

Is this possible? Below is the code of the automation I am talking about.

alias: Magrib Azan
trigger:
  - platform: time_pattern
    seconds: '30'
condition:
  - condition: template
    value_template: '{{ now().time().strftime("%H:%M") == states.sensor.maghrib.state }}'
action:
  - if:
      - condition: device
        type: is_off
        device_id: 9d4e5f4451761cc4c278a7f0c3fe1448
        entity_id: switch.tasmota_2
        domain: switch
    then:
      - type: turn_on
        device_id: 9d4e5f4451761cc4c278a7f0c3fe1448
        entity_id: switch.tasmota_2
        domain: switch
  - if:
      - condition: device
        type: is_off
        device_id: af1e76ca8e8c4c04b3e1d07d0e38ed23
        entity_id: switch.bedroommainlight
        domain: switch
    then:
      - type: turn_on
        device_id: af1e76ca8e8c4c04b3e1d07d0e38ed23
        entity_id: switch.bedroommainlight
        domain: switch
  - if:
      - condition: device
        type: is_off
        device_id: 22a3e66ebb96c9250708088b2d67aa0d
        entity_id: switch.officemainlight
        domain: switch
    then:
      - type: turn_on
        device_id: 22a3e66ebb96c9250708088b2d67aa0d
        entity_id: switch.officemainlight
        domain: switch
  - if:
      - condition: device
        type: is_off
        device_id: 9d9c26c536e4a88ab54ed8d15dd67509
        entity_id: switch.diningfan
        domain: switch
    then:
      - type: turn_on
        device_id: 9d9c26c536e4a88ab54ed8d15dd67509
        entity_id: switch.diningfan
        domain: switch
  - service: media_player.volume_set
    data:
      volume_level: 1
    target:
      device_id:
        - 9fb1f93ea3f38907af42a0c3348e07ec
        - d6d44479977b1fb112a58b9ca4cb2767
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      device_id: fc104b57ce430460c5de60e1add722ba
  - service: media_player.play_media
    data:
      media_content_id: https://www.islamcan.com/audio/adhan/azan3.mp3
      media_content_type: audio/mp3
    target:
      entity_id:
        - media_player.allhomespeakers

Also is the above the best method to run the automation and light control, or is there a better method to control the lights through the above automation, like creating a scene or something?

Thanks in advance for your help and suggestions.