JAN 2020 Update: Created a Repo for this on GitHub https://github.com/robbrad/UKBinCollectionData Raise an issue to get your council added - or do it yourself with a pull request.
It’s quite annoying not knowing which bin colour you need to take out and our council doesn’t distribute the fridge magnet calendars anymore. There are three bins, General waste, Recycling and Garden (Black/Gray and Green)
More often than not we are the last to take our bins out to the street because we want to see what colour people have taken out - A flawed system, because the day the first person takes their bin out gets it wrong, will be the day everyone gets it wrong and the end of the world.
Home Assistant to the rescue. WARNING the following is not pretty.
The council in the UK (Cheshire East) are kind enough to provide a calendar, but no api or fancy way to get the raw data. To make things worse one week it’s one bin and the next week its two bins!
Website to parse: http://online.cheshireeast.gov.uk/MyCollectionDay/
I thought could I capture the table from this page and somehow parse it. I had to work out the post URL from the result page, find the class of the table and export the data.
Software required: curl, pup and jq
Using my Ubuntu Home Assistant Server I created a script to curl the url out to a JSON - I run a cron job each Thursday night after collection to refresh the JSON data
#!/bin/sh
curl -s "http://online.cheshireeast.gov.uk/MyCollectionDay/?##################" | pup '.wasteType td json{}' > binCollection.json
Perfect - I now had the following result
[
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_grey_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "31-May-2018"
},
{
"tag": "td",
"text": "Recycling wheeled bin"
},
{
"tag": "td"
},
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_brown_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "31-May-2018"
},
{
"tag": "td",
"text": "Garden Waste wheeled bin"
},
{
"tag": "td"
},
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_black_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "07-Jun-2018"
},
{
"tag": "td",
"text": "Other Waste wheeled bin"
},
{
"tag": "td"
},
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_grey_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "14-Jun-2018"
},
{
"tag": "td",
"text": "Recycling wheeled bin"
},
{
"tag": "td"
},
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_brown_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "14-Jun-2018"
},
{
"tag": "td",
"text": "Garden Waste wheeled bin"
},
{
"tag": "td"
},
{
"children": [
{
"alt": "bin image",
"src": "Images/bin_black_32.gif",
"tag": "img"
}
],
"class": "imgCell",
"tag": "td"
},
{
"tag": "td",
"text": "Thursday"
},
{
"tag": "td",
"text": "21-Jun-2018"
},
{
"tag": "td",
"text": "Other Waste wheeled bin"
},
{
"tag": "td"
}
]
I created another script to parse that data which my sensor in Home Assistant could run
#!/bin/sh
cat /home/user/scripts/binCollection.json | jq '.[].text'| grep ` date -d 'this Thursday' '+%d-%b-%Y'` -A1| grep bin | tr -d '"' | head -n 1
Now I have my parse data I have the following in my sensors.yaml
- platform: command_line
command: '/home/user/scripts/parseBinCollection.sh'
name: BinCollectionType
To make this look nicer I colour my sensor icon based on the bin to be collected in my customize_sensors.yaml - kudos to @Mikeinnc
sensor.BinCollectionType:
friendly_name: Bin Collection Type
icon: mdi:delete
templates:
icon_color: >
if (state === 'Other Waste wheeled bin') return 'rgb(0,0,0)';
if (state === 'Recycling wheeled bin') return 'rgb(128,128,128)';
if (state === 'Garden Waste wheeled bin') return 'rgb(139,69,19)';
return 'rgb(68,115,158)';
hidden: if (state === '') return true;;
Result!
The second bin type is in the second sensor (couldn’t think of a better way to represent this - for the day when there are two bins - might be nice to hide this sensor in some why when the result is unknown) - UPDATE using hidden in the template when the state is nothing worked - there was an issue in my script, but now the sensor hides when there is no value - e.g. every other week
I’m quite happy with this result and it saves me having to check the website or risk the wrong bin being taken out - it’s a total hack and will probably fail, eventually.