Textzustände farblich darstellen

Ich möchte zB bei einem Fensterkontakt, dass der Zustand “Geschlossen” und “offen” unterschiedliche Farben haben.

Geschlossen grün
Offen rot

card-mod ist installiert.

Das sind zu wenig Infos? Welche Karte nutzt du im Dashboard? Poste auch mal den Code dazu.

Hallo,
ich benutze die Entitätenkarte.

type: entities
entities:

  • entity: binary_sensor.dachflachenfenster
  • entity: binary_sensor.kuche
    title: Fenster
    state_color: true

Wie sirector schon richtig geschrieben hat, wäre gut zu wissen, welche Card Du benutzt. Ich mach das mit Mushroom-Cards z.B. so:

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    primary: Fenster-Bad
    entity: binary_sensor.fenster_bad_contact
    name: Fenster
    secondary: |
      {% if is_state('binary_sensor.fenster_bad_contact', 'off') %}
        Zu
      {% else %}
        Auf
      {% endif %}
    icon: |
      {% if is_state('binary_sensor.fenster_bad_contact', 'off') %}
        mdi:window-closed
      {% else %}
        mdi:window-open
      {% endif %}
    icon_color: |
      {% if is_state('binary_sensor.fenster_bad_contact', 'off') %}
        green
      {% else %}
        red
      {% endif %}
    tap_action:
      action: more-info

Hallo,
wenn ich den Code richtig interpretiere, ändert sich nur die Farbe des Icon.

Ich möchte, dass sich der Zustandstext in der Farbe ändert, in deinem Beispiel das Wort “Zu” bzw. “Anwesend”

Sowas bspw.?

type: custom:mushroom-template-card
primary: Fenster
entity: binary_sensor.fenster_bad_contact
secondary: >
  {% if is_state('binary_sensor.fenster_bad_contact', 'off') %} Geschlossen {% else %} Offen {%
  endif %} 
card_mod:
  style: |
    ha-card {
      {% if is_state('binary_sensor.fenster_bad_contact', 'off') %}
      --card-secondary-color: yellow;
      {% else %}
      --card-secondary-color: red;
      {% endif %};
    }

Hallo Soul,

genau das meinte ich. Dankeschön für die Lösung. :smiley:

1 „Gefällt mir“

Dann markiere es einfach als gelöst hier im Forum :wink: :crayon:=> erl. by HarryP

1 „Gefällt mir“