Formattig output based of number of lights on

Hi,
I need help with this situation. I am trying to format output of my template card based on number of ligths that is on. In my language we are using different form of word for different number of entitities.
if there is 0 or more then 4 we are using one form, if 1 another form, 2-4 another form.
I am trying to format output based on this using if but still getting wrong output syntax wise, could you please help me where the mistake is?

chips:
      - type: template
        icon: mdi:lightbulb
        content: >-
          {% set pocet =
          expand('light.all_lights')|selectattr('state','eq','on')|list|count %}
          {% if pocet == 1 set slovo = 'svetlo' %}
          {% elif 5>pocet>1 set slovo = 'svetla' %}
          {% else set slovo ='svetiel' %}
          {% endif %}
          {{' {} {} vypnúť'.format(pocet, slovo) }}
chips:
      - type: template
        icon: mdi:lightbulb
        content: >-
          {% set pocet = expand('light.all_lights')|selectattr('state','eq','on')|list|count %}
          {% set slovo = 'svetlo' if pocet == 1 else 'svetla' if 1 < pocet < 5 else 'svetiel' %}
          {{' {} {} vypnúť'.format(pocet, slovo) }}

So I have figured it out, this code works. My question is, is there a way to make it simpler? Write in in one block instead of starting each line with {% ?

- type: template
        icon: mdi:lightbulb
        content: >-
          {% set pocet =
          expand('light.all_lights')|selectattr('state','eq','on')|list|count %}
          {% if pocet == 1 %}
          {% set slovo = 'svetlo' %}
          {% elif 5>pocet>1 %} 
          {% set slovo = 'svetlá' %}
          {% else %}
          {% set slovo = 'svetiel' %} 
          {% endif %} {{' Vypnúť {} {} '.format(pocet, slovo) }}

Thank you, you are a genius.
Still learning, but I find this topics with practical problems and commented code much more helpful than reading a documentation.

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.