Lovelace card template problem

Hi guys, im new in programming etc, but im giveing a try.
I am trying to create an entities card for waste collection but i would to display if the collection is today, tomorrow or in n days.

If i use horizontal-stack and create a single card it works like a charm, but i don’t like it.

I use garbage collection integration from HACS
the sensor return 0 if collection is today, 1 if tomorrow and 2 if other days.
so i tryed to do this:

- card:
        title: Spazzatura
        type: entities
        entities:
          - entity: sensor.plastica
            state_template: >-
                {% if state("sensor.plastica") == 0 %} Oggi 
                {% elif state("sensor.plastica") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}
          - entity: sensor.umido
            state_template: >-
                {% if state("sensor.umido") == 0 %} Oggi 
                {% elif state("sensor.umido") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.umido", "days") }} giorni {% endif %}
          - entity: sensor.secco
            state_template: >-
                {% if state("sensor.secco") == 0 %} Oggi 
                {% elif state("sensor.secco") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.secco", "days") }} giorni {% endif %}

Im using card templater and card tools, but in this case i cant undestand where put

type: 'custom:card-templater'

Tnx in advice and sorry for my really bad english.

Daniele

try this:

    - type: 'custom:card-templater'
      card:
        title: Spazzatura
        type: entities
        entities:
          - entity: sensor.plastica
            state_template: >-
                {% if state("sensor.plastica") == 0 %} Oggi 
                {% elif state("sensor.plastica") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}
          - entity: sensor.umido
            state_template: >-
                {% if state("sensor.umido") == 0 %} Oggi 
                {% elif state("sensor.umido") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.umido", "days") }} giorni {% endif %}
          - entity: sensor.secco
            state_template: >-
                {% if state("sensor.secco") == 0 %} Oggi 
                {% elif state("sensor.secco") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.secco", "days") }} giorni {% endif %}

I didn’t look at the templates to see if they were valid. I just looked at answering the question about how to format the custom card.

Unfortunatly doesen’t work.

Also tryed to change code in

- type: 'custom:card-templater'
        card:
           title: Spazzatura
           type: entities
           entities:
             - entity: sensor.plastica
               state_template: >-
                {% if state_attr("sensor.plastica", "days") == 0 %} Oggi 
                {% elif state_attr("sensor.plastica", "days") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}
             - entity: sensor.umido
               state_template: >-
                {% if state_attr("sensor.umido", "days")== 0 %} Oggi 
                {% elif state_attr("sensor.umido", "days") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.umido", "days") }} giorni {% endif %}
             - entity: sensor.secco
               state_template: >-
                {% if state_attr("sensor.secco", "days") == 0 %} Oggi 
                {% elif state_attr("sensor.secco", "days") == 1  %} Domani
                {% else %} Tra {{ state_attr("sensor.secco", "days") }} giorni {% endif %}

Same result

states and atttributes are almost always returned as strings in a template.

so, for the templates to work you need to either convert the strings to a number by adding the “| int” filter or encase the numbers in quotes to change them into strings.

example:

{% if state_attr("sensor.plastica", "days") | int == 0 %} Oggi 
{% elif state_attr("sensor.plastica", "days") | int == 1  %} Domani
{% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}

or:

{% if state_attr("sensor.plastica", "days") == "0" %} Oggi 
{% elif state_attr("sensor.plastica", "days") == "1"  %} Domani
{% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}

try that and see if it gets you somewhere.

I haven’t looked at the docs for the card-templater so I don’t know if the template is correct for that type of card.

It doesent work
here the link to card templater

state_template should be used under the entities option of the card-templater card itself, not the nested card. Something like this:

- type: 'custom:card-templater'
  card:
    title: Spazzatura
    type: entities
    entities:
      - entity: sensor.plastica
      - entity: sensor.umido
      - entity: sensor.secco
  entities:          
    - entity: sensor.plastica
      state_template: >-
        {% if state_attr("sensor.plastica", "days") == 0 %} Oggi 
        {% elif state_attr("sensor.plastica", "days") == 1  %} Domani
        {% else %} Tra {{ state_attr("sensor.plastica", "days") }} giorni {% endif %}
    - entity: sensor.umido
      state_template: >-
        {% if state_attr("sensor.umido", "days")== 0 %} Oggi 
        {% elif state_attr("sensor.umido", "days") == 1  %} Domani
        {% else %} Tra {{ state_attr("sensor.umido", "days") }} giorni {% endif %}
    - entity: sensor.secco
      state_template: >-
        {% if state_attr("sensor.secco", "days") == 0 %} Oggi 
        {% elif state_attr("sensor.secco", "days") == 1  %} Domani
        {% else %} Tra {{ state_attr("sensor.secco", "days") }} giorni {% endif %}

Really tnx man, it works!