Trying to show how many lights are on

Ensure you have an editor installed in your add-ons

image

Editor

find this file
image

add this to the bottom of the file to count all lights and save the file. Restart HA to create the sensor.

template:
 - sensor:
     - name: "Total Lights Count Template"
       state: "{{ states.light | rejectattr('attributes.entity_id', 'defined') | selectattr('state', 'eq', 'on') | list | count }}"

add this with a manual list of lights that you want to count if you don’t want all the lights counted. You don’t need both added, the second can be helpful if you group lights as a single entity.

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 }}          

There are multiple ways so you may receive additional advice, but this works. You do have to define the lights to get a real-time count. Both of these methods will do that.

9 Likes