Basically this is what the card shows right now. There are four total lights on in the house.
But if there are no lights on, it just shows the same thing with no “4”, so it looks as though it’s an indicator that there are “lights on”, when there aren’t any on.
You should have started with a naming a card what you are going to use.
What is that “custom template card” exactly?
What is a desired look in case of no lights?
Post a picture with a draft (MS Paint or whatever).
Ideally, I want the card to disappear when the value is zero. But I’d be happy if it just said “0” or “None”. Like a conditional card, but because it’s a template, I’m not sure how to do the conditional part. I’m experimenting at the moment with different ideas.
Know nothing about mushroom cards.
But if you need to have this card disappeared - then there are at least 2 options:
The mushroom card is placed inside a conditional card
So far, a standard conditional card does not support templates to decide whether to show an internal card or not. So, you may use a custom:state-switch card which does support templated conditions like “if number of lights >= 1 - then condition is TRUE”.
Apply a card-mod style for the mushroom card like “if number of lights >= 1 - then display: none”.
Thanks, but this functions pretty much the same as my original card.
I think I’d be happy if there was a way to take my original code, and modify it so it displayed “None” if the value was “0”. It’s probably the simplest solution to this problem. My main concern is not confusing the wife by seeing a button that just says “Lights On” when the value is “0”, because she may think it’s telling her there are lights on.
If it said “None”, it would be clearer to anyone looking at it.
I tested this out and it works flawlessly, thank you!
I tried to implement some form of the reply from @pedolsky above to change the icon color depending on the state, but I can’t get it to work. If I paste…
icon_color: |
{% set lights=states.light|selectattr('state','eq','on')|rejectattr('entity_id', 'search', 'lights')|list|length %}
{{ 'amber' if lights > 0 else 'disabled' }}
into the icon color field it doesn’t change appropriately. I imagine I have to paste some form of code into the “primary” and “secondary” sections to set the icon and color?
It’s fine as it is, but that’s the only thing keeping it from being perfect. Ideally, I’d like it to change between this…
This creates a card that counts the number of current lights on in the house while excluding light groups. The only caveat is to make sure your entities for light groups are named with “lights”, and individual lights are named “light” without the “s”. This matters, for example, if you have “vanity lights” of a set of multiple bulbs that you want treated as a single light. If you name them “vanity lights” they will be excluded because of the “s”. Just stick to some naming conventions, and this works beautifully to let you know if you left any lights on somewhere…