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.
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.