Waste collection made easy

Hi everyone,

I think every HomeAssistant user comes up with the idea of ​​visualizing their waste calendar sooner or later.

I have seen many approaches and proposed solutions, but none of them really convinced me. Until now. Since the community is helping me a lot with my HomeAssistant project, I would like to give something back and help one or two people with this post.

What do I want to implement?
I want a card in the HomeAssistant dashboard that shows which household waste will be collected next and in how many days.

What do we need for this?
I use the following integrations for my solution:

  • waste_collection_schedule
  • card_mod
  • MushroomCards

Waste Collection Schedule:
Install Waste Collection Schedule from HACS.

Go to the File Editor and insert the sensors from Waste Collection Schedule into your configuration.yaml.

Make sure that the parameter

add_days_to: true

is set for each sensor.
Your configuration should look something like this (value_template is not needed):

The basic configuration is complete.

Now comes the part that gets a bit fiddly and where I was not very convinced by the previous approaches. We now have to prepare the information from the various sensors in such a way that the sensor that has the information about the very next household waste collection is displayed. How do we do that?

To make it easier to understand, I’ll split the logic into two parts. First we want the name of the sensor with the very next household waste (paper, plastic, etc.), then we get the remaining days.

I highly recommend testing things like this in the template section in the developer tools before entering them into a card in the dashboard. In the following, please make sure that you adapt the entity names (e.g. sensor.papiermull) to suit your configuration.

The name of the sensor:
This is how we get the name of the sensor for the very next waste collection:

{% set entities = 'sensor.gelber_sack', 'sensor.papiermull', 'sensor.restmull', 'sensor.biomull' %}
{% set next = expand(entities) | selectattr('attributes.daysTo', 'defined') | sort(attribute='attributes.daysTo') | first | default %}
{{ next.name if next else '??' }}

The remaining days until collection:
This is how we get the remaining days for collection:

{% set entities = 'sensor.gelber_sack', 'sensor.papiermull', 'sensor.restmull', 'sensor.biomull' %}
{% set next = expand(entities) | selectattr('attributes.daysTo', 'defined') | sort(attribute='attributes.daysTo') | first | default %}
{% if (next.attributes.daysTo if next else '??') == 1 %} Morgen {% elif (next.attributes.daysTo if next else '??') == 0 %} Heute
{% else %} in {{ next.attributes.daysTo if next else '??' }} Tagen
{% endif %}

Name & days until collection together:

{% set entities = 'sensor.gelber_sack', 'sensor.papiermull', 'sensor.restmull', 'sensor.biomull' %}
{% set next = expand(entities) | selectattr('attributes.daysTo', 'defined') | sort(attribute='attributes.daysTo') | first | default %}
{{ next.name if next else '??' }}{% if (next.attributes.daysTo if next else '??') == 1 %} Morgen {% elif (next.attributes.daysTo if next else '??') == 0 %} Heute
{% else %} in {{ next.attributes.daysTo if next else '??' }} Tagen
{% endif %}

Dashboard:
With this information we can now turn our attention to the presentation.

The classic entity card
You know it, I don’t think there’s anything else to say here. Just insert the sensors from the waste collection schedule. I’ve adjusted the colors a bit with card_mod (I use colors from the Apple color guidelines).

type: entities
entities:
  - entity: sensor.gelber_sack
    secondary_info: none
    card_mod:
      style: |
        :host {
          --card-mod-icon-color: rgb(255, 204, 0)
  - entity: sensor.restmull
    card_mod:
      style: |
        :host {
          --card-mod-icon-color: rgb(72, 72, 74)
  - entity: sensor.papiermull
    card_mod:
      style: |
        :host {
          --card-mod-icon-color: rgb(0, 122, 255)
  - entity: sensor.biomull
    card_mod:
      style: |
        :host {
          --card-mod-icon-color: rgb(162, 132, 94)
state_color: true

Result:

The template card
I’m using the mushroom template card here because it provides the option of entering .yaml code for the secondary information. And that’s exactly what we’re going to do now. Just enter the code from above (name & days) here.

To adjust the color of the icon accordingly, we need card_mod and use the first part of the code with the names of the sensors:

card_mod:
  style: |
    ha-state-icon {
      color:
        {% set entities = 'sensor.gelber_sack', 'sensor.papiermull',
        'sensor.restmull', 'sensor.biomull' %} {% set next = expand(entities) |
        selectattr('attributes.daysTo', 'defined') |
        sort(attribute='attributes.daysTo') | first | default %}
        {% if (next.name if next else '??' ) == "Gelber Sack" %} 
        rgb(255, 204, 0)
        {% elif (next.name if next else '??' ) == "Restmüll" %}
        rgb(72, 72, 74)
        {% elif (next.name if next else '??' ) == "Biomüll" %}
        rgb(162, 132, 94)
        {% elif (next.name if next else '??' ) == "Papiermüll" %}
        rgb(0, 122, 255)
        {% endif %};
        }

Result:

The badge icon
If you like it even more purist, just use a badge icon to show which garbage is next tomorrow.
We’ll just use our existing code for this too.
In the mushroom template card, we enter the following in the badge icon section:

{% set entities = 'sensor.gelber_sack', 'sensor.papiermull', 'sensor.restmull', 'sensor.biomull' %} {% set next = expand(entities) | selectattr('attributes.daysTo', 'defined') | sort(attribute='attributes.daysTo') | first | default %} {% if (next.attributes.daysTo if next else '??') <= 1 %} mdi:trash-can {% endif %}

This will show us an icon if the next garbage is due tomorrow.
Now we just have to adjust the color accordingly. For this I use card_mod again with the following code:

card_mod:
  style: |
    mushroom-badge-icon {
      --main-color: {% set entities = 'sensor.gelber_sack', 'sensor.papiermull',
        'sensor.restmull', 'sensor.biomull' %} {% set next = expand(entities) |
        selectattr('attributes.daysTo', 'defined') |
        sort(attribute='attributes.daysTo') | first | default %}
        {% if (next.name if next else '??' ) == "Gelber Sack" %}
        rgb(255, 204, 0)
        {% elif (next.name if next else '??' ) == "Restmüll" %}
        rgb(72, 72, 74)
        {% elif (next.name if next else '??' ) == "Biomüll" %}
        rgb(162, 132, 94)
        {% elif (next.name if next else '??' ) == "Papiermüll" %}
        rgb(0, 122, 255)
        {% endif %};
        } !important;
    }

Result:

As you can see, we are actually just using the logic we created at the beginning again and again. I would like to say a big thank you to the community at this point. And not to take credit for other people’s work! The logic used also came from the community. I have now simply used it for what I think is a nice implementation.

I hope I was able to help :slight_smile:

2 Likes