RESTful sensor parsing using date information

I can get the garbage collection calendar for our street via this URL:

https://www.awbkoeln.de/api/calendar?building_number=50&street_code=2&start_year=2019&end_year=2019&start_month=1&end_month=12&form=json

This returns a JSON including all collection dates for the year 2019:

{"data":[
{"day":1,"month":7,"year":2019,"type":"wertstoff"},{"day":1,"month":10,"year":2019,"type":"grey"},{"day":2,"month":1,"year":2019,"type":"grey"}, ...

The collection is sorted by day as it seems.

So everything is in the “data” array. Each element contains the day, the month and the year and the type of the garbage bin which is getting collection. So in the example above on July 1st, 2019 the “wertstoff” bin is getting collected.

My goal would be to show e.g. for the current day which “type” is getting collected. Even better to show it for the current week (starting on Sunday or Monday).

I don’t understand how to “query” this using a value_template. I would like to query by day, month, year to get the type of this element.

Can someone point me in the right direction? Thank you!

I can get the current day with this configuration right now:

sensor:
  - platform: rest
    name: awb_kalender
    resource: https://www.awbkoeln.de/api/calendar?building_number=50&street_code=2&start_year=2019&end_year=2019&start_month=1&end_month=12&form=json
    method: GET
    value_template: '{% for date in value_json.data %}{% if date.month == now().month and date.day == now().day %}{{ date.type}}{% endif %}{% endfor %}'

Hi, maybe you’ll find this one usefull: AWB Köln garbage collection schedule

1 Like