Need help with some coding (Light count)

I’m building my first dashboard new to HA, and currently I have a light bulb Icon (Using template card) I sent a domain to count how many lights are on in the house.

Most of my light switches are controlled by Shelly 1PM plus.
However I do have 3 light switches that are Lightwave.

the problem I’m having is the domain is looks for lights, and lightwave name the LEDs on the light switches as also Lights so it falsely counts these lights too.

The entity for a shelly is
light.ls_barnhallway_switch_0

The entity for the lightwave light switch LEDs is
light.light_switch_bedroom_1_led

My code I’m using to count lights as follows:

So my question is how do I get it to excluded the count of the LED on the light switch plate?

So it gets the right count of lights being on.

Any help will be super appreciated.

Reject any light entity whose object_id ends with the string _led.

{{ states.light | selectattr('state', 'eq', 'on') | rejectattr('object_id', 'search', '_led$') | list | count }} lights on
1 Like

Thank you so much, I need to learn coding ! been trying to solve this for the last two days…

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.