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 %}