Home » Blog » Manage your Waste Collection in Home Assistant NOW!

Manage your Waste Collection in Home Assistant NOW!

https://youtu.be/V1xEv8wuHFE

Hi, here I am again with a new tutorial video. This time, itโ€™s about a service in Home Assistant that shows when you need to put your garbage bins out on the street. This is one of my life-saving videos that I use every week, and it really helps me remember to take out the trash. Letโ€™s get started!


โญโญโญ NOTE: โญโญโญ

This article is the script for a YouTube video. I wrote it prior to recording the video. You can help me continue doing this by checking out the video, commenting under it, giving it a thumbs up, andย subscribing to my YouTube channel. This will ensure that the video is offered more frequently to new visitors, allowing them to stay informed about the latest Home Assistant tutorials and smart home-related product reviews.

I appreciate your support!

Ed

Click here to watch the video

First of all, I should say that there are several ways to do this. Iโ€™ve been using this for years, and I’ve never made a video about it before because I used a specific Dutch integration that wasnโ€™t particularly relevant to an international audience. However, it turns out that there is also an integration that works for multiple countries, so now itโ€™s time to create a tutorial about this one.

In this video, Iโ€™ll show you how to create a dashboard that displays the type of waste you need to dispose of and when it needs to be disposed of. It’ll also notify you of the kind of waste that’ll be collected tomorrow, and youโ€™ll receive a notification on your phone at 7 PM if waste is being collected the next day.

We will use the HACS Waste Collection Schedule integration for this.
If you havenโ€™t installed HACS yet, watch my video on how to install HACS.
Iโ€™ll also be using the Mushroom Template Card, so if you havenโ€™t installed Mushroom, do that through HACS first.
Iโ€™m also using Visual Studio Code, so make sure youโ€™ve installed Studio Code Server via the add-ons in Home Assistant as well.

Installing the Waste Collection Schedule integration

Letโ€™s start by installing the Waste Collection Schedule integration via HACS:

  • Go to HACS.
  • Search for “Waste Collection”.
  • Click on Waste Collection Schedule.
  • Click Download.
  • Click Download again.
  • Go to Settings.
  • Click Restart required.
  • Click Submit and then Finish.

The Waste Collection Schedule integration is now installed.

Copy icon images for all waste types

Next, I want to show nice icons for each waste type, so weโ€™ll first copy the waste images to the Home Assistant server.

Youโ€™ll find the link to the images in the description of this video.
Weโ€™ll do this via Visual Studio Code:

  • Open Studio Code Server.
  • Go to the www folder and create a new folder inside it.
  • Click the Add Folder icon and create a folder called "waste".
  • Open this folder and copy the image files into it.

The images are now copied to the Home Assistant server.

Configuring the Waste Collection integration

Now weโ€™ll configure the Waste Collection integration:

  • Go to Settings > Devices & Services and click Add Integration.
  • Search for Waste Collection.
  • Click Waste Collection Schedule.
  • Select your country.
  • Then choose your service provider.
  • Enter your postal code and house number and click Submit.
  • Check both options to configure the integration in detail.
  • Select the collection types you want to configure.
  • Iโ€™m selecting the types I want to use in my system.
  • Now you can customize each collection type.
  • I give a different alias. In this case, itโ€™s โ€œPlasticโ€ and for the picture, I refer to /local/waste/plastic.PNG. Note: You must use /local instead of /www when referencing images!
  • I repeat this for the other types like โ€œPaperโ€, referring to /local/waste/paper.png.
  • I do this for the remaining two types as well.
  • Once Iโ€™ve adjusted all types, I continue configuring the integration.
  • Give the sensor a name.
  • I call it โ€œupcomingโ€ and select โ€œgenericโ€ as the detail format.
  • Make sure to check โ€œAdd days toโ€.
  • Click Submit.
  • Select an area and click Finish.

The sensor.upcoming is now configured in Home Assistant.

You can reconfigure it by clicking Configure. There youโ€™ll see:

  • Fetch time
  • Random fetch time offset
  • Day Switch Time (this tells the integration when the “day” ends โ€” by default 10 AM, meaning after 10 AM it switches to show the next dayโ€™s collection)

Check the upcoming sensor

Letโ€™s look at the contents of the sensor.upcoming:

  • Go to Developer Tools.
  • Click States.
  • Search for upcoming.
  • Click on sensor.upcoming.

