Lovelace/Markdown Card - Waste Collection as timestamp and "Days left"

Hi there.

Trying to improve my dashboard atm. I now included the waste_collection_schedule via HACS. I successfully configured it and now I want to create a Markdown card for the next collection.

This is what I have done right now.

Sensors:

 # next collection
  - platform: waste_collection_schedule
    name: "Nächste Abholung"
    value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'
  #next ohne Tage
  - platform: waste_collection_schedule
    name: "Nächste Abholung Tage"
    value_template: '{{ value.daysTo }}'
  # Nächste Restmüll-Abholung
  - platform: waste_collection_schedule
    name: "Restmüll"
    value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'
    types:
      - Hausmüll
  # Nächste Biomüll Abholung
  - platform: waste_collection_schedule
    name: "Biomüll"
    value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'
    types:
      - Biomüll
  # Nächste gelber-Sack Abholung
  - platform: waste_collection_schedule
    name: "Gelber Sack"
    value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'
    types:
      - Gelbe Tonne
  # Nächste Papiermüll Abholung
  - platform: waste_collection_schedule
    name: "Papier"
    value_template: '{{value.types|join(", ")}}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'
    types:
      - Papiertonne

Markdown Card

  {{ states.sensor.nachste_abholung.attributes.values() | first |
  replace("papier", "Papiermüll") | replace("gelbersack", "Gelber Sack") |
  replace("rest", "Restmüll") }}: {{ states.sensor.nachste_abholung.attributes | first | as_timestamp |
  timestamp_custom("%a, %d.%m.") }} (in ... )

After the last word “(in …)” I want to publish the days left for the next waste collection. Unfortunelty I am not able to do it.

Can you help me?

Thanks!

Any ideas?

Nonne? Still don’t have a clue.

I am not familiar with waste_collection_schedule. Can you maybe post a screenshot of your sensors output? You can find these under Developer tools > States. From what I understand now is that the state of the sensor is just today, tomorrow or x days ahead.

Also, using {{ states.sensor.nachste_abholung.attributes | first | as_timestamp | timestamp_custom("%a, %d.%m.") }} is not recommended anymore.

Try use state_attr('sensor', 'attribute) .

1 Like

Thanks for you help.
Attached the screenshot. I think we only need this one.

Just so you know, I am trying to reproduce your sensors and try to help you as soon as possible. Still looking into it. Which source do you use? So which Country/region?

1 Like

That’s very kind. Thank you so much.
I am in Bavaria (Bayern), Germany.

Haha, sorry about that, I needed to be cleared. I meant which “Supported Service Providers” did you choose for your data from the source:

I am trying to add your configuration to mine, so I can play around myself.
What did you add in the configuration.yaml under

waste_collection_schedule:
  sources:

I saw that sometimes you need to put in an address. You can ommit that one, as I will look for a random one in the area on Google Maps, for privacy reasons :wink:

1 Like

Really appreciate your hekp.
I am using Abfall.IO / AbfallPlus.de in Germany.

Sorry for the late reply, I was out of town. I will look into it tomorrow!

1 Like

perhaps i’m confused about the question, but don’t you have that here:

  - platform: waste_collection_schedule
    name: "Nächste Abholung Tage"
    value_template: '{{ value.daysTo }}'

if so, why wouldn’t it be

(in {{ states('sensor.nachste_abholung_tage') }} Tage )

(or whatever the entity name ends up being for that sensor?

1 Like

It’s working! And yes you are right. I created the sensor in the past to solve this issue by myself.

Do you know how to create an if clause for:

If one day left → „Morgen“ instead of „1 Tage“
If same day → „Heute“ instead of „0 Tage“

  {{ states.sensor.nachste_abholung.attributes.values() | first |
  replace("papier", "Papiermüll") | replace("gelbersack", "Gelber Sack") |
  replace("rest", "Restmüll") }}: {{ states.sensor.nachste_abholung.attributes | first | as_timestamp |
  timestamp_custom("%a, %d.%m.") }} (in {{ states('sensor.nachste_abholung_tage') }} Tage)

I do not understand anymore. What do you want to accomplish?

1 Like

you have done that already yourself too:

you can replace value.daysTo with states('sensor.nachste_abholung_tage') if you’re using it outside of the sensor definition.

1 Like

Thanks all for you help.
I modified the sensor to look like this:

  #next ohne Tage
  - platform: waste_collection_schedule
    name: "Nächste Abholung Tage"
    value_template: '{{ value.daysTo }}{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'

The output it: “4 in 4 Tagen”.
I only want to have “in 4 Tage” so the first “4” need to be remove. Can you point me in the right direction?

Got it:

    value_template: '{% if value.daysTo == 0 %} Heute{% elif value.daysTo == 1 %} Morgen{% else %} in {{value.daysTo}} Tagen{% endif %}'

great :slight_smile:
Glad it’s working for you!

1 Like