Bin / Waste Collection

Here’s scrape sensors to return the date for pink and grey days:

First “pink” day on page (don’t need an index for the first one, returns “10”):

- platform: scrape
  name: First Pink
  resource: https://apps.castlepoint.gov.uk/cpapps/index.cfm?roadID=2757&fa=wastecalendar.displayDetails
  select: ".pink"

Second “pink” day on page (indexes start at 0, returns “24”):

- platform: scrape
  name: Second Pink
  resource: https://apps.castlepoint.gov.uk/cpapps/index.cfm?roadID=2757&fa=wastecalendar.displayDetails
  select: ".pink"
  index: 1

And you can do the same for the grey days, but the class is .normal in this case (returns “3”).

- platform: scrape
  name: First Grey
  resource: https://apps.castlepoint.gov.uk/cpapps/index.cfm?roadID=2757&fa=wastecalendar.displayDetails
  select: ".normal"

The month header can be grabbed with the following (months are the second and third “h2” on the page, returns “June 2019”)

- platform: scrape
  name: First Month
  resource: https://apps.castlepoint.gov.uk/cpapps/index.cfm?roadID=2757&fa=wastecalendar.displayDetails
  select: "h2"
  index: 1

“.pink” is the css class used for the pink dates, “.normal” for the grey, and “h2” is used for the month headers. Then you just use index to select what number occurrence the element you’re looking for is, index numbers start at zero and go up from there.

1 Like

Hi

https://www.wakefield.gov.uk/site/Where-I-Live-Results?uprn=63121996

This is not my exact address but a random one but how would I scrape that please ?

There isnt a calendar on the page just text

Thanks in advance

Martyn

So here are instructions on how to accomplish this with a scrape sensor, but I will say that I was unable to get a working sensor for it as the wakefield site takes far too long to load and times out.

  1. In chrome right click the element that you want to get and select “inspect”.
  2. In the panel that just opened right click the highlighted element.
  3. Select “copy” then “copy selector”.
  4. Paste the copied selector into the select: field of a scrape sensor.

For the wakefield site, doing this on the date under “last collection” of “household waste” gives us:

#ctl00_PlaceHolderMain_Waste_output > div:nth-child(2) > div:nth-child(2) > div:nth-child(2)

Your sensor would look like this:

- platform: scrape
  resource: https://www.wakefield.gov.uk/site/Where-I-Live-Results?uprn=63121996
  select: "#ctl00_PlaceHolderMain_Waste_output > div:nth-child(2) > div:nth-child(2) > div:nth-child(2)"
3 Likes

Thats amazing, looks so easy but I just couldn’t work it out. Thank you mayker for your time on this.

Is there a way to create and test scrapes without writing them in yaml and restating Hassio each time?

You could scrape the data and then set it to a variable in the template editor and play with the template to get the correct data and then make the sensor and restart. I do that all the time to check I am trying the right options.

Unfortunately not. There are browser plugins to help find out the correct selectors though. Search Google Chrome CSS selector extension

Thanks David and Robbrad, I will look into both methods.

Thank you for explaining and possibly why I wasn’t getting anything but I will keep trying lol

Martyn

Hi,

Sorry for the delay in replying. If you use Node-red the following code will scrap the information, split it into Garden, Recycling, and General waste. Those are then sent via mqtt (which I “sense” in HA for display).

You will need to change the http request for the one you obtain when you enter your postcode, but it appears to be working for me.