Youโ€™ll see:

  • The types being tracked
  • Dates, icons, pictures, and types per day
  • At the end, a daysTo variable showing how many days until the next type is picked up

So the sensor.upcoming is filled with our collection schedule.

Define Waste_Today and Waste_Tomorrow sensors

Next, weโ€™ll define two sensors:

  1. One that shows what waste is picked up today
  2. and One for tomorrowโ€™s pickup.

Weโ€™ll use custom template sensors, written in YAML and Jinja.

If you want to learn more about YAML and Jinja, follow my free course on how to use them in Home Assistant.

  • Go to Studio Code Server.
  • Open configuration.yaml.
  • Add the following lines: template: !include templates.yaml
  • Create a new file called templates.yaml.
  • Go to Settings > 3 dots > Restart Home Assistant.

After restarting, open the templates.yaml file.

Iโ€™ve prepared the code and will now explain it step by step.
You can copy it from the screen or download it for a small sponsorship fee โ€” youโ€™ll get lifetime updates, and you help support the channel if you sponsor me.


For “waste today,” I start by assigning it a name. In this case, thatโ€™s simply โ€œWaste today.โ€ Next, I define a unique ID. The unique ID can be anything you come up with, but in Visual Studio Code, you can also generate it automatically by right-clicking. After that, we define the Stateโ€”this is the value of the sensor.

We start by setting the variable waste_type to “Nothing.” Then, we retrieve the date from the first attribute of the upcoming sensor we defined earlier. That first attribute contains the next type of waste that will be picked up.

First, we create a variable waste_collection_date and assign it the date from the first attribute of the upcoming sensor. Then, we create another variable called days_until_collection, which holds the number of days between the waste_collection_date and today.

After that, I perform a check to see whether days_until_collection equals zero. If it does, it means that a specific type of waste will be collected today. In that case, I set waste_type to the type specified in the attribute of the upcoming sensor. Finally, I return waste_type.

Now Iโ€™ve defined the type as the State. I also want to define the date and the entity picture as attributes of this “waste today” sensor. I donโ€™t personally use the date much, but Iโ€™m including it here for people who prefer to show the exact date instead of the number of days until pickup.

Letโ€™s start by defining the date as an attribute. This works almost the same as defining the state. Youโ€™ll see that the code is nearly identical, except in this case, I refer to the date attribute in the upcoming sensor instead of the type attribute. I then return the date.

Next, I define the entity_picture attribute. Again, the code is similar to what I used for both state and date, but now I reference the picture attribute in the upcoming sensor. If no waste is being collected today, I set the picture to an image of an empty trash canโ€”in my case, thatโ€™s empty_bin.png.

And that completes the “waste today” sensor.


Now we’re going to do roughly the same thing for the waste tomorrow sensor. This code is a bit longer because Iโ€™m going to take into account the first two values within the upcoming attribute of the upcoming sensor.

For example, if the first value indicates that waste is being collected today, then I need to check the second value to see whether it contains waste for tomorrow.

To achieve this, weโ€™ll use a for loop to iterate through values. Again, if you want to know exactly how this works, take a look at my YAML and JINJA course.

We start by defining the name again. Then we create a new unique ID. In the state, I do the following:

First, I create a namespace where I set the waste_type to โ€œNothing.โ€ You need a namespace in a for loop to store variable values that will be available outside the loop.

Next, I start the for loop and iterate through a range of two values: 0 and 1. So i equals either 0 or 1. For each of these, I retrieve the date and calculate the number of days between that date and today.

Then I check whether the number of days difference is equal to one, because if it is, it means that the value corresponds to tomorrow. If thatโ€™s the case, I set the waste_type in the namespace to the type I retrieved from the upcoming attribute. I do this for both the first and second value within the upcoming attribute of the upcoming sensor. Finally, I return the waste_type.

Just like with waste today, Iโ€™m now going to create two additional attributes: date and entity_picture. The code here is almost identical to the code I used for the state. The only difference is that for date I fetch and return the date, and for picture I fetch and return the picture.

The only thing that works a little differently with the picture is that I set a default valueโ€”an image of an empty trash canโ€”and this gets overwritten as soon as itโ€™s determined that waste will be collected tomorrow.

Now save the templates.yaml file and then go to Developer Tools. Click on the YAML tab and select Template Entities.

Check the new sensors

Now go to the States tab and search for waste_to. You should now see both sensors appear, and if everything went well, they should be filled with the correct values.

