Mushroom couleur icone selon l'état

Mon problème

Bonjour,
Je souhaite que l’icone change de couleur suivant si off ou on mais avec Mushroom. J’arrive bien à le faire avec HA mais par Mushroom impossible.
J’ai testé plusieurs code trouvé je n’y arrive pas.
Pouvez-vous m’aider ?
Merci

Voici tous les codes que j’ai testé:

if (state === 'on') return '#ff0000'; else return '#00b300';"

    icon_color: | -
      {% if states('binary_sensor.nest_protect_hallway_smoke_status') == 'On' %}
        red
      {% elif states('binary_sensor.nest_protect_hallway_smoke_status') == 'Off' %}
        green
      {% else %}
        red
      {% endif %}
icon_color: |-
  {% if is_state ('binary_sensor.nest_protect_hallway_smoke_status', 'on') %}
   red
  {% else %}
   green
  {% endif %}
icon_color: "{{ 'green' if states('binary_sensor.nest_protect_hallway_smoke_status') == 'off' else 'red' }}"

Salut @sebr

Là t’es sur une carte « tile », carte que Piitaya a intégré « officiellement » à HA bien après avoir créé « Mushroom » et après avoir rejoint la team « Nabu Casa ». Et on ne peut pas y appliquer de template.

Pour modifier les couleurs tu as 2 solutions :

1- Jouer avec card-mod, sur cette carte.
2- Prendre les cartes « mushroom » depuis HACS.

Avec les cartes « mushroom » d’hacs tu pourras le faire avec « mushroom-template-card », le + de cette carte c’est que tu peux personnaliser vraiment à fond. Et proprement, puisqu’elle est prévue pour ça :stuck_out_tongue:

Cas N°1 :

type: tile
entity: binary_sensor.mvt_escalier
card_mod:
  style: |
    ha-card {     
      {% if is_state('binary_sensor.mvt_escalier','on') %}
      --tile-color: red !important;
      {% else %}
      --tile-color: lawngreen !important;
      {% endif %}      
    }

image

Cas N°2 :

type: custom:mushroom-template-card
entity: binary_sensor.mvt_escalier
primary: Escalier
secondary: |
  {% if is_state(config.entity,'on') %}
    Détecté
  {% else %}
    Ras
  {% endif %}
icon: |
  {% if is_state(config.entity,'on') %}
    mdi:motion-sensor
  {% else %}
    mdi:motion-sensor-off
  {% endif %}
icon_color: |
  {% if is_state(config.entity,'on') %}
    deep-orange
  {% else %}
    cyan
  {% endif %}        
fill_container: true
tap_action:
  action: more-info
card_mod:
  style: |
    :host {
      --mush-icon-size: 48px;
    }
    mushroom-shape-icon {
      --shape-color: transparent !important;
    }
    ha-card {
      background: transparent;
      box-shadow: none;
    }

image

Voilà à toi de faire ton choix :wink:

Salut, ah en effet j’ai du me tromper en cherchant ma carte ! Merci de ta réponse.

Merci cela fonctionne mais pas pour mettre 3 entités dans la même ligne. Dans le code du Cas 2 il y a que ton escalier et pas le parking ou ton salon.
Merci.

Oui en effet, dans le screen il s’agit d’une carte « grid » + les mushroom :

type: custom:mod-card
card_mod:
  style: |
    ha-card {
      background-color: rgba(10,10,10,0.4);
      box-shadow: var( --ha-card-box-shadow, 0px 2px 1px -1px rgba(255, 255, 255, 0.2), 0px 1px 1px 0px rgba(255, 255, 255, 0.14), 0px 1px 3px 0px rgba(255, 255, 255, 0.12) ); 
    }
