#Card displaying 2 lights on when only 1 is on

1 messages · Page 1 of 1 (latest)

barren obsidian
#

Hello,
I've been using home assistant for 2 years now and it's been really great.
I am having a problem with my custom card that shows how many lights are on.
When no lights are on it says 0 lights are on which is what i want, when I turn on a light, the value increases by 1, however when I turn on this light, it says that there are 2 lights on instead of 1.
I have provided screen shots of the card that displays my lights and the card that displays the number of lights on, and the custom card with the code that is running it.

Thanks!

drifting bridge
#

Is the light a member of a group? If so, the light will be counted as one and the group as a second. You can add a line to your template to exclude Groups. I forget the syntax off the top of my head but I can figure it out when I get home from work.

drifting bridge
#

rejectattr ('entity_id', 'in', integration_entities('group'))

type: custom:mushroom-chips-card
chips:
  - type: template
    icon: |-
      {% set domain = 'light' %}
      {% set count = states[domain]
        | selectattr ('state', 'eq', 'on')
        | selectattr ('entity_id', 'in', integration_entities('group'))
        | rejectattr ('entity_id', 'in', integration_entities('Demo'))
        | list | count %}
      {% if count > 0 %}
        mdi:lightbulb-on
      {% else %}
        mdi:lightbulb
      {% endif %}
    icon_color: |-
      {% set domain = 'light' %}
      {% set count = states[domain]
        | selectattr ('state', 'eq', 'on')
        | selectattr ('entity_id', 'in', integration_entities('group'))
        | rejectattr ('entity_id', 'in', integration_entities('Demo'))
        | list | count %}
      {% if count > 0 %}
        yellow
      {% else %}
        gray
      {% endif %}
    content: |-
      {% set domain = 'light' %}
      {% set count = states[domain]
        | selectattr ('state', 'eq', 'on')
        | rejectattr ('entity_id', 'in', integration_entities('group'))
        | rejectattr ('entity_id', 'in', integration_entities('Demo'))
        | list | count %}
      {% if count == 0 %}
        No lights on
      {% elif count == 1 %}
        1 light on
      {% else %}
        {{ count }} lights on
      {% endif %}
```Note: I also had to reject the Demo integration to prevent the template from showing those entities. Also, you can do the opposite of rejecting the Group entities and show *only* them as seen in the screenshot.
EDIT: Changed the IF statement for better context.
barren obsidian
#

Thanks so much