[{“id”:“4737b518.c5bcec”,“type”:“inject”,“z”:“3e0d8381.5dd29c”,“name”:"",“topic”:"",“payload”:"",“payloadType”:“date”,“repeat”:“7200”,“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:210,“y”:100,“wires”:[[“686629f7.10a8d8”]]},{“id”:“240a841d.08d0dc”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:false,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:570,“y”:240,“wires”:[]},{“id”:“686629f7.10a8d8”,“type”:“http request”,“z”:“3e0d8381.5dd29c”,“name”:"",“method”:“GET”,“ret”:“txt”,“url”:"",“tls”:"",“x”:350,“y”:200,“wires”:[[“240a841d.08d0dc”,“f489f1db.0789d8”,“9109ca9c.5945c”]]},{“id”:“f489f1db.0789d8”,“type”:“html”,“z”:“3e0d8381.5dd29c”,“name”:"",“property”:“payload”,“outproperty”:“payload”,“tag”:“table[class=“mb10 wilWasteContent gardenFutureData”]”,“ret”:“html”,“as”:“single”,“x”:390,“y”:280,“wires”:[[“8836ed72.79a688”]]},{“id”:“8836ed72.79a688”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:false,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:630,“y”:340,“wires”:[]},{“id”:“9109ca9c.5945c”,“type”:“html”,“z”:“3e0d8381.5dd29c”,“name”:"",“property”:“payload”,“outproperty”:“payload”,“tag”:“div[class=“mb10 ind-waste-wrapper”]”,“ret”:“html”,“as”:“single”,“x”:370,“y”:460,“wires”:[[“c19b6f46.cd128”,“e7255980.dc6a08”,“91d1edf5.05ad3”,“ae205d9f.5ab878”]]},{“id”:“c19b6f46.cd128”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:710,“y”:500,“wires”:[]},{“id”:“e7255980.dc6a08”,“type”:“html”,“z”:“3e0d8381.5dd29c”,“name”:"",“property”:“payload[2]”,“outproperty”:“payload”,“tag”:“div”,“ret”:“html”,“as”:“single”,“x”:810,“y”:440,“wires”:[[“b8414891.1b716”,“ad2e3ccd.e71bf”]]},{“id”:“b8414891.1b716”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload[6]”,“x”:1000,“y”:440,“wires”:[]},{“id”:“91d1edf5.05ad3”,“type”:“html”,“z”:“3e0d8381.5dd29c”,“name”:"",“property”:“payload[1]”,“outproperty”:“payload”,“tag”:“div”,“ret”:“html”,“as”:“single”,“x”:810,“y”:380,“wires”:[[“4503744c.71f94c”,“54055bd3.a99f34”]]},{“id”:“4503744c.71f94c”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload[6]”,“x”:1000,“y”:380,“wires”:[]},{“id”:“ae205d9f.5ab878”,“type”:“html”,“z”:“3e0d8381.5dd29c”,“name”:"",“property”:“payload[0]”,“outproperty”:“payload”,“tag”:“div”,“ret”:“html”,“as”:“single”,“x”:810,“y”:320,“wires”:[[“26ffccf.40081b4”,“1bb9846e.98a20c”]]},{“id”:“26ffccf.40081b4”,“type”:“debug”,“z”:“3e0d8381.5dd29c”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“payload[6]”,“x”:1000,“y”:320,“wires”:[]},{“id”:“87378101.fd7128”,“type”:“mqtt out”,“z”:“3e0d8381.5dd29c”,“name”:"",“topic”:“recycling”,“qos”:“2”,“retain”:“true”,“broker”:“db107b84.66e6”,“x”:1180,“y”:420,“wires”:[]},{“id”:“1cfdde38.c152e2”,“type”:“mqtt out”,“z”:“3e0d8381.5dd29c”,“name”:"",“topic”:“garden”,“qos”:“2”,“retain”:“true”,“broker”:“db107b84.66e6”,“x”:1180,“y”:480,“wires”:[]},{“id”:“1c5197ad.e595e”,“type”:“mqtt out”,“z”:“3e0d8381.5dd29c”,“name”:"",“topic”:“waste”,“qos”:“2”,“retain”:“true”,“broker”:“db107b84.66e6”,“x”:1170,“y”:360,“wires”:[]},{“id”:“1bb9846e.98a20c”,“type”:“function”,“z”:“3e0d8381.5dd29c”,“name”:"",“func”:“msg.payload = msg.payload[6];\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:1010,“y”:360,“wires”:[[“1c5197ad.e595e”]]},{“id”:“54055bd3.a99f34”,“type”:“function”,“z”:“3e0d8381.5dd29c”,“name”:"",“func”:“msg.payload = msg.payload[6];\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:1010,“y”:420,“wires”:[[“87378101.fd7128”]]},{“id”:“ad2e3ccd.e71bf”,“type”:“function”,“z”:“3e0d8381.5dd29c”,“name”:"",“func”:“msg.payload = msg.payload[6];\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:1010,“y”:480,“wires”:[[“1cfdde38.c152e2”]]},{“id”:“db107b84.66e6”,“type”:“mqtt-broker”,“z”:"",“name”:"",“broker”:“localhost”,“port”:“1883”,“clientid”:"",“usetls”:false,“compatmode”:true,“keepalive”:“60”,“cleansession”:true,“birthTopic”:"",“birthQos”:“0”,“birthPayload”:"",“closeTopic”:"",“closeQos”:“0”,“closePayload”:"",“willTopic”:"",“willQos”:“0”,“willPayload”:""}]

