Bin Day Collection Project

Hi all,

I am attempting a Bin Day Collection project for my HA instance but am pretty new to this type of thing so am feeling my way through.

My council have no type of API so I am using MS Power Automate to create variables of dates and type of bin to put out.

I have created an automation on PA which gets the following:

Bin Day Near (the next date for collection
Bin Day Next (The following date for collection)
Bin 1 Near (Name of bin 1 being collected)
Bin 2 Near (Name of bin 2 being collected)
Bin 1 Next (Name of bin 1 being collected)
Bin 2 Next (Name of bin 2 being collected)

I then created a webhook automation which then delivers the appropriate JSON to HA. To start I have been trying to deliver one date.

{
  "input_text": {
    "webhook_date_near": "15/11/2024",
  }
}

In HA I have added the following to the configuration file to add the sensors I want to push the info to.

template:

  • sensor:
    • name: “Webhook Date Near”
      state: “{{ states(‘input_text.webhook_date_near’) }}”
    • name: “Webhook Date Next”
      state: “{{ states(‘input_text.webhook_date_next’) }}”
    • name: “Webhook Bin 1 Near”
      state: “{{ states(‘input_text.webhook_bin_1_near’) }}”
    • name: “Webhook Bin 2 Near”
      state: “{{ states(‘input_text.webhook_bin_2_near’) }}”
    • name: “Webhook Bin 1 Next”
      state: “{{ states(‘input_text.webhook_bin_1_next’) }}”
    • name: “Webhook Bin 2 Next”
      state: “{{ states(‘input_text.webhook_bin_2_next’) }}”

I have then created the following automation which I was hoping would receive the content but it does not seem to change the sensor I have created.

- id: '1731591540071'
  alias: Webhook Test Date
  description: ''
  triggers:
  - trigger: webhook
    allowed_methods:
    - POST
    - PUT
    local_only: true
    webhook_id: -Qul_xxxxxxxx-xxxxxxxxx
  conditions: []
  actions:
  - action: input_text.set_value
    metadata: {}
    data:
      value: '{{ trigger.json.input_text.webhook_date_near }}'
    target:
      entity_id: input_text.input_text_webhook_date_near
  mode: single

I can see the automation triggers so the webhook part works. But I cannot work out why the sensor stays as ‘Unknown’ on the dashboard.

Any ideas where I am going wrong?

Have you lookes at the “Waste Collection Schedule” integration? It has a large list of supported local authorities

I have, unfortunately my council doesn’t sign up to it. It would have been ideal :frowning:

1 Like

Is schedule available somewhere?
For instance, in my region they have android/ios app with schedule. So I sniffed the app to find out where it calls to get the data, and used that. Then I fed that data to local calendar and am actioning based on that.

Yes, schedule is available on the council website. This is where I am getting the data from and supplying the webhook.

Can’t you use restful or similar methods and feed data into calendar?
Maybe you can post the url with schedule here?
Once you have the data stored, it is only about actioning on it?

The website is Bin Collection Site

I suppose I could, I just thought this would work directly feeding sensors.

How would the calendar way work?

Just seems a real round about way of doing this.

For me, my company has a site where info is stored. So I parsed that data and fed to calendar as events. Benefit for me is - I only need to do it once a year to grab data and store it into calendar.
Here is my script that I used to feed the data.

alias: Waste
sequence:
  - action: rest_command.get_waste_data
    response_variable: waste
    data: {}
  - repeat:
      for_each: "{{ waste.content }}"
      sequence:
        - variables:
            type: "{{ repeat.item.wasteId}}"
            date: "{{ repeat.item.date }}"
            isbiweekly: "{{ repeat.item.isBiweekly }}"
            ismonthly: "{{ repeat.item.isMonthly }}"
        - if:
            - condition: template
              value_template: "{{ type == 2 }} "
          then:
            - if:
                - condition: and
                  conditions:
                    - condition: state
                      entity_id: input_select.waste_frequency
                      state: Bi-Weekly
                    - condition: template
                      value_template: "{{isbiweekly}}"
              then:
                - action: calendar.create_event
                  target:
                    entity_id: calendar.waste
                  data:
                    summary: >-
                      {% if type == 2 %} Mixed {% elif type == 5 %} Paper {%
                      elif type == 7 %} Plastic {% endif %}
                    start_date_time: >-
                      {{as_timestamp(date) | timestamp_custom('%Y-%m-%d
                      08:00:00')}}
                    end_date_time: >-
                      {{as_timestamp(date) | timestamp_custom('%Y-%m-%d
                      10:00:00')}}
            - if:
                - condition: and
                  conditions:
                    - condition: state
                      entity_id: input_select.waste_frequency
                      state: Monthly
                    - condition: template
                      value_template: "{{ismonthly}}"
              then:
                - action: calendar.create_event
                  target:
                    entity_id: calendar.waste
                  data:
                    summary: >-
                      {% if type == 2 %} Mixed {% elif type == 5 %} Paper {%
                      elif type == 7 %} Plastic {% endif %}
                    start_date_time: >-
                      {{as_timestamp(date) | timestamp_custom('%Y-%m-%d
                      08:00:00')}}
                    end_date_time: >-
                      {{as_timestamp(date) | timestamp_custom('%Y-%m-%d
                      10:00:00')}}
        - if:
            - condition: not
              conditions:
                - condition: template
                  value_template: "{{ type == 2 }}"
          then:
            - action: calendar.create_event
              target:
                entity_id: calendar.waste
              data:
                summary: >-
                  {% if type == 2 %} Mixed {% elif type == 5 %} Paper {% elif
                  type == 7 %} Plastic {% endif %}
                start_date_time: "{{as_timestamp(date) | timestamp_custom('%Y-%m-%d 08:00:00')}}"
                end_date_time: "{{as_timestamp(date) | timestamp_custom('%Y-%m-%d 10:00:00')}}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 200
description: ""
icon: mdi:trash-can

I have these selectors for frequency, as this may be different for everyone in region (weekly, bi-weekly, once a month…) and I wanted script to be universal.
Calendar events are between 8-10AM.

Then I have automation to notify me for instance day ahead:

alias: Waste Notifications
description: ""
triggers:
  - alias: Trigger at offset defined by template
    value_template: >-
      {{ (state_attr('calendar.waste', 'start_time')|as_datetime|as_local) -
      now() <
      timedelta(hours=states('input_number.waste_notifiaction_offset')|int) }}
    id: templated-trigger
    trigger: template
conditions: []
actions:
  - if:
      - condition: trigger
        id:
          - templated-trigger
    then:
      - if:
          - condition: state
            entity_id: input_boolean.waste_notification_xxx
            state: "on"
        then:
          - action: notify.xxx_notification
            data:
              message: >-
                {{(state_attr('calendar.waste', 'message'))}} waste will be
                collected tomorrow
              title: Collect Garbage
              data:
                notification_icon: mdi:delete-empty
                channel: Waste
                sticky: true
      - if:
          - condition: state
            entity_id: input_boolean.waste_notification_xxx
            state: "on"
        then:
          - action: notify.xxx_notification
            data:
              message: >-
                {{(state_attr('calendar.waste', 'message'))}} waste will be
                collected tomorrow
              title: Collect Garbage
              data:
                notification_icon: mdi:delete-empty
                channel: Waste
                sticky: true
mode: single

I also have badges on dashboard if event is coming up in next day/7 days

That’s brilliant. But I wish my council was that good! It doesn’t have a way of downloading my own collection days for the year.

But thinking about what you have done, I could get the contents of this table from the site and then just do the script more frequently applying the bins to the relevant dates in a calendar.

Then I could run an automation to tell me which bins are due a day before like you have.

Which is the best external calendar to use with HA?

Why external? There is local calendar as default integration.
I looked at the site - wondering if this is the schedule until end of year? What would be there at the beginning of the year? Basically you can get the data in a form (file?) and then just use script to feed it into calendar

Your automation is setting the value of input_text.input_text_webhook_date_near - is that intentional?

Yes, the intention was to take the value of the nearest date from that table and push that with json via the we hook to webhook_date_near sensor on HA.

Right, but isn’t the sensor looking for input_text.webhook_date_near?

Found this: GitHub - robbrad/UKBinCollectionData: UK Council Bin Collection Data Parser Outputting Bin Data as a JSON

Seems like Dartford is supported?

I am not sure where you are seeing this :neutral_face:

I have made a lot of progress though.

I realised that from Power Automate I had to set up individual webhooks for each bit of info, but they are all set up to be sent together.

I have successfully pushed the data to the individual entities on HA and then have been able to show them on my dashboard. The automation waits for the webhook and then updates the entities and it is instant!

I was able to then set within the cards the ability to if ‘GARDEN’ is the value, then the bin would go brown or if ‘REFUSE’ then green and it works really well.

I have the near dated bins on my ‘Home’ page for quick access.

I then set up an automation that every Thursday at 17.30, a message is sent to my wife and I to notify us which bins need to go out which simply says “Tomorrow’s bins are Green and Brown”.

I am really happy with the outcome and now I am being asked by neighbours to send to them…I may look at pushing to WhatsApp to see if this is possible.

Dartford Borough Council

Is it not the same thing?

You are right, thanks for the link.

Quite happy with my progress so will my automations.