Where is the best way to configure a card (or template) that can change an icon as well?

Hi,

since a couple of hours I try to get a “somehow” nice card, that shows the door status of our garage.
I want to see the word “closed” if its closed “Open” if its open, and choose an different icon for closed/open.

I have HA 2024.2.3 running with IMHO all needed Extensions (default installation plus addons), but maybe I need to check for one or the other extension that supports my problem.

I went to Setup → helper and used the template.

I assumed I could there use

value: >
  {% if is_state('binary_sensor.shelly1minig3_84fce636a7a0_input_0_input', 'on') %}
    zu
  {% else %}
    offen
  {% endif %}
icon: >  
  {% if is_state('binary_sensor.shelly1minig3_84fce636a7a0_input_0_input', 'on') %}
    mdi:garage
  {% else %}
    mdi:garage-open
  {% endif %}

But if the garage is e.g. closed it gives:

evalue: > zu icon: > mdi:garage

which “somehow” is what I wanted :slight_smile:

I than stayed with

{% if is_state('binary_sensor.shelly1minig3_84fce636a7a0_input_0_input', 'on') %}
  zu
{% else %}
  offen
{% endif %}

which is a start, but I definitely miss the icon change there.

I have the feeling that I have to wrap around some HTML/CSS/whatever “somehow”, that I see the icons, but I also think, that I am on the totally wrong track, if I want the Icon at the card changed as well.

I read thru some threads here, but I can’t avoid the feeling, that I am doing something basic very wrong.
I also tried to use the developer → template but this gives similar examples than above,. I think I am missing a big understandingh, but cannot find a good way how to implement such a IMHO simple thing.

I really assume, that this is an rtfm, so a pointer for a newby to “tfm” would really make me “r” it.

So my question is:
is the start with the Setup → helper the right one, or do I have to start the whole thing with

custom_templates\garage.jinja

and learn the whole jinja templatig. Or is there an easier start for someone new to HA?
many thanks for your help
Juergen

Just change the device class of your original device.

Which card are you using? What template is that?

For my garage door, I created a switch template which takes its state from the reed sensor (door status) and supports different icons based on its state. I added this switch to the dashboard using a button card which also supports tap/double-tap/hold actions and overrides the icon colors using the theme customization.

If you want to use this, I can share the code/configuration etc. with you.