Code Monkey home page Code Monkey logo

christchurch-bins-with-home-assistant's Introduction

Christchurch Bins integration with Home Assistant

Christchurch [New Zealand] City Council has a great website for checking what bins need to go out for collection

image-20211127165316748

Setting up the Data for Home Assistant

To integrate with Home Assistant you need to find out the property ID of your address

Using the information on the lookup.js

https://ccc.govt.nz/resources/ccc-kerbside/client/dist/js/lookuptool.js

image-20211127170317178

You can use the rest URL followed by your house number + street address

https://opendata.ccc.govt.nz/CCCSearch/rest/address/suggest?q=

Example:

https://opendata.ccc.govt.nz/CCCSearch/rest/address/suggest?q=53+Hereford

you will need the "RatingUnitID"

image-20211127170041061

Now using the information on the lookup.js again all we need to do is use the original website with "/getProperty?ID=[RatingUnitID]":

image-20211127170759542

image-20211127170831635

Example:

https://ccc.govt.nz/services/rubbish-and-recycling/collections/getProperty?ID=86089

That will give you a JSON output of that property:

image-20211127171207369

Home Assistant

We need to add the scraping from the API into the configuration.yaml and some logic to get the bin of the week for lovelace

sensor:
  - platform: rest
    resource: https://ccc.govt.nz/services/rubbish-and-recycling/collections/getProperty?ID=86089
    method: GET
    name: "Christchurch Bin Type"
    value_template: >
      {% set value_json_sort = value_json.bins.collections | sort(attribute='next_planned_date') | rejectattr('next_planned_date', 'le', (now().strftime('%Y-%m-%d')|string)) %}
      {% set value_json = value_json_sort | rejectattr('material', 'equalto', 'Organic') | map(attribute='material') | list | first %}
      {{ value_json}}
    scan_interval: 43200
  - platform: rest
    resource: https://ccc.govt.nz/services/rubbish-and-recycling/collections/getProperty?ID=86089
    method: GET
    name: "Christchurch Bin Date"
    value_template: >
      {% set value_json_sort = value_json.bins.collections | sort(attribute='next_planned_date') %}
      {% set value_json = value_json_sort | rejectattr('next_planned_date', 'le', (now().strftime('%Y-%m-%d')|string)) | map(attribute='next_planned_date')| list| first %}
      {{ value_json }}
    scan_interval: 43200

Then add a custom card to lovelace:

type: vertical-stack
cards:
  - type: custom:button-card
    entity: sensor.christchurch_bin_type
    show_entity_picture: true
    state:
      - entity_picture: https://ccc.govt.nz/resources/ccc-kerbside/client/images/yellowbin.png
        value: Recycle
      - entity_picture: https://ccc.govt.nz/resources/ccc-kerbside/client/images/redbin.png
        value: Garbage
  - type: entity
    entity: sensor.christchurch_bin_date
    state_color: false
    icon: mdi:delete-clock

image-20211127173015400

christchurch-bins-with-home-assistant's People

Contributors

durankeeley avatar

Stargazers

Shawinder Singh avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.