We have automated the lights to turn off when watching movies. This works good most of the time, but then we are going through the picture folder on Kodi (with some short movies) it triggers the light off and on again, resulting in flickering of the lights. The solution is to set a condition for media duration so it doesn’t triggers the light on/off.
Adapt to your need.

Automation:

# Media playing evening - living room media center
- alias: Media playing evening - living room media center
  id: media_playing_evening_living_room_media_center
  trigger:
  - platform: state
    entity_id: input_boolean.test
    to: 'on'
  - platform: state
    entity_id: media_player.living_room_androidtv
    to: 'playing'
  - platform: state
    entity_id: media_player.living_room_kodi
    to: 'playing'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: group.all_people
      state: 'home'
    - condition: numeric_state
      entity_id: sensor.garden_illuminance_lux
      below: 200
  action:
  - delay: '00:00:05'
  - choose:
# Choice 0
    - conditions:
        - condition: and
          conditions:
            - condition: template
              value_template: >
                {{ (state_attr('media_player.living_room_kodi', 'media_duration') | float > 600 )}}
            - condition: state
              entity_id: timer.kitchen_normal
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_dark_mode
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_normal
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_max
              state: 'idle'
      sequence:
      - service: scene.turn_on
        entity_id: scene.living_room_media
      - service: timer.cancel
        entity_id: timer.1st_floor_motion
      - service: homeassistant.turn_off
        entity_id: media_player.kitchen_radio
      - service: homeassistant.turn_off
        entity_id: switch.1st_floor_musiccast
# Choice 1
    - conditions:
        - condition: and
          conditions:
            - condition: template
              value_template: >
                {{ (state_attr('media_player.living_room_androidtv', 'media_duration') | float > 600 )}}
            - condition: state
              entity_id: timer.kitchen_normal
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_dark_mode
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_normal
              state: 'idle'
            - condition: state
              entity_id: timer.living_room_max
              state: 'idle'
      sequence:
      - service: scene.turn_on
        entity_id: scene.living_room_media
      - service: timer.cancel
        entity_id: timer.1st_floor_motion
      - service: homeassistant.turn_off
        entity_id: media_player.kitchen_radio
      - service: homeassistant.turn_off
        entity_id: switch.1st_floor_musiccast