Bin / Waste Collection


i dont think there is an elevenst but an eleventh?
or am i wrong about that :wink:

@apt i know that you can use vars (or in this case a dict) but i think you need to search the forum to find examples.
the code i gave works, but it can be simplefied.


The code you supplied just seems to output th, it’s defaulting to the final {% else %} from what I can see.


it gives st when the day is 1, nd when the day is 2 and rd when the day is 3
i replaced (as_timestamp(states.calendar.waste_collection.attributes.start_time)|timestamp_custom("%d")|int) with 1 and then it gives st

of course th is default, that applies to 90% from all dates.


Thanks for all your help. I managed however (via another thread) to work out how to perform what I wanted via a Jinja2 macro, See below for the full sensor:

    friendly_name: 'Collection Date'
    value_template: >
       {%- macro suffix(d) %}
       {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
       {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
       {%- endmacro %}
       {% set day = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%A') %}
       {% set date = as_timestamp(states.calendar.waste_collection.attributes.start_time) | timestamp_custom('%d') |int %}
       {{ day }} {{ date }}{{ suffix(date) }}
    icon_template: mdi:calendar-star


if it makes you happy :wink:
it does the same but way more complex :wink:


But yours doesn’t work as far as I can tell, because your algorithm doesn’t take into account 11, 12 and 13.


thats because it shouldnt.

1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, etc.
so you only need exceptions for 1, 2 and 3

its the script from apt what is very strange.

that says:
make it “th” if the date is 11, 12 or 13
else make it like we put in the dict (so use 1, 2 and 3) and if its not in the dict use “th”

so the complete first statement is obsolete.
this macro would do exactly the same:

       {%- macro suffix(d) %}
       {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
       {{- sfx.get(d%10, 'th') }}
       {%- endmacro %}

we are looking at the day in date, not at the last figure from the day in date


Could you explain how the code you have presented will handle 21st, 22nd, 23rd and 31st?


i didnt think of those :wink:
probably because english isnt my first language.
and now i get the more complex part from the macro :wink:

thanks for pointing those exceptions out to me.


@nickrout @reef-actor @ReneTode

Take a look at my solution thanks to @petro :+1:t3:


No problem, you teach HA, we’ll teach english :wink: Your contributions are very much valued.


@matchett808 Hey. I just stole the python file you posted here for ical URLs, but when I try to set up the sensor, HA just says “Platform not found: sensor.ical”. I had assumed that this file should go into the “custom_components/sensor/” file, but was I mistaken? Are there any other steps to getting this to work?

I had tried a similar thing in bash script before encountering this thread, but your solution is much nicer if I can get it to work.

My sensor:

- platform: command_line
  name: Garbage Collection
  command: 'wget -qO- [YOUR_ICAL_URL_HERE] | /home/hass/config/'
  command_timeout: 60
  scan_interval: 86400 # daily
  value_template: '{{ value_json.displayDate }}: {{ value_json.summary }}'
    - uid
    - date
    - displayDate
    - summary
    - description

My bash script


currentDate=`date -Idate`

handle_event() {
  local dt=${content[DTSTART]}
  local entryDate="${dt:0:4}-${dt:4:2}-${dt:6:2}"
  if [[ foundFirstMatch -eq 0 ]]; then
    if [[ $entryDate < $currentDate ]]; then
      #printf "PAST ($entryDate <= $currentDate): ${content[SUMMARY]}"; echo
      displayDate=`date -d "2018-11-20" "+%A, %B %-d, %Y"`
      echo "{";
      echo "  \"uid\": \"${content[UID]}\",";
      echo "  \"date\": \"$entryDate\",";
      echo "  \"displayDate\": \"$displayDate\",";
      echo "  \"summary\": \"${content[SUMMARY]//\\/}\",";
      echo "  \"description\": \"${content[DESCRIPTION]//\\/}\"";
      echo "}";

declare -A content=( ) # define an associative array (aka map, aka hash)
#declare -A tzid=( )    # another associative array for timezone info

while IFS=: read -r key value; do
  value=${value%$'\r'} # remove DOS newlines
  if [[ $key = END && $value = VEVENT ]]; then
    content=( )
    # tzid=( )
    #if [[ $key = *";TZID="* ]]; then
    #  tzid[${key%%";"*}]=${key##*";TZID="}


Hi - yeah, that’s where it should go - I’ve got the following config:

  - platform: ical
    name: "Refuse Collection"
    url: "https://[snip]/bin-ical?uprn=[snip]"
    prefix: bins
      - value: "Black box"
        icon: mdi:glass-tulip
        name: "Black - glass and electronics Bin"
      - value: "Green refuse"
        icon: mdi:delete
        name: "Green - refuse Bin"
      - value: "Brown garden bin"
        icon: mdi:nature
        name: "Brown - garden bin"
      - value: "Blue recycling bin"
        icon: mdi:recycle
        name: "Blue - recycling Bin"
      - value: "Food caddy"
        icon: mdi:food
        name: "Grey - food Bin"

This gives me 5 sensors, for the coming 5 (sensor.binsx) bin pickups (also reflects cancellations etc - so long as they update their feed)


Unable to install Pup on my Ubuntu Server for some odd reason, would anyone be kind enough to give a brief description of how to get it installed?

Trying to get the info from Sedgemoor Council via the scrape sensor but its proving impossible!


Looks like this:


Why on earth does each council have to re-invent the wheel and list the dates in a different way on their own site! It would be a million times easier just to have a single site with all the dates for the whole country but that would be too easy.

Anyway I’m using HassOS which does not include ‘pup’ but it does include ‘curl’ and ‘jq’.

Are there any alterntives to ‘pup’, maybe some python parsing could work also


:rofl::man_facepalming: tell me about it!


I use a shell_command to pull and scrape the html:

curl -s "https://page.with/relevant.html"|iconv -f iso8859-1 -t utf-8|python3 -c '
import sys, re, itertools;
pattern = "crazyRegexPattern";
source =;
rx = re.compile(pattern, re.S);
for match in itertools.islice(rx.finditer(source ),3):
  caps = {**match.groupdict(), "m":int(match.groupdict()["m"])+1};

This pulls in the html into source where you can then go nuts with python


Has anyone given any thought to “bin presence detection”. Meaning - don’t remind me to put my bins out if I have already put my bins out. Some thoughts that pop into mind:

  • BLE inside the bin (yuck),
  • Ultrasonic sensor + nodemcu pointing at the bin’s normal spot,
  • Image processing / object recognition to see if bins are out on the street.

Any easier way that is a bit simpler / thinking outside the box?


Look out the window?

Our bins already have some sort of rfid in them, so the council trucks can tell if we are double dipping by putting them in a neighbouring street that has a different collection date. (I used to live in a street that had a different bin day on the other side of the street, twas great but was before they moved to the rfids!). Anyway, it seems to me that I could probably sort this sort of detection if I really wanted to.