Intro

Recycling is important. That’s why one or more garbage trucks pass my doorstep every week to collect non-reclyclable waste, paper/cardboard and the plastics-metal-drink cartons (PMD) group.
I could even have my organic waste (grass and prunings) collected.

But to get my recyclables collected, I need to put the garbage bag at my doorstep the night before collection day.
Luckily the garbage truck usually doesn’t pass my house before I leave to work, so I often get reminded by the bags standing at my neighbour’s doorstep :P
However, this “system” is of course far from perfect: the garbage truck can be early, my neighbour can have forgotten about it (or not have anything to be collected), I may not have enough time left in the morning, …
So I need a better system.

Introducing Garbage Collection

There’s a nice integration/component for Home Assistant written by bruxy70: Garbage Collection .
This plugin allows you to add the garbage collection schedule in a calendar within Home Assistant.
You can then use this calendar via custom sensors to create visualisations or even trigger notifications/reminders.

Installation

The easiest method of installing this component is through the Home Assistant Community Store (HACS) . This ofcourse assumes you’ve already installed HACS.
Manual installation is also an option, but HACS is prefered.
After installing the component, I prefer to reboot Home Assistant.

Next you’ll need to configure the sensors that you’ll soon be able to use in your automations.
Open up configuration.yaml in your editor. I’m using the Visual Studio Code addon.
Add the garbage_collection sensor and configure your schedule. Schedules can be made up of weekly/monthly/… occurences and/or specific dates. The component even takes into account national holidays, if you tell it to.

Below is my collection schedule. I have configured 3 types of collections. 1 is scheduled weekly, another every 2 weeks and the third every 4 weeks.

Note that the name will be used for the sensor name as well.

garbage_collection:
  sensors:
    - name: "Restafval"
      frequency: weekly
      collection_days:
      - tue
      expire_after: '12:00'
      move_country_holidays: 'BE'
    - name: "PMD"
      frequency: odd-weeks
      collection_days:
      - tue
      expire_after: '12:00'
      move_country_holidays: 'BE'
    - name: "Papier/karton"
      frequency: every-n-weeks
      collection_days:
      - tue
      period: 4
      first_week: 2
      expire_after: '12:00'
      move_country_holidays: 'BE'

After rebooting Home Assistant, you’ll see that a Calendar has been added to Home Assistant displaying your garbage collection schedule.

You’ll now find new sensors, in my case: sensor.restafval, sensor.pmd and sensor.papier_karton.
Looking at the Developer Tools, you’ll see data similar as follows:

state: 2
next_date: '2020-09-29T00:00:00+02:00'
days: 7
last_collection: '2020-09-22T12:00:00'
last_updated: '2020-09-22T12:00:39.746713+02:00'
friendly_name: Restafval
icon: 'mdi:trash-can'
device_class: garbage_collection__schedule

Note that state has a value of 2.
There are 3 possible state values.

ValueMeaning
0Collection is today
1Collection is tomorrow
2Collection is later

If the verbose_state parameter is set, it will show date and remaining days, for example “Today” or “Tomorrow” or “on 2020-09-24, in 2 days”.

Displaying cards in Lovelace

Using the lovelace-card-templater plugin for Lovelace, you can create a nice visual presentation of the garbage collection schedule based on the sensor state.
Note that it’s not necessary to use this plugin, or the garbage-collection-card to integrate your garbage collection schedule in Lovelace.

Using the lovelace-card-templater, you can create a visual like this:

Visualisation in Lovelace
Visualisation in Lovelace

Add a Horizontal Stack Card to Lovelace, with a card/column for each sensor you’d like to display.
Below is the code for one of the collection schedules, adapt this to your situation.

card:
  entity: sensor.restafval
  name_template: '{{ states.sensor.restafval.attributes.days }} days'
  show_name: true
  show_state: false
  state_image:
    '0': /local/img/garbage/afval-rest_now.png
    '1': /local/img/garbage/afval-rest.png
    '2': /local/img/garbage/afval-rest_bw.png
  type: picture-entity
entities:
  - sensor.restafval
type: 'custom:card-templater'

You’ll see that I’m referencing 3 images.
These are images I quickly created using some logos I found online and some work in Paint.net to give it some color.

Collection Restafval today Collection Restafval tomorrow Collection Restafval later

These images are saved at /config/www/img/garbage.
The images are matched with a state to visually display whether the garbage collection is today, tomorrow or later.

By using the name_template attribute, I’m also able to display in how many days the collection will be (i.e. is it the day after tomorrow or in 10 days?).

Creating automations in Node-RED

Aside from showing nice visuals in Lovelace, we can also create automation based on the garbage collection schedule.

Below you see the visual representation of my automation which warns me at 18:00 (6pm) when a collection is scheduled for the next day.

Setting up notifications in Node-RED
Setting up notifications in Node-RED

The automation is quite simple:

  1. An inject node triggers the flow daily at 18:00

  2. The state of the sensors is checked using the evaluation “If state is 1 (number)” If the evaluation returns true, i.e. collection is scheduled for tomorrow, we continue

  3. A function block is used to format the notification message. Using the friendly_name attribute, we can customise the notification for each collection.

    msg.payload =
    {
        "data": {
            "title": "Vuilnisophaling",
            "message": "Morgen ophaling " + msg.data.attributes.friendly_name + "!"
        }
    }
    return msg;
    
  4. Finally we call the notify service of my smartphone’s Home Assistant app

The only thing that rests me now, is to find a robot that’ll drop off my garbage bags at the front door by the time the garbage truck arrives :)