Bin / Waste Collection

With much help from this post, from @lolouk44 and The EPIC Time Conversion and Manipulation Thread!

This is the working sensors setup if anyone else finds it useful (postcode changed)

It is for East Riding Council:
https://binscollections.eastriding.gov.uk/Output/Results?searchString=XXXX+XXXt&ButtonSearchTrial=Search

bins

- platform: scrape
  resource: https://binscollections.eastriding.gov.uk/Output/Results?searchString=XXXX+XXXt&ButtonSearchTrial=Search
  select: ".er-bin-item-row-wrapper > div:nth-of-type(77) > div:nth-of-type(1) > div:nth-of-type(3) > div:nth-of-type(1)"
  name: EYRC Next Green Bin
  scan_interval: 3600

- platform: scrape
  resource: https://binscollections.eastriding.gov.uk/Output/Results?searchString=XXXX+XXX&ButtonSearchTrial=Search
  select: ".er-bin-item-row-wrapper > div:nth-of-type(77) > div:nth-of-type(1) > div:nth-of-type(4) > div:nth-of-type(1)"
  name: EYRC Next Blue Bin
  scan_interval: 3600

- platform: scrape
  resource: https://binscollections.eastriding.gov.uk/Output/Results?searchString=XXXX+XXX&ButtonSearchTrial=Search
  select: ".er-bin-item-row-wrapper > div:nth-of-type(77) > div:nth-of-type(1) > div:nth-of-type(5) > div:nth-of-type(1)"
  name: EYRC Next Brown Bin
  scan_interval: 3600

Also used this to create a sensor to display number of days until each one is collected, one of these needed for each bin. Date comes from the scraper as “Mon, 19 April 2019” so had to do a bit of conversion (thanks again @lolouk44):

- platform: template
  sensors:
    green_bin_days:
      value_template: >-
        {% set date_in = states.sensor.eyrc_next_green_bin.state|replace('\n', '') %}
        {% set bin = strptime((date_in), "%a, %d %B %Y") %}
        {% set diff = as_timestamp(bin) - as_timestamp(now()) %}
        {% set days = (diff /86400) | int %}
        {% if days == 0 %}
          Today
        {% elif days == 1 %}
          Tomorrow
        {% else %}
          {{ days }} days
        {% endif %}
3 Likes

Nice work :+1:

What you using for the bin colours - I was using custom UI but it’s broken.

Using these images from google, re-coloured and sized on a glance card:

blue_bin2 brown_bin2 green_bin2

1 Like

Custom UI has been fixed again :slight_smile:

1 Like

My bins just come every Monday for the general waste and then alternating weeks for green waste and recycling. Has anyone done anything simple like that just using dates? I hadn’t thought of it until I saw this thread so looking to piggy back off existing effort!

I did but then I was able to setup a scrape from my local council website
You can just use week numbers if you want something simple - then determine if week is odd or even

1 Like

Pretty much what I did.

Used @Rookeh script form Here

and For days left I added This

Cheers

mb

1 Like

Thanks! Perfect!

My little Raspberry Pi must be working hard for some reason as those scripts take some time to execute

1 Like

sorry all, been playing around for a while and cannot work out how to scrape info from my council (if thats the best thing here?)
note: they dont publish a calendar :frowning:


(fake address )

If you right click on the web page and select view source, it will breakdown the page format for
Had a quick look and the title is held in object H3
So if you scrape “h3:nth-of-type(1)” is should return “Your next bin collections for BN14 9EL”
Then just work out what other fields you want after that, so your next scrape would be
“h3:nth-of-type(1) td:nth-of-type(3)” would give your grey bin collection date
Trouble with scrape is you can only scrape one field at a time
So to get 4 sensors, you would have to do 4 scrapes

2 Likes

Thanks!! I was looking at the “inspect” page
Follow ups please

  1. How do you test this without updating your config.yaml and rebooting each time? Or it is painful
  2. Is there a better way then to scape the info you can recommend sorry?

Sorry - its painful, update sensor then reboot to retry
People have used code red to scrape but I haven’t played with that

1 Like

thanks, the first one worked (h3:nth-of-type(1)), however the value for this is always “unknown”

select: “h3:nth-of-type(1) td:nth-of-type(4)”

Thought I would share my setup for this. Fortunately a group from one of the tech schools in my city created an API for waste collection. I wanted to take it a bit further by making a readable version for my wife that displays Next Thursday's pickup is trash only. or Tomorrow's pickup includes recycling.. This template will include “next” if the day is 7 days away or greater and “today” or “tomorrow” when necessary.

image

The sensors used that I made from my city’s API:

  • states.sensor.trash.state returns trash pickup month-day-year. i.e. 1-6-2019
  • states.sensor.trash.state returns recycling pickup month-day-year. i.e. 1-6-2019
  • states.sensor.trash_day returns the pickup’s day of the week. i.e. Monday
- platform: template
  sensors:
    trash_day:
      icon_template: >-
        {% if states.sensor.trash.state == states.sensor.recycling.state %}
          mdi:recycle
        {% else %}
          mdi:delete
        {% endif %}
      value_template: >-
        {% set between = strptime(states.sensor.trash.state, '%m-%d-%Y') - strptime((''~now())[:10], '%Y-%m-%d') %}
        {% set between = float((''~between)[:2]) %}
        {% if between == '0:' %} # when less than a day difference between returns '0:' 
          {% set between = 0 %}  # set to just '0' without the colon
        {% endif %}
        {% set day = states.sensor.trash_day %}
        {% if between > 6 %}
          {% set prefix = 'Next' %}
        {% elif between < 1 %}
          {% set day = 'Today' %}
        {% elif between < 2 %}
          {% set day = 'Tomorrow' %}  
        {% endif %}
        {% if states.sensor.trash.state == states.sensor.recycling.state %}
          {{prefix}} {{day}}'s pickup includes recycling.
        {% else %}
          {{prefix}} {{day}}'s pickup is trash only.
        {% endif %}
1 Like

love this idea…Cant get it to work for me, but love the idea

I’m not sure if it’ll be useful to you folks or not, but inspired by the original post, I wrote a small HTTP server that scrapes the result of the Cheshire East bin collection site, caches and serves the result as an iCalendar file (.ics)

Using this, I can subscribe to the full year’s bin collection schedule using FastMail, Gmail, Outlook, or pretty much any other calendar application, but it will also play nicely with any existing Home Assistant calendar components.

4 Likes

sorry, is anyone able to help with the scrape from this site please?


(fake address )

Hi, I have tried and am unable to grab the data you require with my limited knowledge of scrape, not sure if its the way the web page is built or the fact that they are using a table within the web page, sorry

1 Like

thanks for trying bud :slight_smile:

Try the following - be sure to set scan interval to something sensible - or your council might block your ip

   - platform: scrape
     resource: https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=200004017089&return-url=%2Fbin-day%2F
     name: TestRefuse
     select: 'tr:nth-child(1) > th'
     scan_interval: 86400

If You wanted date

tbody > tr:nth-child(1) > th

1 Like