If count of template is zero, do mot show the digit zero

I have the following template that gives me the count of lights that are on in a group .

{{ expand(states.group.all_living) | selectattr( 'state', 'eq', 'on') | list | count }}

It works great, but if the count is zero, I would like not to show the digit zero in the card. How can I do this?


{% set x = expand('group.all_living') | selectattr('state', 'eq', 'on') | list | count %}
{{ iif(x > 0, x, '') }}

Awesome!! Thanks!

1 Like

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.