JSON Value_template with changing lines

I am using the REST sensor to retrieve from API sources and have done this successfully for a few sources. For one of the rainfall API source, the value_template that I am using looks as below:

value_template: '{{ states.sensor.rainfall.attributes["items"][0]["readings"][**47**]["value"] }}

My issue is that the API source changes and the 47 changes based on the number of weather stations that is available. The source looks as below:

image

from which I obtained from JSON parser the following, which I used in my value_template.

Is there anyway to identify the station based on the station_id instead of using the “row number” that the JSON parser is showing currently?

Short answer: yes. Take a look at the example in the template dev tool for how to use a for loop and you can say something like

{%- for station in value_json.items[0].readings if (station.station_id == 582) -%}
  {{ station.value }}
{%- endfor -%}