Ive run ‘go get github.com/ericchiang/pup’ on my ubuntu distribution and its installed the ‘pup’ file in /go/bin folder. Is there anything else I need to do? as it keeps coming up with

Command ‘pup’ not found, but there are 17 similar ones.

Does running /go/bin/pup work?

/go/bin/pup didn’t but /root/go/bin/pup seem to do something, just a cursor waiting for something to be entered.

59

This is what I get until I press cont+c to stop.

Sorry to be so vague but I’ve searched everywhere I could think of and couldn’t get any information hence posting here.

1 Like

Node - Red maybe the solution for some but I could not copy that code into my Node Red. I got a couple of erros with the " not been correct and then with mb10.

Not sure if its just me but I could not import it via the clipboard to even have a lool

I just tried copying it in myself and can confirm I couldn’t copy it into my work machine’s node-red.

I’ll have a look ino it when I get home tonight.

Sorry about that.

Try the following code. It should work when imported into node-red

[{"id":"6bd549e0.d96d4","type":"inject","z":"6d2074e9.2b7754","name":"","topic":"","payload":"","payloadType":"date","repeat":"7200","crontab":"","once":false,"onceDelay":0.1,"x":189.0833282470703,"y":95.08333587646484,"wires":[["b3b2730b.3be07"]]},{"id":"2dc73fc9.cf3368","type":"debug","z":"6d2074e9.2b7754","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":549.0833282470703,"y":235.08333587646484,"wires":[]},{"id":"b3b2730b.3be07","type":"http request","z":"6d2074e9.2b7754","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","tls":"","proxy":"","x":329.0833282470703,"y":195.08333587646484,"wires":[["2dc73fc9.cf3368","78db4ba6.043e54","a8b94b36.a0584"]]},{"id":"78db4ba6.043e54","type":"html","z":"6d2074e9.2b7754","name":"","property":"payload","outproperty":"payload","tag":"table[class=\"mb10 wilWasteContent gardenFutureData\"]","ret":"html","as":"single","x":369.0833282470703,"y":275.08333587646484,"wires":[["4fb1be76.59b5b"]]},{"id":"4fb1be76.59b5b","type":"debug","z":"6d2074e9.2b7754","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":609.0833282470703,"y":335.08333587646484,"wires":[]},{"id":"a8b94b36.a0584","type":"html","z":"6d2074e9.2b7754","name":"","property":"payload","outproperty":"payload","tag":"div[class=\"mb10 ind-waste-wrapper\"]","ret":"html","as":"single","x":349.0833282470703,"y":455.08333587646484,"wires":[["10d2fba4.d2759c","ef3ab086.9ae69","9ccbed0d.1c919","ff490a6a.2642f"]]},{"id":"10d2fba4.d2759c","type":"debug","z":"6d2074e9.2b7754","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":689.0833282470703,"y":495.08333587646484,"wires":[]},{"id":"ef3ab086.9ae69","type":"html","z":"6d2074e9.2b7754","name":"","property":"payload[2]","outproperty":"payload","tag":"div","ret":"html","as":"single","x":789.0833282470703,"y":435.08333587646484,"wires":[["2e4e9ae5.823cc6","976ff218.a386"]]},{"id":"2e4e9ae5.823cc6","type":"debug","z":"6d2074e9.2b7754","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[6]","x":979.0833282470703,"y":435.08333587646484,"wires":[]},{"id":"9ccbed0d.1c919","type":"html","z":"6d2074e9.2b7754","name":"","property":"payload[1]","outproperty":"payload","tag":"div","ret":"html","as":"single","x":789.0833282470703,"y":375.08333587646484,"wires":[["e32b7bd3.af4ff8","982d95c3.d0179"]]},{"id":"e32b7bd3.af4ff8","type":"debug","z":"6d2074e9.2b7754","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[6]","x":979.0833282470703,"y":375.08333587646484,"wires":[]},{"id":"ff490a6a.2642f","type":"html","z":"6d2074e9.2b7754","name":"","property":"payload[0]","outproperty":"payload","tag":"div","ret":"html","as":"single","x":789.0833282470703,"y":315.08333587646484,"wires":[["3ac0b59d.f3e9da","e17d16c1.f713f"]]},{"id":"3ac0b59d.f3e9da","type":"debug","z":"6d2074e9.2b7754","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[6]","x":979.0833282470703,"y":315.08333587646484,"wires":[]},{"id":"73cf76a6.e1cbb8","type":"mqtt out","z":"6d2074e9.2b7754","name":"","topic":"recycling","qos":"2","retain":"true","broker":"a36b32eb.678dd","x":1159.0833282470703,"y":415.08333587646484,"wires":[]},{"id":"8a22c700.46de08","type":"mqtt out","z":"6d2074e9.2b7754","name":"","topic":"garden","qos":"2","retain":"true","broker":"a36b32eb.678dd","x":1159.0833282470703,"y":475.08333587646484,"wires":[]},{"id":"ebe1053d.985d58","type":"mqtt out","z":"6d2074e9.2b7754","name":"","topic":"waste","qos":"2","retain":"true","broker":"a36b32eb.678dd","x":1149.0833282470703,"y":355.08333587646484,"wires":[]},{"id":"e17d16c1.f713f","type":"function","z":"6d2074e9.2b7754","name":"","func":"msg.payload = msg.payload[6];\nreturn msg;","outputs":1,"noerr":0,"x":989.0833282470703,"y":355.08333587646484,"wires":[["ebe1053d.985d58"]]},{"id":"982d95c3.d0179","type":"function","z":"6d2074e9.2b7754","name":"","func":"msg.payload = msg.payload[6];\nreturn msg;","outputs":1,"noerr":0,"x":989.0833282470703,"y":415.08333587646484,"wires":[["73cf76a6.e1cbb8"]]},{"id":"976ff218.a386","type":"function","z":"6d2074e9.2b7754","name":"","func":"msg.payload = msg.payload[6];\nreturn msg;","outputs":1,"noerr":0,"x":989.0833282470703,"y":475.08333587646484,"wires":[["8a22c700.46de08"]]},{"id":"a36b32eb.678dd","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Hi mate.

Spot on. That actually worked where the scrape didnt. So thank you.

Ive attached my love lace card for now.

Just need to get the colours changed accordingley and maybe change it to countdown days but I will be hooking it up to my Telegram warnings.

Thanks again

Martyn

image

1 Like

Im stumped, Ive been trying to work out how show the next date and colour of rubbish to be placed out a few days in advance.
After using this information - Bin / Waste Collection
Ive created a snippet to show the days count down as in -

{% set day = states.sensor.second_pink_sack.state %}
{% set month = states.sensor.month_current.state %}
{% set datetext = day + month %}
{% set days = strptime(datetext,’%d%B %Y’) | as_timestamp - as_timestamp(now()) %}
{{(days/86400) | round | int}} days

I was intending to make the ‘day’ in the first line a variable and populate it via a ‘if loop’ looking at the ‘now().day’ and ‘<, >, =,’ comparisons containing something like this -

{% set week1 = states.sensor.first_black_sack.state %}
{% set week2 = states.sensor.first_pink_sack.state %}
{% set week3 = states.sensor.second_black_sack.state %}
{% set week4 = states.sensor.second_pink_sack.state %}
{% set week5 = states.sensor.third_black_sack.state %}
{% set week6 = states.sensor.third_pink_sack.state %}

I also create a short snippet to test a ‘if loop’, by manually changing the {“day”:n} number to represent the date changing, it sort of worked -

{% set day = {“day”:19} %}
{{day.day}}

{% if (day.day | int <= states.sensor.first_pink_sack.state |int) and (day.day | int < states.sensor.second_pink_sack.state |int) %}1st pink

{% elif (day.day | int <= states.sensor.second_pink_sack.state |int) and (day.day | int > states.sensor.first_pink_sack.state |int)%}2nd pink

{% elif (day.day | int <= states.sensor.third_pink_sack.state |int) and (day.day | int > states.sensor.second_pink_sack.state |int)%}3nd pink

{% else %}
{%endif%}

I was intending to some how rewrite and merge the snippets together with a automation, but with my limited knowledge in this Im not even sure Im taking the right approach. any pointers on this would be much appreciated.

How do you find the uniqueAddressID ?

If you use the componnent by @yniezink it wil get that for you.
You can also do a post request:

curl -X POST -v -d '{"companyCode":"<REPLACE BY THE COMPANYCODE OF YOUR 
 MUNICIPALTY>", "postCode":"<YOUR POSTCODE>", "houseNumber":"<YOUR HOUSENUMBER>", "houseLetter":"", "houseNumberAddition":""}' http://wasteapi2.2go-mobile.com/api/FetchAdress

Do a callender request trough you local waste-webpage in your municipality and watch the response to post messages. In for example firefox look at the pagesource and than in the networktab. you wil find a post-request FetchAdress. When you sellect that that request you can read the response wich wil give u the UniqueId u need.

1 Like