HVC rest api - help needed

My Garbage company has an rest api where you can check when they come to empty the container

http://inzamelkalender.hvcgroep.nl/push/calendar?postcode=2954NL&huisnummer=10

[{
"id": "001ce9bf0b847080a4ec7c9c89f8992e",
"adresId": "",
"code": "GFT",
"naam": "GFT",
"icon": "gft.png",
"dateTime": [{
	"date": "2017-08-23 00:00:00",
	"timezone_type": 3,
	"timezone": "Europe\/Amsterdam"
}, {
	"date": "2017-08-23 00:00:00",
	"timezone_type": 3,
	"timezone": "Europe\/Amsterdam"
}, {
	"date": "2017-09-06 00:00:00",
	"timezone_type": 3,
	"timezone": "Europe\/Amsterdam"
}, {
	"date": "2017-09-06 00:00:00",
	"timezone_type": 3,
	"timezone": "Europe\/Amsterdam"
}, {
	"date": "2017-09-20 00:00:00",
	"timezone_type": 3,
	"timezone": "Europe\/Amsterdam"
}],
"opmerkingen": "",
"alt": false,
"datums": ["woensdag 23 augustus", "woensdag 23 augustus", "woensdag  6 september", "woensdag  6 september", "woensdag 20 september"]

}, {
“id”: “ee77b91da50ba360445eebbe541c9581”,
“adresId”: “”,
“code”: “REST”,
“naam”: “REST”,
“icon”: “rest.png”,
“dateTime”: [{
“date”: “2017-08-30 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-08-30 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-09-27 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-09-27 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-10-25 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}],
“opmerkingen”: “”,
“alt”: false,
“datums”: [“woensdag 30 augustus”, “woensdag 30 augustus”, “woensdag 27 september”, “woensdag 27 september”, “woensdag 25 oktober”]
}, {
“id”: “1bce248267719c42ea142d573ea750a6”,
“adresId”: “”,
“code”: “PAPIER”,
“naam”: “PAPIER”,
“icon”: “papier.png”,
“dateTime”: [{
“date”: “2017-09-01 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-09-29 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-10-27 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-11-24 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-12-22 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}],
“opmerkingen”: “”,
“alt”: false,
“datums”: [“vrijdag 1 september”, “vrijdag 29 september”, “vrijdag 27 oktober”, “vrijdag 24 november”, “vrijdag 22 december”]
}, {
“id”: “14400684f6bfd7233e64b97a61001aef”,
“adresId”: “”,
“code”: “PMD”,
“naam”: “PMD”,
“icon”: “plastic.png”,
“dateTime”: [{
“date”: “2017-09-13 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-10-11 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-11-08 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}, {
“date”: “2017-12-06 00:00:00”,
“timezone_type”: 3,
“timezone”: “Europe/Amsterdam”
}],
“opmerkingen”: “”,
“alt”: false,
“datums”: [“woensdag 13 september”, “woensdag 11 oktober”, “woensdag 8 november”, “woensdag 6 december”]
}]

I’ve now setup this in my configuration.yaml as follows

sensor:
  - platform: rest
    name: afvalkalender
    resource: http://inzamelkalender.hvcgroep.nl/push/calendar?postcode=2954NL&huisnummer=10
    value_template: '{{ value_json.0.naam }} {{ value_json.0.datums.0 }}'

But I would like have it not only for the first object but also for the other ones. I could set up the sensor three times for (Organic, Paper and Plastic waste) but is there a better way to do this?

Ideally I would like to have a group and then the name of the waste and the date it’s collected. The json is sorted by date.

Is it possible to use a json_value as friendly name of the sensor?

They HAD an JSON REST API. Not anymore. Since Monday.

Please, whoever used the REST API of HVC: Spam [email protected] to make them enable it again.
They replaced the website last monday… Great going.

See https://gadget-freakz.com/domoticz-dzvents-getgarbagedates-script/ for an alternative API

Hi TopdRob,

Did you ever got your garbage pickup date / time fixed? I saw from the link you shared that there was a new weburl for HVC.

The output of the URL looks like this:

[{"afvalstroom_id":5,"ophaaldatum":"2018-08-02"},{"afvalstroom_id":6,"ophaaldatum":"2018-08-08"},{"afvalstroom_id":2,"ophaaldatum":"2018-08-09"},{"afvalstroom_id":5,"ophaaldatum":"2018-08-16"},{"afvalstroom_id":6,"ophaaldatum":"2018-08-22"},{"afvalstroom_id":3,"ophaaldatum":"2018-08-23"},{"afvalstroom_id":2,"ophaaldatum":"2018-08-23"},{"afvalstroom_id":5,"ophaaldatum":"2018-08-30"},{"afvalstroom_id":6,"ophaaldatum":"2018-09-05"},{"afvalstroom_id":2,"ophaaldatum":"2018-09-06"},{"afvalstroom_id":5,"ophaaldatum":"2018-09-13"},{"afvalstroom_id":6,"ophaaldatum":"2018-09-19"},{"afvalstroom_id":2,"ophaaldatum":"2018-09-20"},{"afvalstroom_id":3,"ophaaldatum":"2018-09-27"},{"afvalstroom_id":5,"ophaaldatum":"2018-09-27"},{"afvalstroom_id":6,"ophaaldatum":"2018-10-03"},{"afvalstroom_id":2,"ophaaldatum":"2018-10-04"},{"afvalstroom_id":5,"ophaaldatum":"2018-10-11"},{"afvalstroom_id":6,"ophaaldatum":"2018-10-17"},{"afvalstroom_id":2,"ophaaldatum":"2018-10-18"},{"afvalstroom_id":3,"ophaaldatum":"2018-10-25"},{"afvalstroom_id":5,"ophaaldatum":"2018-10-25"},{"afvalstroom_id":6,"ophaaldatum":"2018-10-31"},{"afvalstroom_id":2,"ophaaldatum":"2018-11-01"},{"afvalstroom_id":5,"ophaaldatum":"2018-11-08"},{"afvalstroom_id":6,"ophaaldatum":"2018-11-14"},{"afvalstroom_id":2,"ophaaldatum":"2018-11-15"},{"afvalstroom_id":3,"ophaaldatum":"2018-11-22"},{"afvalstroom_id":5,"ophaaldatum":"2018-11-22"},{"afvalstroom_id":6,"ophaaldatum":"2018-11-28"},{"afvalstroom_id":2,"ophaaldatum":"2018-11-29"},{"afvalstroom_id":5,"ophaaldatum":"2018-12-06"},{"afvalstroom_id":6,"ophaaldatum":"2018-12-12"},{"afvalstroom_id":2,"ophaaldatum":"2018-12-13"},{"afvalstroom_id":5,"ophaaldatum":"2018-12-20"},{"afvalstroom_id":6,"ophaaldatum":"2018-12-27"},{"afvalstroom_id":3,"ophaaldatum":"2018-12-27"},{"afvalstroom_id":2,"ophaaldatum":"2018-12-28"}]

