5 minutes
Garbage Collection Schedule and Notification
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.
Value | Meaning |
---|---|
0 | Collection is today |
1 | Collection is tomorrow |
2 | Collection 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:

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.
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.

[{"id":"cff3f2b8.ed05c8","type":"tab","label":"Vuilnis ophaling","disabled":false,"info":""},{"id":"3653f0c5.b43408","type":"inject","z":"cff3f2b8.ed05c8","name":"Daily 18:00","props":[{"p":"payload"}],"repeat":"","crontab":"00 18 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":160,"wires":[["ddf1f854.b9bcd","9ad6d00f.0516e8","655301a1.f56e"]]},{"id":"ddf1f854.b9bcd","type":"api-current-state","z":"cff3f2b8.ed05c8","name":"Restafval","server":"2ce15169.23b9de","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.restafval","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":320,"y":100,"wires":[["e1de8830.87ebb"],[]]},{"id":"9ad6d00f.0516e8","type":"api-current-state","z":"cff3f2b8.ed05c8","name":"PMD","server":"2ce15169.23b9de","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.pmd","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":310,"y":160,"wires":[["e1de8830.87ebb"],[]]},{"id":"655301a1.f56e","type":"api-current-state","z":"cff3f2b8.ed05c8","name":"Papier/karton","server":"2ce15169.23b9de","version":1,"outputs":2,"halt_if":"1","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.papier_karton","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":340,"y":220,"wires":[["e1de8830.87ebb"],[]]},{"id":"e1de8830.87ebb","type":"function","z":"cff3f2b8.ed05c8","name":"Data","func":"msg.payload =\n{\n \"data\": {\n \"title\": \"Vuilnisophaling\",\n \"message\": \"Morgen ophaling \" + msg.data.attributes.friendly_name + \"!\"\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":160,"wires":[["1a637b9f.2ce43c"]]},{"id":"1a637b9f.2ce43c","type":"api-call-service","z":"cff3f2b8.ed05c8","name":"Notify me","server":"2ce15169.23b9de","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_me","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":660,"y":160,"wires":[[]]},{"id":"e0e16241.e99dd","type":"comment","z":"cff3f2b8.ed05c8","name":"Garabage collection example by sequr.be","info":"https://sequr.be/blog/2020/09/home-automation-garbage-collection-schedule-and-notification/","x":220,"y":40,"wires":[]},{"id":"2ce15169.23b9de","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
The automation is quite simple:
An inject node triggers the flow daily at 18:00
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 continueA 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;
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 :)
Home Automation Home Assistant Garbage Collection Node-RED
882 Words
2020-09-17 (Last updated: 2020-09-22)