Waste Bin Collection Calendar update - Post #1

Reading time: 4 minutes (656 words)
Author: @pugmiester
Tags: homeautomation , homeassistant , automation , calendar

This is turning out to be a larger post than I expected, so I’m going to split it up into a couple of smaller posts.

Back in the good old days, when the Google calendar integration meant you had to create sensors in yaml for any of your events, I built a set of 4 sensors that would track the 4 waste bins (general garbage, paper and cardboard, tins and glass, garden waste) that we have collected. The schedules vary betwwen every week and every 2 and 3 weeks depending on the bin. I created a set of coloured images to match each bin and we had a notification on the day of collection as well as a countdown to the next time each bin was being collected. Ahhhhh, the good old days.

And then, the new shiny Home Assistant Google calendar integration was launched, allowing you to dispense with the manual yaml setup and just click a few buttons. Cool, I’ll do that. Except…. now it’s impossible to tell when the next bin collection event is because the only thing the integreation can tell you is when the next event is. But, all of our events are in our shared Google calendar so they’re easy to see and update meaning now there’s no way to countdown to the next occurance of a single event type. Well that’s a bit rubbish (pun intended).

The current itteration had me update all of our bin events so that they start at 18:00 on the day before collection so that they could trigger an automation to turn on a relevent input_boolean that I then use to both show the bins due to be emptied tomorrow to remind us to take them out as well as triggering the right combination of reminders for our morning briefing from Home Assistant’s text to speech engine just in case we’ve forgotten. It’s clumsy, but it works. It’s been working for, I can’t remember, but it’s probably been over a year.

But now I’m thinking, having watched one of Vaclav Chaloupka’s videos where he works through replacing his custom garbage collection integration with Home Assistant local calendars, I could do the same. Yes, it means we have a local calendar for each bin colour but they’re not cluttering up our Google calendar so that’s less of an issue plus as each calendar now only has a single repeating event I can create a countdown for the next event again so can see at a glance when the bins are next due to be emptied. The one downside is that updating the calendars is now done in Home Assistant rather than through our existing Google calendar but with our collection being on a Wednesday it’s almost never adjusted because of national holidays so it hardly ever needs updating.

OK, enough of the theory, time to document how this works.

First off, a quick view of the new calendars up and running

View of the new multiple bin collection calendars in Home Assistant

Here’s the template I used to generate a countdown for the number of days to the next event in each calendar.

# Template to calculate the remaining days until each bin gets collected                                                 
- platform: template                                                                                                     
  sensors:                                                                                                               
    black_bin_days_countdown:                                                                                            
      value_template: >-                                                                                                 
       {{ ((state_attr('calendar.black_bin_day','start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int}}
- platform: template                                                                                                     
  sensors:                                                                                                        
    blue_bin_days_countdown:                                                                                      
      value_template: >-                                                                                          
       {{ ((state_attr('calendar.blue_bin_day','start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int}}
- platform: template                                                                                                     
  sensors:                                                                                                        
    brown_bin_days_countdown:                                                                                     
      value_template: >-                                                                                          
       {{ ((state_attr('calendar.brown_bin_day','start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int}}
- platform: template                                                                                                     
  sensors:                                                                                                        
    green_bin_days_countdown:                                                                                     
      value_template: >-                                                                                          
       {{ ((state_attr('calendar.green_bin_day','start_time') | as_timestamp - today_at('00:00') | as_timestamp) / 86400) | int}}

So, that’s the basics up and running. Next I need to plug the new calendar events into the existing automations to have the bin notifications continuing to trigger as they do currently. Following on from that is including a bit more intelligence into the process so we can use a more human readable notification process.