For now i only can get the first object in the array via

`- platform: rest
  name: afvalkalender
  json_attributes:
- afhaalstroom_id
- ophaaldatum
  #method: get
  resource: https://apps.hvcgroep.nl/rest/adressen/0505200000051904/kalender/2018
#  value_template:  '{{value_json[0].afvalstroom_id}} + {{value_json[0].ophaaldatum}}'
  value_template:  '{{value_json[0].afvalstroom_id}} + {{value_json[0].ophaaldatum}}'`

After this point I have no clue where to begin, i would like it to work the same as the pick updates from this component: LINK Garbage pickup date mijnafvalwijzer.nl

For now I know that I have to do something with the date, this must be converted to a timestamp so I can check if the date is today or near, filter out the afvalstroom_id so I can show which container is being picked up. But first I would like to know how I can get all the values, and convert the time and save it in an attribute of the object?

This is the first time trying something like this, so if somebody got some examples to share are any help is really appriciated.

Keep you posted!

Greets! DrEnergy

@TopdRob:
Thanks man! Now we have to hobby-bob the ID’s and the dates to be functional :wink: Will take some time, but hey :wink:

Hi,
They also have a calendar you can import in google calendar.

You can use the Google Calendar component to import the data into home assistant.

Add to configuration.yaml

google:
  client_id: !secret google_calendar_client_id
  client_secret: !secret google_calendar_client_secret

Add to google_calendars.yaml:

- cal_id: ***************@import.calendar.google.com
  entities:
  - device_id: Afvalkalender
    ignore_availability: true
    name: Afvalkalender
    track: true

Add to sensors.yaml:

- platform: template
  sensors:
    garbage_date_afvalkalender:
      value_template: '{{ (as_timestamp(states.calendar.afvalkalender.attributes.start_time)) | timestamp_custom("%d-%m-%Y") }}'
    garbage_type:
      value_template: '{{states.calendar.afvalkalender.attributes.message}}'
    garbage_color:
      value_template: >
        {% if is_state("sensor.garbage_type", "Papier en karton") -%}
          blauwe
        {% elif is_state('sensor.garbage_type', 'Plastic, blik & drinkpakken') -%}
          oranje
        {% elif is_state('sensor.garbage_type', 'Gft & etensresten') -%}
          groene
        {% else %}
          grijze
        {% endif %}
      entity_picture_template: >
        {% if is_state("sensor.garbage_type", "Restafval") -%}
           /local/icons/garbage_icons/huisafval.svg
        {% elif is_state('sensor.garbage_type', 'Papier en karton') -%}
           /local/icons/garbage_icons/papier-en-karton.svg
        {% elif is_state('sensor.garbage_type', 'Plastic, blik & drinkpakken') -%}
           /local/icons/garbage_icons/plastic-blik-drinkpak.svg
        {% elif is_state('sensor.garbage_type', 'Gft & etensresten') -%}
           /local/icons/garbage_icons/gft.svg
        {% else %}
           /local/icons/warning.svg
        {% endif %}

Automation for the notification:
Sends notification at 18:00 the day before.

- alias: Notify Trash Day
  initial_state: 'on'
  trigger:
    - platform: time
      hours: 18
      minutes: 00
      seconds: 0
  condition:
    - condition: state
      entity_id: input_boolean.notify_trash
      state: 'on'
    - condition: template
      value_template: '{{ now().strftime("%d-%m-%Y") == (as_timestamp(states.calendar.afvalkalender.attributes.start_time) - (86400)) | timestamp_custom("%d-%m-%Y") }}'
  action:
  - service: notify.all
    data_template:
      title: Afvalcontainer!
      message: "Het is vandaag {{ ['maandag','dinsdag','woensdag','donderdag','vrijdag','zaterdag','zondag'][now().weekday()] }}. Morgen wordt de {{ states.sensor.garbage_color.state }} bak geleegd!"
2 Likes

Based on the new API I created a custom component. It takes your postcode and huisnummer and creates sensors for the trash types being picked up on that address. eg. trash_gft, trash_rest and trash_papier.

If you find any bugs (very likely given my Python skills) or have feature requests/ideas, let me know.

2 Likes

Works like a charm! All I have to do now is create some notifications!

To let the custom component work with the new 0.92 version you have to add an empty file with the name __init__.py in the folder where you saved the sensor.py