Icon Based on State

type: custom:mushroom-entity-card
entity: sensor.lader_laptop
name: Lader
fill_container: true
primary_info: state
secondary_info: none
icon: |
  {% if is_state('sensor.lader_laptop', 'Connected') %}
    mdi:power-plug-outline
  {% elif is_state('sensor.lader_laptop', 'Disconnected') %}
    mdi:power-plug-off-outline
  {% else %}
    mdi:help-circle-outline  # Fallback icoon als de status onbekend is
  {% endif %}
icon_color: |
  {% if is_state('sensor.lader_laptop', 'Connected') %}
    green
  {% elif is_state('sensor.lader_laptop', 'Disconnected') %}
    red
  {% else %}
    gray
  {% endif %}

What’s wrong in the code, I’ve tried everything
No Icon shows

The Mushroom Entity Card does not accept templates. Use the Mushroom Template card instead.

A heads up… Please post your code using the forum standards

:one::one: Format it properly

When sharing the code, share it as text and not an image. When you do that, remember that spacing is critical in YAML, and if you just throw the code on the page then it’ll look ugly and nobody will know if the problem is because of spacing. We need you to use code blocks and appropriate markup.

sorry, for posting it wrong
Can I use the same code or should I approach this completely differently?

Yes

type: custom:mushroom-template-card
primary: Example
secondary: Template
icon: |
  {% if is_state('sensor.lader_laptop', 'Connected') %}
    mdi:power-plug-outline
  {% elif is_state('sensor.lader_laptop', 'Disconnected') %}
    mdi:power-plug-off-outline
  {% else %}
    mdi:help-circle-outline 
  {% endif %}
icon_color: |
  {% if is_state('sensor.lader_laptop', 'Connected') %}
    green
  {% elif is_state('sensor.lader_laptop', 'Disconnected') %}
    red
  {% else %}
    gray
  {% endif %}

I only miss the status in primary, do I have to set that via template?

I’m new to templates and YAML. Previously, I used to do everything through the visual editor.

Yes something like this :arrow_down:

primary: "{{states('sensor.living_room_humidity')}}%"

or for you

primary: "{{states('sensor.lader_laptop)}}"

1 Like

Thanks for helping me

1 Like