Leeds bin collections

As an effort to learn node.js I’ve written myself a little app that downloads the bin collection dates and types (black, green, brown) for about three months from data mill north.

If anyone’s interested I could make it a little more robust and post it, don’t know how many people there are here from Leeds.

1 Like

Hi @eggman. I would like to check your script.

regards

Great effort. Im from Wakefield and I had help getting that one working but its broke now.

It’s not so much a script as a small app that sits in docker, I’ve just added configuration options and error checking and swapped out some dependencies that were not robust. Then it’s configured as a rest sensor in ha.

It’s simply parsing a csv file but the file is really big. Another option would be to download the file with wget parse it locally with a shell script and get the data that way. But then I wouldn’t have learnt any JavaScript …

There’s a council web page which has some POST to filter the data: https://www.leeds.gov.uk/residents/bins-and-recycling/check-your-bin-day

But i haven’t been able to figure out how to emulate it. I was thinking I could do a scrape from that using the scrape sensor.

Another route is to reach out to @thomasforth at imactive. I believe he’s also head of data at Open Data Institute Leeds. I wonder if there’s an API we can use rather than pull that big xxxmb file each time?

This might also be useful for some…

https://github.com/odileeds/bins

I’m interested in this to add my Leeds bin collection day / colour etc… to my home assistant. One that updates with bank holidays, Christmas changes etc…

I don’t care what my bin day past the next one, which i think is why we’re all here…
Let their servers do the work. Maybe form fill on the html?

1 Like

Just got this working in my setup:

from datetime import datetime
import json
import pandas as pd
import requests

premises_url = "https://opendata.leeds.gov.uk/downloads/bins/dm_premises.csv"
jobs_url = "https://opendata.leeds.gov.uk/downloads/bins/dm_jobs.csv"

premises = pd.read_csv(premises_url, header=None)

premises = premises.rename(columns={0: "premise_id", 2: "building_number", 3: "street_name"})
my_premise = premises.loc[(premises["building_number"] == "MY HOUSE NUMBER") & (premises["street_name"] == "MY STREET NAME")].copy()
premise_id = my_premise["premise_id"].iloc[0]

jobs = pd.read_csv(jobs_url, header=None)

jobs = jobs.rename(columns={0: "premise_id", 1: "bin_colour", 2: "collection_date"})
my_jobs = jobs.loc[(jobs["premise_id"] == premise_id)].copy()

my_jobs["collection_date"] = pd.to_datetime(my_jobs["collection_date"], format="%d/%m/%y")
my_jobs = my_jobs[(my_jobs["collection_date"] > datetime.today())]
my_jobs = my_jobs.sort_values(by=["bin_colour", "collection_date"])

next_dates = {"black": my_jobs.loc[(my_jobs["bin_colour"] == "BLACK")].copy().nsmallest(1, "collection_date")["collection_date"].iloc[0].strftime("%Y-%m-%d"),
              "brown": my_jobs.loc[(my_jobs["bin_colour"] == "BROWN")].copy().nsmallest(1, "collection_date")["collection_date"].iloc[0].strftime("%Y-%m-%d"),
              "green": my_jobs.loc[(my_jobs["bin_colour"] == "GREEN")].copy().nsmallest(1, "collection_date")["collection_date"].iloc[0].strftime("%Y-%m-%d")}

webhook_url = "MY EXTERNAL WEBHOOK URL"

response = requests.post(webhook_url, json.dumps(next_dates), headers={'Content-Type': 'application/json'})
  • Trigger-based template sensors defined in configuration.yaml take the data from the webhook and create a sensor for each bin type’s next collection date, and these dates are shown on my dashboard
template:
  - trigger:
    - platform: webhook
      allowed_methods:
      - POST
      - PUT
      local_only: false
      webhook_id: "MY INTERNAL WEBHOOK IDENTIFIER"
    sensor:
    - name: "Bins Next Black Collection"
      unique_id: "'sensor.bins_next_black_collection"
      icon: "mdi:calendar"
      state: "{{ as_timestamp(trigger.json.black) | timestamp_custom('%A %d/%m/%Y', true) }}"

  - trigger:
    - platform: webhook
      allowed_methods:
      - POST
      - PUT
      local_only: false
      webhook_id: "MY INTERNAL WEBHOOK IDENTIFIER"
    sensor:
    - name: "Bins Next Brown Collection"
      unique_id: "'sensor.bins_next_brown_collection"
      icon: "mdi:calendar"
      state: "{{ as_timestamp(trigger.json.brown) | timestamp_custom('%A %d/%m/%Y', true) }}"

  - trigger:
    - platform: webhook
      allowed_methods:
      - POST
      - PUT
      local_only: false
      webhook_id: "MY INTERNAL WEBHOOK IDENTIFIER"
    sensor:
    - name: "Bins Next Green Collection"
      unique_id: "'sensor.bins_next_green_collection"
      icon: "mdi:calendar"
      state: "{{ as_timestamp(trigger.json.green) | timestamp_custom('%A %d/%m/%Y', true) }}"
  • Automation runs daily and checks if the next collection dates stored in the sensors are tomorrow - if they are, it sends a notification in the evening to my phone to take the bin(s) out
alias: Bin reminders
description: ""
trigger:
  - platform: time
    at: "19:30:00"
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ strptime(states('sensor.bins_next_black_collection')[-10:],
              '%d/%m/%Y').date() == (now().date() + timedelta(days=1)) }}
        sequence:
          service: notify.MY_MOBILE_DEVICE
          data:
            message: Black bin collection tomorrow
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ strptime(states('sensor.bins_next_brown_collection')[-10:],
              '%d/%m/%Y').date() == (now().date() + timedelta(days=1)) }}
        sequence:
          service: notify.MY_MOBILE_DEVICE
          data:
            message: Brown bin collection tomorrow
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ strptime(states('sensor.bins_next_green_collection')[-10:],
              '%d/%m/%Y').date() == (now().date() + timedelta(days=1)) }}
        sequence:
          service: notify.MY_MOBILE_DEVICE
          data:
            message: Green bin collection tomorrow
mode: single

Hey everyone, i wrote an integration to show next bin dates for leeds council, see info here - GitHub - joemcc-90/leeds-bins-hass: Welcome to Leeds waste collection Home asistant integration! This is an integration to get data from Leeds City Council in the UK and create sensors for each bin type.

Hope this can help someone!

1 Like

giving this a try now.

1 Like