If you want to get the last item in the list, this is the ‘pythonic’ way to do it:
- platform: rest
name: quivre
resource: https://waterservices.usgs.gov/nwis/iv/?sites=05514705&period=P7D&format=json
value_template: >-
{{ (value_json.value.timeSeries[0]['values'][0].value)[-1].value }}
verify_ssl: false
Here’s the answer to your original question. The reason why your template failed is due to how it referenced the values
list.
If it’s referenced this way, using bracket notation, it works (it returns 17.71
).
If it’s referenced this way, using dot notation, it fails (produces an error message).
In your case, the key called values
is, as the error message indicates, the name of a built-in function. To differentiate it from the built-in function, don’t reference it using dot notation, use bracket notation.
Bracket notation can also handle keys containing spaces (such as ['time series'][0]
). However, it is less compact than dot notation. Here is your template in full bracket notation:
value_json['value']['timeSeries'][0]['values'][0]['value'][667]['value']
and it works:
but it’s rather long so that’s why dot notation is popular (except when it causes you to ‘work for days’ to fix it).

Hope this helps avoid similar problems in the future. Good luck!