You can find the link to this code in the description of the video.
I’d really appreciate it if you’d consider sponsoring me for the work Iโ€™ve put into this!


Let’s create the dashboard

Great! We now have all the sensors available to start building our dashboard.

  • Open any dashboard and create a new view.
  • Give it the title “Waste” and set the maximum number of sections wide to 1.
  • Click Save.
  • Edit the section heading and name it “Waste”.
  • Now create a new card and select the Mushroom Template Card.
  • Fill in the following:
    • For Primary Information, display the type from the first attribute value in the upcoming attribute of the upcoming sensor.
    • For Secondary Information, show the number of days we have to wait until itโ€™s picked up.
    • For Picture, show the path where the icon image is stored.
  • Select Vertical Layout.
  • Go to the Layout tab and ensure everything is displayed in a single column.
  • Click Save.
  • Next, weโ€™re going to duplicate this card:
    • Click the three dots in the upper right corner of the card and choose Duplicate.
    • Replace every instance of 0 with 1 (This refers to the next value in the upcoming attribute of the upcoming sensor).
    • Save this card.
  • Repeat the same for the following two waste types:
    • In the third card, replace 1 with 2.
    • In the fourth card, replace 2 with 3.

You now have an overview of the upcoming four waste types and their scheduled collection dates.
Of course, you may only have two or maybe even five waste types. In that case, create two or five cards accordingly.


Now weโ€™re going to create two more cards: one for waste today and one for waste tomorrow. For this, weโ€™ll make two Tile Cards.

  1. Add a Tile Card and select the entity waste_today.
  2. Open the Content section and enable Show Entity Picture.
  3. Save the card.
  4. Do the same for waste_tomorrow:
    • Select the Tile Card.
    • Select the entity waste_tomorrow.
    • In the Content section, again select Show Entity Picture.
    • Click Save.

Now you have two cards on your dashboard showing whether waste will be collected today or tomorrow.


Now, I want to do one more thing, which is to show a card only if there is waste being collected today or tomorrow.
For that, weโ€™ll use the Conditional Card.

  • Add a new card and select the Conditional Card.
  • Click Add Condition.
  • Select Entity State.
  • Choose the entity waste_today.
  • For State, choose is not equal to, and enter “Nothing".
  • Go to the Card tab.
  • Add a Tile Card and select waste_today as the entity.
  • Open the Content section and select Show Entity Picture.
  • Click Save.
  • Duplicate the waste_today card you just created and change the entity to waste_tomorrow.
  • In the Card tab, also select waste_tomorrow.
  • Click Save.
  • Click Done.

Youโ€™ll now see that both cards are hidden, since both currently have the value Nothing. However, as soon as there is a value for waste today or tomorrow, the card will be displayed.


Create an automation to warn you when waste should be taken outside

Weโ€™re almost done, but I want to do one last thing:
Letโ€™s create an automation that sends a notification to your phone at 7 PM if waste will be collected tomorrow, so you remember to put out the bin.

  • Go to Settings > Automations & Scenes.
  • Click Create Automation.
  • Click Create New Automation.
  • Click Add Trigger.
  • Search for Time and enter 7:00 PM in the โ€œAt Timeโ€ field.
  • Go to the And If section and click Add Condition.
  • Select State.
  • Enter upcoming as the entity and daysTo as the attribute.
  • Set the state to 1.
  • Go to the Then Do section.
  • Select your phone’s Notify service.
  • For the Message, enter something like:
    “Tomorrow, {{ states(‘sensor.waste_tomorrow’) }} will be picked up.”
  • Click Save.
  • Give your automation a clear name and click Save again.

Youโ€™ll now get a notification the night before waste collection.


That was my tutorial on managing your waste collection with Home Assistant. I hope it was helpful! This is one of the most essential automations in my home, as it ensures I never forget to take out the trash.

If you find my videos helpful, consider sponsoring me monthly like these awesome people do. You might not realize this, but creating these tutorials requires at least 24 hours of work for a 10-minute video, so it’s a significant amount of effort. You’ll find the links on how to sponsor me in the video description. Thanks a lot for watching! Donโ€™t forget to give a thumbs up and subscribe if you havenโ€™t yet.

See you in my next video.
Bye-bye!

Please follow and like us:


Back to all articles

Leave a Reply

Your email address will not be published. Required fields are marked *