Change icon depending on the first word in a string

Hello everyone,

I want to change the icon in a mushroom entity card depending on the first word in the state of the entity “sensor.muell_naechste_abholung”.

For example, the state is “Restmüll in 8 days”.

Where is the error in my code?
<

      - type: custom:mushroom-entity-card
        entity: sensor.muell_naechste_abholung
        name: Next garbage collection
        icon: |
          {% set d ={
          "Restmüll": "mdi:trash-can"',
          "Papiertonne": "mdi:trash-can-outline"',
          "Gelber": "mdi:recycle",
          "BioTonne": "mdi:flower-outline" 
          "Sonderabfall": "mdi:alert" 
          } %}
          {{ d.get(state(sensor.muell_naechste_abholung)|split(" ")[0]) }}
        fill_container: true
>

The error is your assumption that you can use templates in a mushroom entity card’s icon declaration.

You might be able to use that template in the sensor’s icon declaration which might then get picked up by the mushroom card.

There are a bunch of errors in your template, though. Try it in Developer Tools / Template first.

image

Here’s a fixed version:

{% set d = {
     "Restmüll": "mdi:trash-can",
     "Papiertonne": "mdi:trash-can-outline",
     "Gelber": "mdi:recycle",
     "BioTonne": "mdi:flower-outline", 
     "Sonderabfall": "mdi:alert" } %}
{{ d.get((states("sensor.muell_naechste_abholung").split(" "))[0]) }}