Need help TS automation code

Hi,

hopefully someone can help with the the following automation.

I am not getting to it, target is, if all of the lights are of, do NOT trigger, if at least one light is on, trigger the hallway light.

- alias: hallway on at motion, 21.30 - 23.59
  trigger:
    platform: state
    entity_id: sensor.hallway_motion_sensor
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions: 
    - condition: time
      after: '21:31'
      before: '23:59'
    - condition: template
      value_template: "{{ not is_state('light.sessel', 'off') }}"
    - condition: template
      value_template: "{{ not is_state('light.sofa', 'off') }}"
    - condition: template
      value_template: "{{ not is_state('light.unten', 'off') }}"
    - condition: template
      value_template: "{{ not is_state('light.leiste', 'off') }}"
    - condition: template
      value_template: "{{ not is_state('switch.bett', 'off') }}"
  action:
    service: light.turn_on
    entity_id:
    - light.rechts
    - light.links
    data:
      brightness: 80

Currently, even if the ‘switch.bett’ is on, it does not trigger the hallway, even it should.

Maybe someone does have a complete other approach at this automation, I am open for all.

Thanks in advance.

Why not put the lights in a group, then you can check the state of the group - which will be on if any of the lights are on?

group:
  my_lights:
    name: My lights
    view: false
    entities:
      - light.sessel
      - light.sofa
      - light.unten
      - light.leiste
      - switch.bett

automation:
  - alias: hallway on at motion, 21.30 - 23.59
    trigger:
      platform: state
      entity_id: sensor.hallway_motion_sensor
      from: 'off'
      to: 'on'
    condition:
      condition: and
      conditions: 
      - condition: time
        after: '21:31'
        before: '23:59'
      - condition: state
        entity_id: group.my_lights
        state: 'on'
    action:
      service: light.turn_on
      entity_id:
      - light.rechts
      - light.links
      data:
        brightness: 80

Hi,

this is a very good idea, I did not thought about that.

AND, this is working fine, exactly as I expected it.

Thank you a lot !