Skip to content

ValeofWhiteHorseCouncil: returns the previous collection date for the bin collected earlier in the fortnight #2213

Closed

Description

@dpage

Council

ValeofWhiteHorseCouncil

Version

uk_bin_collection 0.171.3, via the Home Assistant integration of the same version.

What happens

For whichever bin was collected earlier in the current fortnight, the scraper returns that past collection date rather than the next one. Running it today, 22 August 2026:

{
    "bins": [
        { "type": "Rubbish",   "collectionDate": "17/08/2026" },
        { "type": "Recycling", "collectionDate": "24/08/2026" }
    ]
}

17 August has been and gone; the next rubbish collection is 31 August.

Why

The council page publishes the current fortnight's pair rather than the next occurrence of each bin, and both panels are parsed verbatim:

It's rubbish week      Monday 17 August -   grey bin, small electrical items and food bin
It's recycling week    Monday 24 August -   food bin, green bin, textiles and garden waste bin

get_next_occurrence_from_day_month() is called on each, but the result then has its year forced to the current year, so a date earlier in the same year cannot roll forward.

Effect in Home Assistant

The integration only creates entities for collections still in the future, so every Rubbish entity disappears for roughly a week each fortnight, then returns and takes Recycling with it when the page flips. The raw JSON sensor holds a single key during that window:

{"raw_data": {"Recycling": "2026-08-24"}}

Any dashboard card or automation pointing at a specific bin's sensors therefore goes unavailable every other week, which is how I noticed. Entities that vanish and reappear are also awkward to template around, since there is nothing stable to reference.

Suggested fix

Collections here alternate weekly between the two bins, so each bin is fortnightly. Where the parsed date is before today, advancing it by 14 days gives the correct next collection: 17 August plus 14 is 31 August, which matches the council's own schedule.

Minor, and separate

bin_colour is computed at lines 75 and 78 of ValeofWhiteHorseCouncil.py and then never added to dict_data, so it is dead code. Worth noting that passing it through would not change anything on the Home Assistant side by itself, since the integration derives the colour solely from the icon_color_mapping option and ignores any colour in the bin data; but as it stands the scraper computes a value it cannot use.

To reproduce

python -m uk_bin_collection.uk_bin_collection.collect_data ValeofWhiteHorseCouncil \
  "https://eform.whitehorsedc.gov.uk/ebase/BINZONE_DESKTOP.eb" -u <any Vale of White Horse UPRN> -s

Run it in the week following a rubbish collection and the returned rubbish date will be in the past.

Activity

  1. robbrad commented on Sep 2, 2026

    @robbrad
    Owner

    Excellent diagnosis — confirmed exactly right and fixed as you suggested.

    get_next_occurrence_from_day_month()'s year adjustment was being thrown away immediately by the unconditional bin_date.replace(year=current_year) right after it, so it never actually took effect — and a full-year roll-forward was the wrong tool for a fortnightly schedule anyway. Replaced with day-based rollover (add 14 days until the date is genuinely upcoming), which also naturally handles the Dec→Jan boundary without the separate special case that was there before.

    Verified live with your exact worked example: 17 August correctly rolls forward to 31 August now, and both Rubbish and Recycling return future dates instead of the current fortnight's stale pair. Also dropped the dead bin_colour variable you flagged. Included in the September release PR. Thanks for such a precise report — made this an easy fix.

  2. dpage commented on Sep 3, 2026

    @dpage
    Author

    Thanks for the fix!

  3. sammort commented on Sep 11, 2026

    @sammort
    Contributor

    In the example given, 31st August was a Bank Holiday, so there would not have been a bin collection on that day.

    I think it's worse to give false, inferred information than it is to wait until the source of truth actually holds the correct bin collection date.

  4. dpage commented on Sep 11, 2026

    @dpage
    Author

    Fair point on the 31st, and it's not just Christmas: the council moves collections on every bank holiday, so an inferred date in any bank holiday week will be wrong.

    I'd put the trade-off differently, though. Before the fix the scraper wasn't waiting for the source of truth; it returned 17 August on 22 August, which is just as false a "next collection" as 31 August, and in Home Assistant it made the entity vanish for a week every fortnight. So it was roughly 26 weeks a year of a stale or missing bin, against about eight weeks a year where the inferred date can be a day out for the few days until the page flips and the real date is read.

    There's a middle path that gives you the "don't invent it" behaviour exactly where inference is unreliable: #2229 keeps the roll-forward but skips it when the resulting week contains a bank holiday (using the package's existing is_holiday()), leaving that bin out until the page shows the rescheduled date. Dates the page states outright are returned as they are, as before.

  5. sammort commented on Sep 11, 2026

    @sammort
    Contributor

    Yes that's an excellent middle-path 🙌🏼

  6. dpage commented on Sep 11, 2026

    @dpage
    Author

    Except it breaks at Christmas :-(. Working on that now....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions