Still not working:
New yaml is:
- platform: rest
resource_template: 'http://v0.postcodeapi.com.au/radius/?latitude={{ states.device_tracker.kab_phone.attributes.latitude }}&longitude={{ states.device_tracker.kab_phone.attributes.longitude }}&distance=1000'
value_template: '{% if value_json[0] is defined %}{{ value_json[0].name}}{% endif %}'
name: kab_suburb
headers:
Accept: 'application/json'
There is an error in the log (didn’t notice it before):
Log Details (ERROR)
Wed Jan 08 2020 06:16:03 GMT+1000 (Australian Eastern Standard Time)
Error while setting up platform rest
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 222, in async_render
return compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.7/site-packages/jinja2/sandbox.py", line 387, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'attributes'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 95, in setup_platform
resource = resource_template.render()
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 207, in render
self.hass.loop, self.async_render, kwargs
File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 435, in result
return self.__get_result()
File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 70, in run_callback
future.set_result(callback(*args))
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 224, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'attributes'
I am testing the response here:
https://reqbin.com/xps3pots
The feeding the result into the developer template editor like:
{% set value_json = [
{
"name": "Brisbane Adelaide Street",
"postcode": 4000,
"state": {
"name": "Queensland",
"abbreviation": "QLD"
},
"locality": "BRIS CITY CNTRY",
"latitude": -27.465,
"longitude": 153.02340000000001
},
{
"name": "Spring Hill",
"postcode": 4000,
"state": {
"name": "Queensland",
"abbreviation": "QLD"
},
"locality": "BRIS CITY CNTRY",
"latitude": -27.465,
"longitude": 153.02340000000001
}
] -%}
{% if value_json[0] is defined %}{{ value_json[0].name}}{% endif %}
Any other ideas? … Thanks again K