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.
Test Postcode : MK43 9JT
Address: pick any from the drop down list.
then how to get that specific data?
Thanks in Advance.
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.
Is for number 10 in the postcode area you gave.
So, I decided to take a shot at scraping the data from my county’s trash and recycling collection site:
https://www.baltimorecountymd.gov/Agencies/publicworks/solid_waste/collection-schedule.html
*Note: This is not my real address.
Here’s what my sensors look like:
- platform: scrape
resource: https://www.baltimorecountymd.gov/Agencies/publicworks/solid_waste/collection-schedule.html#/schedule/123%201ST%20AVE
name: Trash Collection Occurs
select: "tr:nth-of-type(1) td:nth-of-type(2)"
- platform: scrape
resource: https://www.baltimorecountymd.gov/Agencies/publicworks/solid_waste/collection-schedule.html#/schedule/123%201ST%20AVE
name: Recycling Collection Occurs
select: "tr:nth-of-type(2) td:nth-of-type(2)"
- platform: scrape
resource: https://www.baltimorecountymd.gov/Agencies/publicworks/solid_waste/collection-schedule.html#/schedule/123%201ST%20AVE
name: Trash Next Collection
select: "tr:nth-of-type(1) td:nth-of-type(3)"
- platform: scrape
resource: https://www.baltimorecountymd.gov/Agencies/publicworks/solid_waste/collection-schedule.html#/schedule/123%201ST%20AVE
name: Recycling Next Collection
select: "tr:nth-of-type(2) td:nth-of-type(3)"
However, in all of my attempts, the values are only returning unavailable.
Evidently 2020 having 53 weeks means 2021 has swapped odd/even weeks for my council’s schedule.
Simple enough to swap the bin types around in the Python code though.
import datetime
today = datetime.date.today()
if today.weekday() > 3:
# If this Thursday has passed, we only care about next week.
today = today + datetime.timedelta((0 - today.weekday()) % 7)
# Get the ISO week number (1-52~53)
week_number = today.isocalendar()[1]
if (week_number % 2) == 0:
# Even weeks are for Recycling
collection_type = 'Recycling'
else:
# Odd weeks are for Garden Waste
collection_type = 'Garden Waste'
print(collection_type)
And just as a refresher (for those searching, and have a simple week-about schedule), these are the sensors…
sensor:
- platform: command_line
name: bintype
command: "python3 /config/python_scripts/bin_week.py"
- platform: template
sensors:
bincol:
friendly_name: "This week's bin"
value_template: '{{ states("sensor.bintype") }}'
entity_picture_template: >
{% if is_state('sensor.bintype', 'Recycling') %}
/local/images/bin_yellow.png
{% elif is_state('sensor.bintype', 'Garden Waste') %}
/local/images/bin_green.png
{% endif %}
… and my two bin images (just recoloured mdi-trash-can-outline)
Hi,
Somewhat embarrassing but I’m struggling to get the sensors set up correctly. I’ve got a JSON file created correctly from the website and made a cronfile to update it daily, but every attempt I make at creating the home assistant sensors is resulting in one error or another. Been at this for hours, so after a little help please even though this is probably supposed to be the easy bit! Could someone show me how to create a sensor to just display some basic information from the JSON data? Aim will be next collection of each bin type.
Here’s a copy of the JSON file:
{
"bins": [
{
"BinType": "Empty Standard Mixed Recycling",
"collectionDate": "07/04/2021"
},
{
"BinType": "Empty Standard Garden Waste",
"collectionDate": "07/04/2021"
},
{
"BinType": "Empty Standard General Waste",
"collectionDate": "14/04/2021"
},
{
"BinType": "Empty Standard Garden Waste",
"collectionDate": "21/04/2021"
},
{
"BinType": "Empty Standard Mixed Recycling",
"collectionDate": "21/04/2021"
},
{
"BinType": "Empty Standard General Waste",
"collectionDate": "28/04/2021"
},
{
"BinType": "Empty Standard Mixed Recycling",
"collectionDate": "05/05/2021"
},
{
"BinType": "Empty Standard Garden Waste",
"collectionDate": "05/05/2021"
},
{
"BinType": "Empty Standard General Waste",
"collectionDate": "12/05/2021"
},
{
"BinType": "Empty Standard Mixed Recycling",
"collectionDate": "19/05/2021"
}
]
}
And one of the many sensor configs I’ve tried, which I know is miles off and thus the plea for help
It can see the file, but my parsing is just miles off I’m assuming.
sensor:
- platform: file
file_path: customjson/bins2.json
name: "Black Bin"
value_template: '{{ value_json["bins"] }}'
Hi,
I’ve been trying to get this working but all the councils listed in this thread all seem simpler to my council’s website. Is anyone able to see if this website format will be able to be added into home assistant?
https://self.maidstone.gov.uk/service/check_your_bin_day
You can use ME16 9FX for the postcode
Thanks
Are they on a regular cycle? If so, use this is my suggestion:
And there is a corresponding lovelace card
It normally is on a regular cycle but quite often they have staff shortages so change the days around. Also is different around Xmas.
Was hoping to have it pull directly from the website like some of the examples in this thread but will check out those custom components. Thanks!
Hi, Can someone help me get the past and present collection dates from the Harrow council website. I tried the suggestions of doing F12 via chrome but the site uses widgets to display the data.
On the element page i have managed to drill down and see that the data is displayed here. After that i am not sure how to proceed.
Please can anyone help point me in the right direction.
Hi mate - there is a much easier way of doing this using the REST sensor (RESTful Sensor - Home Assistant) in Home Assistant
Given Harrow council is :
https://www.harrow.gov.uk/site/custom_scripts/harrow/ajax/bin_collections.php?u=100021261750 with a u{id} of 100021261750 (this uid is for your property)
The result is a nice JSON which can be consumed using the above mentioned sensor - MAKE SURE you set scan_interval you dont want to be hammering the council API
Hi Rob,
That’s spot on. I would like to learn how to get these kind of details. would be able to tell me how you went about finding this info please.
GIVE A MAN a fish and you feed him for a day. Teach him how to fish and you feed him for his life time.
Much appreciated.
Raj
Light a man a fire and you keep him warm for a day. Set a man on fire and you keep him warm for the rest of his life.
Sorry couldn’t resist.
Network tab in browser web console is your friend
See the two highlighted links on the right - you can right click and copy the whole URL from it
I agree with Nickrout - the garbage/recycling addon works really well for tracking these on a regular schedule.
Quick start guide here if anyone needs it: https://smarthomepursuits.com/how-to-setup-garbage-collection-reminder/
Hey @Robbrad
I am trying to use the REST sensor as you suggested and have got under the resource part the full address i.e. : https://www.harrow.gov.uk/site/custom_scripts/harrow/ajax/bin_collections.php?u=100021261750 but it doesn’t work and throws an error.
Can you please show me how I can configure it?
Thanks.
these are my errors:
2021-09-22 15:59:18 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform rest is taking over 10 seconds.
2021-09-22 15:59:18 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform rest
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 587, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 698, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 464, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 578, in _async_write_ha_state
self.hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 1219, in async_set
state = State(
File "/usr/src/homeassistant/homeassistant/core.py", line 907, in __init__
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.harrow_bin. State max length is 255 characters.
2021-09-22 15:59:18 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up rest platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 257, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 587, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 698, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 464, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 578, in _async_write_ha_state
self.hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 1219, in async_set
state = State(
File "/usr/src/homeassistant/homeassistant/core.py", line 907, in __init__
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.harrow_bin. State max length is 255 characters.
and my configuration is:
sensor:
- platform: rest
name: Harrow Bin
resource: http://www.harrow.gov.uk/site/custom_scripts/harrow/ajax/bin_collections.php?u=100021261750
scan_interval: 15
Your pulling the JSON but you need a way to parse the output
At the moment the sensor state is the whole output - hence the error at the bottom saying Invalid state encountered for entity ID: sensor.harrow_bin. State max length is 255 characters
See the examples further down on the page RESTful Sensor - Home Assistant
For example
https://api.github.com/repos/home-assistant/home-assistant/releases/latest yeilds
{
"url": "https://api.github.com/repos/home-assistant/core/releases/49796565",
"assets_url": "https://api.github.com/repos/home-assistant/core/releases/49796565/assets",
"upload_url": "https://uploads.github.com/repos/home-assistant/core/releases/49796565/assets{?name,label}",
"html_url": "https://github.com/home-assistant/core/releases/tag/2021.9.7",
"id": 49796565,
"author": {
"login": "balloob",
"id": 1444314,
"node_id": "MDQ6VXNlcjE0NDQzMTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1444314?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/balloob",
"html_url": "https://github.com/balloob",
"followers_url": "https://api.github.com/users/balloob/followers",
"following_url": "https://api.github.com/users/balloob/following{/other_user}",
"gists_url": "https://api.github.com/users/balloob/gists{/gist_id}",
"starred_url": "https://api.github.com/users/balloob/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/balloob/subscriptions",
"organizations_url": "https://api.github.com/users/balloob/orgs",
"repos_url": "https://api.github.com/users/balloob/repos",
"events_url": "https://api.github.com/users/balloob/events{/privacy}",
"received_events_url": "https://api.github.com/users/balloob/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOAMSroc4C99XV",
"tag_name": "2021.9.7",
"target_commitish": "master",
"name": "2021.9.7",
"draft": false,
"prerelease": false,
"created_at": "2021-09-18T15:29:25Z",
"published_at": "2021-09-18T15:29:44Z",
"assets": [
],
"tarball_url": "https://api.github.com/repos/home-assistant/core/tarball/2021.9.7",
"zipball_url": "https://api.github.com/repos/home-assistant/core/zipball/2021.9.7",
"body": "- Support incoming SMS messages via polling ([@ocalvo] - [#54237]) ([sms docs])\r\n- Fix generic thermostat switch state initialization ([@brianegge] - [#56073]) ([generic_thermostat docs])\r\n- Bump growattServer to 1.1.0 ([@muppet3000] - [#56084]) ([growatt_server docs])\r\n- Ensure rainmachine device name is a string ([@bdraco] - [#56121]) ([rainmachine docs])\r\n- Bump pykodi to 0.2.6 ([@mxilievski] - [#56148]) ([kodi docs])\r\n- Bump plexapi to 4.7.1 ([@jjlawren] - [#56163]) ([plex docs])\r\n- Update docker base image to 2021.09.0 ([@ludeeus] - [#56191])\r\n- Fix HomeKit requests with hvac mode and temperature in the same call ([@bdraco] - [#56239]) ([homekit docs])\r\n- Bump pyopenuv to 2.2.1 ([@bachya] - [#56270]) ([openuv docs])\r\n- Bump pychromecast to 9.2.1 ([@emontnemery] - [#56296]) ([cast docs])\r\n- Avoid sending Standby when already off ([@elupus] - [#56306]) ([philips_js docs])\r\n- Bump aioswitcher to 2.0.6 ([@thecode] - [#56358]) ([switcher_kis docs])\r\n- Fix yeelight nightlight mode ([@bdraco] - [#56363]) ([yeelight docs])\r\n- Fetch the data a second time when -9999 error occurs in Xiaomi Miio integration ([@bieniu] - [#56288]) ([xiaomi_miio docs])\r\n\r\n[#54237]: https://github.com/home-assistant/core/pull/54237\r\n[#56073]: https://github.com/home-assistant/core/pull/56073\r\n[#56084]: https://github.com/home-assistant/core/pull/56084\r\n[#56121]: https://github.com/home-assistant/core/pull/56121\r\n[#56148]: https://github.com/home-assistant/core/pull/56148\r\n[#56163]: https://github.com/home-assistant/core/pull/56163\r\n[#56191]: https://github.com/home-assistant/core/pull/56191\r\n[#56239]: https://github.com/home-assistant/core/pull/56239\r\n[#56270]: https://github.com/home-assistant/core/pull/56270\r\n[#56288]: https://github.com/home-assistant/core/pull/56288\r\n[#56296]: https://github.com/home-assistant/core/pull/56296\r\n[#56306]: https://github.com/home-assistant/core/pull/56306\r\n[#56358]: https://github.com/home-assistant/core/pull/56358\r\n[#56363]: https://github.com/home-assistant/core/pull/56363\r\n[@bachya]: https://github.com/bachya\r\n[@bdraco]: https://github.com/bdraco\r\n[@bieniu]: https://github.com/bieniu\r\n[@brianegge]: https://github.com/brianegge\r\n[@elupus]: https://github.com/elupus\r\n[@emontnemery]: https://github.com/emontnemery\r\n[@jjlawren]: https://github.com/jjlawren\r\n[@ludeeus]: https://github.com/ludeeus\r\n[@muppet3000]: https://github.com/muppet3000\r\n[@mxilievski]: https://github.com/mxilievski\r\n[@ocalvo]: https://github.com/ocalvo\r\n[@thecode]: https://github.com/thecode\r\n[cast docs]: https://www.home-assistant.io/integrations/cast/\r\n[generic_thermostat docs]: https://www.home-assistant.io/integrations/generic_thermostat/\r\n[growatt_server docs]: https://www.home-assistant.io/integrations/growatt_server/\r\n[homekit docs]: https://www.home-assistant.io/integrations/homekit/\r\n[kodi docs]: https://www.home-assistant.io/integrations/kodi/\r\n[openuv docs]: https://www.home-assistant.io/integrations/openuv/\r\n[philips_js docs]: https://www.home-assistant.io/integrations/philips_js/\r\n[plex docs]: https://www.home-assistant.io/integrations/plex/\r\n[rainmachine docs]: https://www.home-assistant.io/integrations/rainmachine/\r\n[sms docs]: https://www.home-assistant.io/integrations/sms/\r\n[switcher_kis docs]: https://www.home-assistant.io/integrations/switcher_kis/\r\n[xiaomi_miio docs]: https://www.home-assistant.io/integrations/xiaomi_miio/\r\n[yeelight docs]: https://www.home-assistant.io/integrations/yeelight/"
}
And value_template: "{{ value_json.tag_name }}"
returns 2021.9.7
Make sense?