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
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:
- One that shows what waste is picked up today
- 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 theupcoming
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.
- For Primary Information, display the type from the first attribute value in the
- 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
with1
(This refers to the next value in theupcoming
attribute of theupcoming
sensor). - Save this card.
- Repeat the same for the following two waste types:
- In the third card, replace
1
with2
. - In the fourth card, replace
2
with3
.
- In the third card, replace
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.
- Add a Tile Card and select the entity
waste_today
. - Open the Content section and enable Show Entity Picture.
- Save the card.
- 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 towaste_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 anddaysTo
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!