I’m trying to set up a rest sensor and getting some unexplained results.
Here is the code:
- platform: rest
resource: https://api.weather.gov/alerts/active?zone=INZ009
name: NWS Weather Alert
value_template: "{{ value_json['features'][0]['properties'] }}"
json_attributes:
- event
- description
- instructions
- expires
headers:
Accept: application/ld+json
scan_interval: 30
This is the example curl command from the template creator on the NWS website
curl -X GET "https://api.weather.gov/alerts/active/zone/INZ009" -H "accept: application/ld+json"
If I put the above in the command line this is the result I get:
and in a chrome browser on windows:
So the website is returning data correctly.
But when I try to run the sensor I get the following errors in the log and the sensor shows as ‘unknown’:
2018-10-02 06:32:19 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: <HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://api.weather.gov/alerts/active?" on this server.<P>
Reference #18.150bf748.1538476339.1dfed2c
</BODY>
</HTML>
, template: {{ value_json['features'][0]['properties'] }})
I can’t figure out why the results between the two formats are different.
How can I troubleshoot this?
Another issue that I need to figure out is how to handle when there is no “properties” attribute but I can probably come up with something after I get the “access denied” problem figured out.
Unless the template is what’s causing the problem. Then I need help with why that would be.