Current command_line for parseBinCollection.sh below, if any of it is recyclable: cat /config/scripts/binCollection.json | jq ‘…|.“text”? | select (. !=null)’ | tr -d ‘"’ | grep Bin -A3
#!/usr/bin/env python3
#This script pulls (in one hit) the data from Chelmsford Council Bins Data
#import the wonderful Beautiful Soup and the URL grabber
from urllib.request import Request, urlopen
import json
from bs4 import BeautifulSoup
#Set a user agent so we look like a browser ;-)
user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'
headers = {'User-Agent': user_agent}
#Make the Request
req = Request('https://mychelmsford.secure.force.com/WasteServices/WM_WasteViewProperty?id=a02240000054H2rAAE')
req.add_header('User-Agent', user_agent)
fp = urlopen(req).read()
#decode the page
page = fp.decode("utf8")
#Make a BS4 object
soup = BeautifulSoup(page, features="html.parser")
soup.prettify()
#Form a JSON wrapper
data = {"bins":[]}
#Search for the specific table using BS4
rows = soup.find("tbody", {"id" : lambda L: L and L.startswith('Registration:')}).find_all("tr")
#Loops the Rows
for row in rows:
#set the vars per bin and date for each row
cells = row.find_all("td")
binType = cells[1].get_text()
lcDate = cells[2].get_text()
ncDate = cells[3].get_text()
fcDate = cells[4].get_text()
#Make each Bin element in the JSON
dict_data = {
"BinType": binType,
"Last Collection Date": lcDate,
"Next Collection Date": ncDate,
"Following Collection Date": fcDate,
}
#Add data to the main JSON Wrapper
data["bins"].append(dict_data)
#Make the JSON
json_data = json.dumps(data,sort_keys=True, indent=4)
#Output the data - run this script with a redirect to send the output to a file
#Suggest Crontab
print(json_data)
{"recordCount":2,"jobs_FeatureScheduleDates":[{"jobID":9573337,"jobName":"Empty Bin 240L Black","jobDescription":"Empty Bin 240L Black","jobStatus":"Not Started","previousDate":"2020-01-14T09:23:27.173","nextDate":"2020-01-28T07:00:00","rescheduledDate":"0001-01-01T00:00:00","rescheduledDateSpecified":false,"rescheduledReason":"","uprn":100090181402,"usrn":30101686,"address1":"","address2":"12","street":"CANTERBURY ROAD","locality":"WERRINGTON","town":"PETERBOROUGH","postCode":"PE4 6PE","easting":516645,"northing":303330,"longitude":-0.278563,"latitude":52.615194},{"jobID":9584045,"jobName":"Empty Bin 240L Green","jobDescription":"Empty Bin 240L Green","jobStatus":"Not Started","previousDate":"2020-01-21T11:53:24.833","nextDate":"2020-02-04T07:00:00","rescheduledDate":"0001-01-01T00:00:00","rescheduledDateSpecified":false,"rescheduledReason":"","uprn":100090181402,"usrn":30101686,"address1":"","address2":"12","street":"CANTERBURY ROAD","locality":"WERRINGTON","town":"PETERBOROUGH","postCode":"PE4 6PE","easting":516645,"northing":303330,"longitude":-0.278563,"latitude":52.615194}]}
I would like the ‘jobName’ and ‘nextDate’ collected - one for the Black bin (jobID: 9573337) and one for the Green bin (jobID: 9584045).
jobs_FeatureScheduleDates:
- jobID: 9573337
jobName: Empty Bin 240L Black
jobDescription: Empty Bin 240L Black
jobStatus: Not Started
previousDate: '2020-01-28T09:52:17.837'
nextDate: '2020-02-11T07:00:00'
rescheduledDate: '0001-01-01T00:00:00'
rescheduledDateSpecified: false
rescheduledReason: ''
uprn: 100090181402
usrn: 30101686
address1: ''
address2: '12'
street: CANTERBURY ROAD
locality: WERRINGTON
town: PETERBOROUGH
postCode: PE4 6PE
easting: xx
northing: xx
longitude: xx
latitude: xx
- jobID: 9584045
jobName: Empty Bin 240L Green
jobDescription: Empty Bin 240L Green
jobStatus: Not Started
previousDate: '2020-01-21T11:53:24.833'
nextDate: '2020-02-04T07:00:00'
rescheduledDate: '0001-01-01T00:00:00'
rescheduledDateSpecified: false
rescheduledReason: ''
uprn: 100090181402
usrn: 30101686
address1: ''
address2: '12'
street: CANTERBURY ROAD
locality: WERRINGTON
town: PETERBOROUGH
postCode: xx
easting: xx
northing: xx
longitude: xx
latitude: xx
friendly_name: bindates
The template sensor does not work. Can anyone help with what am I doing wrong? Is it something to do with the fact everything is a sub attribute of jobs_FeatureScheduleDates?
yeah it worked well, all i had to also do was have HA update the sensor value, im sure there is a better way but all i did was added it to one of my daily automations
Nice idea, thanks. My council have a rather tricky way of getting data, they send a token which needs to be added to a 2nd Curl command, I’ll see if I can add an easy way of doing it.
Hi All, different post but on similar subject. I have an automation to advise me at 1800hrs on garbage night to put the bin out. Its a TTS but it continually fails. I tried another test automation with tts at a time trigger and it worked. Can anyone please advise why this might be not working.
id: ‘1xxxxxxxxxx’
alias: Garbage Reminder
description: TTS warning for putting Garbage Out
trigger:
at: ‘18:00:00’
platform: time
condition:
condition: state
entity_id: sensor.garbage
state: ‘0’
action:
data:
entity_id: media_player.all_speakers
message: Hi. Dont forget to take the bin out.
service: tts.google_say
Lichfield (UK) is a beautiful place to live, with one huge caveat that sends shudders through the thousands of households: the council’s bin collection URL isn’t particularly machine-readable.
EDIT: prior config removed as it no longer applies, as the council restructured the web calendar. If you were looking for this, the HACS Waste Collection Schedule now supports our leafy city.
That’s going to be tricky, I’m afraid. The page is even less scrapable than Lichfield’s. There is an API request going on behind the scenes: it’s a POST request to https://api.cardiff.gov.uk/WasteManagement/api/WasteCollection with a payload like {"systemReference":"web","language":"eng","uprn":100100085369} (uprn is unique property reference number at a guess: that one is from the postcode you suggested).
That call returns something useful like this (including typo right at the start!):
but the API is set up with security to prevent calls other than from that webpage (which generates an Authorization: Bearer cookie as a “password”), which is a real shame. Perhaps it might be worth trying to contact someone techie in the council to get this opened up? Failing that, perhaps move to a different area
Thanks for taking a look. Trust my council to be the arkward one - but hey at least I know nobody will steal my bin collection days - classified information
You know I struggled with getting my bin collection from my council’s api. Then I gave up and went with this custom component. Unless you have some really weird random collection cycle, it copes really well. https://github.com/bruxy70/Garbage-Collection
Hi Everybody.
Previously I have managed to cobble things together and get a working output. I have since moved and am now battling with a new Council website. There doesn’t appear to be an easily accessible UTRN or other identifier… I can see. looked at URL, but then you have to put postcode into page, it then does an HTTP post & download, then you enter your address from the list and it then downloads the correct data. I cant see a way to do this as before. Any assistance would be greatly appreciated.
If you use the web-console (F12 in chrome / edge-chromium) and go to the network view, then follow through to where you want to go and you’ll be able to pick out the URL to your address, i.e.