Urgh, can’t believe you tried to get ChatGPT to solve this.
Create a rest sensor using the line of code I gave you to extract the list of times.
Then create a series of template sensors to extract each time from the list:
sensor:
- platform: rest
resource: YOUR_URL
name: Train times list
value_template: "{{ value_json['Departure']|selectattr('directionFlag','eq','2')|map(attribute='time')|list }}"
scan_interval: 120
template:
- sensor:
- name: Next train time 1
state: >-
{% if states('sensor.train_times_list')|from_json|length > 0 %}
{{ (states('sensor.train_times_list')|from_json)[0] }}
{% else %}
unavailable
{% endif %}
- name: Next train time 2
state: >-
{% if states('sensor.train_times_list')|from_json|length > 1 %}
{{ (states('sensor.train_times_list')|from_json)[1] }}
{% else %}
unavailable
{% endif %}
…and so on.
And in future, please format any code in your posts with the </> button.