Markdown Card - Change color and replace text

Hello there,

i am experimenting with the HACS Integration “waste collection schedule” and a markdown card. I have this so far:

# Abfall
***
Papier: **in {{ states.sensor.abfallpapier.state}} Tagen** am {{ states.sensor.abfallpapier.attributes|first
|as_timestamp|timestamp_custom("%d.%m.%Y")}} 

Restmüll: **in {{ states.sensor.abfallrestmuell.state}} Tagen** am {{ states.sensor.abfallrestmuell.attributes|first
|as_timestamp|timestamp_custom("%d.%m.%Y")}} 

Biomüll: **in {{ states.sensor.abfallbiomuell.state}} Tagen** am {{ states.sensor.abfallbiomuell.attributes|first
|as_timestamp|timestamp_custom("%d.%m.%Y")}} 

Problemmüll: **in {{ states.sensor.abfallproblemmuell.state}} Tagen** am {{ states.sensor.abfallproblemmuell.attributes|first
|as_timestamp|timestamp_custom("%d.%m.%Y")}} 

I want to add two additional things:

  1. I want to change the color of the whole line to red if the “states.sensor.abfallproblemmuell.state” has the value <2 (like on the screenshot with “Restmüll”)

  2. at the same time replace the words “In 1 Tagen” with “morgen” (I tried |replace (“In 1 Tagen”; “morgen”) but because of the existing sensor values in this text thats too difficult for me)

Can someone with a deeper understanding of Markdown Cards please help me out with this one?

Thank you very much!

1 Like

For you second point, you can try:

Problemmüll:  {% if states('sensor.abfallproblemmuell')=='1' %} **morgen** {% else %} **in {{ states('sensor.abfallproblemmuell') }} Tagen**{%endif %} am {{ states.sensor.abfallproblemmuell.attributes|first|as_timestamp|timestamp_custom("%d.%m.%Y")}}  

I have done this with buttons:
grafik

If it is just one or zero days to go, the button is highlighted in red.

Code:

type: custom:button-card
entity: sensor.abfall_restmull
show_entity_picture: true
entity_picture: /local/img/Abfall_Rest.png
name: Restmüll
show_name: false
show_state: false
show_label: true
label: |
  [[[
    if (entity.state == 0)
    { return "Heute" }
    else if (entity.state == 1)
    { return "Morgen" }
    else
    { return "in " + entity.attributes.daysTo + " Tagen" }
  ]]]
styles:
  name:
    - font-size: 12px
  label:
    - font-size: 14px
  icon:
    - width: 70%
state:
  - value: 1
    operator: <=
    styles:
      card:
        - border-color: red
        - border-style: solid
        - border-width: 2px
      label:
        - font-weight: bold

Thank you very much :slight_smile: Now i have this… sadly still without the color…

Problemmüll:  {% if states('sensor.abfallproblemmuell')=='1' %} **morgen** {% elif states('sensor.abfallproblemmuell')=='0' %} **heute** {% else %} **in {{ states('sensor.abfallproblemmuell') }} Tagen**{%endif %} am {{ states.sensor.abfallproblemmuell.attributes|first|as_timestamp|timestamp_custom("%d.%m.%Y")}}

Thank you for the inspiration. Sadly i can’t use that code in Markdown. Maybe i will set up something like this in a couple of days! :slight_smile:

Like this?

<font color = {{'red' if states('sensor.abfallproblemmuell')|int < 3 else 'black'}}>
Problemmüll:  {% if states('sensor.abfallproblemmuell')=='1' %} **morgen** {% elif states('sensor.abfallproblemmuell')=='0' %} **heute** {% else %} **in {{ states('sensor.abfallproblemmuell') }} Tagen**{%endif %} am {{ states.sensor.abfallproblemmuell.attributes|first|as_timestamp|timestamp_custom("%d.%m.%Y")}}
</font>