card:
  type: grid
  square: false
  columns: 3
  cards:
    - type: custom:mushroom-template-card
      entity: binary_sensor.mvt_escalier
      primary: Escalier
      secondary: |
        {% if is_state(config.entity,'on') %}
          Détecté
        {% else %}
          Ras
        {% endif %}
      icon: |
        {% if is_state(config.entity,'on') %}
          mdi:motion-sensor
        {% else %}
          mdi:motion-sensor-off
        {% endif %}
      icon_color: |
        {% if is_state(config.entity,'on') %}
          deep-orange
        {% else %}
          cyan
        {% endif %}        
      fill_container: true
      tap_action:
        action: more-info
      card_mod:
        style: |
          :host {
            --mush-icon-size: 48px;
          }
          mushroom-shape-icon {
            --shape-color: transparent !important;
          }
          ha-card {
            background: transparent;
            box-shadow: none;
          }
    - type: custom:mushroom-template-card
      entity: binary_sensor.mvt_parking
      primary: Parking
      secondary: |
        {% if is_state(config.entity,'on') %}
          Détecté
        {% else %}
          Ras
        {% endif %}
      icon: |
        {% if is_state(config.entity,'on') %}
          mdi:motion-sensor
        {% else %}
          mdi:motion-sensor-off
        {% endif %}
      icon_color: |
        {% if is_state(config.entity,'on') %}
          deep-orange
        {% else %}
          cyan
        {% endif %}
      fill_container: true
      tap_action:
        action: more-info
      card_mod:
        style: |
          :host {
            --mush-icon-size: 48px;
          }
          mushroom-shape-icon {
            --shape-color: transparent !important;
          }
          ha-card {
            background: transparent;
            box-shadow: none;
          }
    - type: custom:mushroom-template-card
      entity: binary_sensor.mvt_salon
      primary: Salon
      secondary: |
        {% if is_state(config.entity,'on') %}
          Détecté
        {% else %}
          Ras
        {% endif %}
      icon: |
        {% if is_state(config.entity,'on') %}
          mdi:motion-sensor
        {% else %}
          mdi:motion-sensor-off
        {% endif %}
      icon_color: |
        {% if is_state(config.entity,'on') %}
          deep-orange
        {% else %}
          cyan
        {% endif %}
      fill_container: true
      tap_action:
        action: more-info
      card_mod:
        style: |
          :host {
            --mush-icon-size: 48px;
          }
          mushroom-shape-icon {
            --shape-color: transparent !important;
          }
          ha-card {
            background: transparent;
            box-shadow: none;
          }     

1 « J'aime »

Bonjour !
J’ai plusieurs chips dans un mushroom-chips-card dont une entity où j’avais ajouté un style :

type: custom:mushroom-chips-card
chips:
  - type: entity
    entity: input_boolean.presence_rio
    use_entity_picture: false
    double_tap_action:
      action: none
    tap_action:
      action: toggle
    hold_action:
      action: none
    card_mod: null
    style: |
      ha-card {
      {% if states('input_boolean.presence_rio', 'on') %}
        color: green;
      {% else %}
        color: grey;
      {% endif %}
      }

Suite à la mise à jour de card-mod quelle est la bonne pratique dans ce cas ?
J’ai testé comme cela mais cela ne fonctionne pas :

type: custom:mushroom-chips-card
chips:
  - type: entity
    entity: input_boolean.presence_rio
    use_entity_picture: false
    double_tap_action:
      action: none
    tap_action:
      action: toggle
    hold_action:
      action: none
    card_mod:
      style: |
        ha-card {
        {% if states('input_boolean.presence_rio', 'on') %}
          color: green;
        {% else %}
          color: grey;
        {% endif %}
        }

Après avoir farfouillé ici : https://github.com/piitaya/lovelace-mushroom/blob/main/docs/cards/template.md
J’ai trouvé cette solution, qui fonctionne, en passant par une chip template :

type: custom:mushroom-chips-card
chips:
  - type: template
    entity: input_boolean.presence_rio
    icon: mdi:cat
    icon_color: |-
      {% if states('input_boolean.presence_rio', 'on') %}
        green
      {% else %}
        grey
      {% endif %}
    content: |-
      {% if states('input_boolean.presence_rio', 'on') %}
        Présent
      {% else %}
        Absent
      {% endif %}

Salut @Hankey71

Voir si une chips de type « template » serait plus simple ?

Exemple :

type: custom:mushroom-chips-card
chips:
  - type: template
    entity: input_boolean.plex_play_music
    icon_color: |-
      {% if is_state(config.entity, 'on') %}
        cyan        
      {% else %}
        deep-orange
      {% endif %}
    icon: mdi:plex
    content: Plex music {{ states(config.entity) }}
    double_tap_action:
      action: none
    tap_action:
      action: more-info
    hold_action:
      action: none

image

image

[EDIT] j’avais pas vu ton dernier post :stuck_out_tongue:

Yes ! Merci pour la réponse !
Je cherchais en même temps de mon côté et c’est ce que j’avais trouvé !

1 « J'aime »