One of my REST sections is misbehaving and I can’t work out how to debug it. In configuration.yaml I have a section with a number of REST resources & sensors like this:
rest:
- resource_template: https://meteostat.p.rapidapi.com/stations/daily?station=03707&start={{ (now() - timedelta(days=1)).date() }}&end={{ (now() - timedelta(days=1)).date() }}
scan_interval: 86400
headers:
X-RapidAPI-Key: XXX
X-RapidAPI-Host: meteostat.p.rapidapi.com
sensor:
- name: "Wnd_dir"
value_template: "{{ value_json['data'][0]['wdir'] }}"
...
- resource: https://admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/0536/TidalEvents?duration=7
scan_interval: 43200
headers:
Ocp-Apim-Subscription-Key: OOO
sensor:
- name: "UKTide 1 type"
unique_id: "UKtide1type"
value_template: "{{ value_json[0]['EventType']|replace('Water','') }}"
...
- resource_template: https://admiraltyapi.azure-api.net/uktidalapi-premium/api/V2/Stations/0536/TidalHeights?StartDateTime={{ today_at('00:00').strftime("%Y-%m-%dT%H:%M") }}&EndDateTime={{ (today_at('00:00')+timedelta(hours=48)).strftime("%Y-%m-%dT%H:%M") }}&IntervalInMinutes=1
scan_interval: 86400
headers:
Cache-Control: no-cache
Ocp-Apim-Subscription-Key: OOOO1
sensor:
- name: "UKTideRestriction"
unique_id: "uktiderestriction"
value_template: "{{ value_json | truncate }}"
I’ve got a number of issues I’m trying to resolve in the last of the above examples (including how to call it with datetime sensors in resource_template), but when I edit it & use developer tools reload YAML REST entities, this particular one doesn’t work correctly (eg the individual sensors become unavailable) until I perform a restart. My other REST resources don’t have this problem - ie if I edit them & reload YAML without restarting, the changes are applied immediately.
I wondered if it is to do with the amount of data returned by the API. The problem one gets a large amount of data, between 2-3,000 records whereas the others are quite small eg 1% of this.
I am also unclear how the scan_interval works in conjunction with the automations that trigger them. Most the the sensors in this REST section are updated in automations like:
alias: SLWRetrictionRefreshUKHOData
description: Gets new UKHO height restrictions when SLW changes
trigger:
- platform: state
entity_id: sensor.slwrestrictions
to: null
condition: []
action:
- service: homeassistant.update_entity
target:
entity_id:
- sensor.uktiderestriction1start
- sensor.uktiderestriction1end
- sensor.uktiderestriction2start
...
data: {}
mode: single
And I try manually triggering this automation to refresh the sensor values after editing & reloading the YAML (it doesn’t help without a restart).
Each time I iterate this section I test the YAML in developer tools with data manually downloaded from the API & pasted into {% set value_json = ... %}
, so I don’t think the problem is always in my poor coding.