Trying to show how many lights are on

binary_sensor:
  - name: Ein Licht an
    device_class: light
    unique_id: einlichtan_status
    state: "{{ is_state('switch.00161a499cb9a2_2', 'on') or
      is_state('switch.00161a499cb9a2_18', 'on') or
      is_state('light.00169be9a0f15a_10', 'on') or
      is_state('switch.00161a499cb98e_26', 'on') or
      is_state('light.led_wohnzimmer', 'on') or
      is_state('switch.00161a499cb98e_6', 'on') or
      is_state('light.ambilight', 'on') or
      is_state('switch.00161a499cb98e_2', 'on') or
      is_state('light.00169be992f89f_10', 'on') or
      is_state('switch.00161a499cb9a2_10', 'on') or
      is_state('switch.00161a499cb98e_10', 'on') or
      is_state('light.ambilight_arbeitszimmer', 'on') or
      is_state('input_boolean.helfer_spiegelschrank', 'on') or
      is_state('light.led_badezimmer_oben', 'on') or
      is_state('light.led_badezimmer_unten', 'on') or
      is_state('switch.00161a499cb9a2_30', 'on') or
      is_state('light.led_schlafzimmer', 'on') or
      is_state('light.deckenventilator', 'on') or
      is_state('light.00169be992f89f_2', 'on') or
      is_state('light.00169be992f89f_6', 'on') or
      is_state('light.00169be9a0f15a_6', 'on') or
      is_state('light.00169be9a0f15a_2', 'on') or
      is_state('switch.00161a499cb9a2_14', 'on') }}"
    attributes:
      gesamte_lichter: >-
        {{ [
          is_state('switch.00161a499cb9a2_2', 'on'),
          is_state('switch.00161a499cb9a2_18', 'on'),
          is_state('light.00169be9a0f15a_10', 'on'),
          is_state('switch.00161a499cb98e_26', 'on'),
          is_state('light.led_wohnzimmer', 'on'),
          is_state('switch.00161a499cb98e_6', 'on'),
          is_state('light.ambilight', 'on'),
          is_state('switch.00161a499cb98e_2', 'on'),
          is_state('light.00169be992f89f_10', 'on'),
          is_state('switch.00161a499cb9a2_10', 'on'),
          is_state('switch.00161a499cb98e_10', 'on'),
          is_state('light.ambilight_arbeitszimmer', 'on'),
          is_state('input_boolean.helfer_spiegelschrank', 'on'),
          is_state('light.led_badezimmer_oben', 'on'),
          is_state('light.led_badezimmer_unten', 'on'),
          is_state('switch.00161a499cb9a2_30', 'on'),
          is_state('light.led_schlafzimmer', 'on'),
          is_state('light.deckenventilator', 'on'),
          is_state('light.00169be992f89f_2', 'on'),
          is_state('light.00169be992f89f_6', 'on'),
          is_state('light.00169be9a0f15a_6', 'on'),
          is_state('light.00169be9a0f15a_2', 'on'),
          is_state('switch.00161a499cb9a2_14', 'on')
        ] | count }}
      aktive_lichter: >-
        {{ [
          is_state('switch.00161a499cb9a2_2', 'on'),
          is_state('switch.00161a499cb9a2_18', 'on'),
          is_state('light.00169be9a0f15a_10', 'on'),
          is_state('switch.00161a499cb98e_26', 'on'),
          is_state('light.led_wohnzimmer', 'on'),
          is_state('switch.00161a499cb98e_6', 'on'),
          is_state('light.ambilight', 'on'),
          is_state('switch.00161a499cb98e_2', 'on'),
          is_state('light.00169be992f89f_10', 'on'),
          is_state('switch.00161a499cb9a2_10', 'on'),
          is_state('switch.00161a499cb98e_10', 'on'),
          is_state('light.ambilight_arbeitszimmer', 'on'),
          is_state('input_boolean.helfer_spiegelschrank', 'on'),
          is_state('light.led_badezimmer_oben', 'on'),
          is_state('light.led_badezimmer_unten', 'on'),
          is_state('switch.00161a499cb9a2_30', 'on'),
          is_state('light.led_schlafzimmer', 'on'),
          is_state('light.deckenventilator', 'on'),
          is_state('light.00169be992f89f_2', 'on'),
          is_state('light.00169be992f89f_6', 'on'),
          is_state('light.00169be9a0f15a_6', 'on'),
          is_state('light.00169be9a0f15a_2', 'on'),
          is_state('switch.00161a499cb9a2_14', 'on')
        ] | select('equalto', true) | list | count }}

Is there a question or advice associated with all this code?

Its Working fine, just a Solution/Sample :slight_smile:

There is something similar further up this post

sensor:
  - platform: template
    sensors:
     lights_on:
       friendly_name: 'Lights ON'
       value_template: >
       
          {% set lights = [
          states.light.pc_lights,
          states.light.bed_lights,
          states.light.tv_lights,
          states.light.night_stands,
          states.light.bathroom_lights,
          states.light.server_light,
          states.light.closet,
          states.light.hallway_lights,
          ] %}
          {{ lights | selectattr('state','eq','on') | list | count }}