Hello all,
I have been struggling for months now to get this REST sensor working, but finally admitted my defeat and opted to reach out for help.
My municipality (or better said: the outsourced service provider) provides an online calendar with garbage collection dates. I was able to simulate the POST request that their website makes to an API in HA and get a valid reply back. The issue is that the POST request needs an ‘start date’ and ‘end date’ to fetch the results. This results in a requirement to POST a date, which changes with every (daily) call. The yaml looks like this:
- platform: rest
name: vuilophaal
resource: https://wasteprod2api.ximmio.com/api/GetCalendar
method: POST
json_attributes:
- dataList
headers:
User-Agent: Home Assistant
Content-Type: application/json
payload: '{"companyCode":"<SOME PII INFO>","startDate":"2020-11-19","endDate":"2021-12-31","community":"Lisse","uniqueAddressID":"<SOME PII"}'
value_template: 'OK'
- platform: template
sensors:
gft:
friendly_name: 'GFT-bak'
icon_template: mdi:delete-empty
value_template: >
{% set current = state_attr('sensor.vuilophaal','dataList')[0].pickupDates[0] | string %}
{{ as_timestamp(strptime(current, "['%Y-%m-%dT%H:%M:%S']")) | timestamp_custom("%d %B %Y") }}
papier:
friendly_name: 'Papier-container'
icon_template: mdi:delete-empty
value_template: >
{% set current = state_attr('sensor.vuilophaal','dataList')[1].pickupDates[0] | string %}
{{ as_timestamp(strptime(current, "['%Y-%m-%dT%H:%M:%S']")) | timestamp_custom("%d %B %Y") }}
pmd:
friendly_name: 'PMD-container'
icon_template: mdi:delete-empty
value_template: >
{% set current = state_attr('sensor.vuilophaal','dataList')[2].pickupDates[0] | string %}
{{ as_timestamp(strptime(current, "['%Y-%m-%dT%H:%M:%S']")) | timestamp_custom("%d %B %Y") }}
I have tried numerous options to enter the ‘start date’ with a variable, being today’s date, but only get a valid reply back if I enter a ‘fixed’ date.
Having tried for months, admitting defeat (:)), I hope that someone is able to push me into the right direction.
Thank you!