Hi again!
I have been working more on my project.
With the solution that Troon gave me:
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
I was able to create a sensor that gave me a list, but the next part didnt work.
Also when I worked in the template editor, it intepreted the result from
{{ states('sensor.train_times_list') }}
as a string I think, making it again impossible to extraxt every time as its on element. I think when a sensor gives its state it does so only as a string? I am not sure.
After a little bit of reading I was able to then take this string and turn it into a list again with the code below, so it is possible to extract every element as its own time. Also removing the [, ] and ’ from the results.
{% set traintimes = states('sensor.train_times_list').split(',') %}
{% set traintimes = ' '.join(traintimes).replace('[','').replace(']','')
.replace("'",'').split() %}
{{ traintimes[0] }}
This produces just for example 14:31:00
Which is in the nice format I want.
But now I dont know how to get it into a sensor?
My sensors.yaml file accepts many things, but the config check alway rejects it.
Currently the sensors.yaml file looks only like this:
# Extracting list of train times into sensor
- platform: rest
resource: https://api.resrobot.se/v2.1/departureBoard?id=740000775&duration=60&maxJourneys=-1&products=16&passlist=0&lang=sv&format=json&requestId=random%20string&accessId=db5f04e0-7fa1-403d-8a2c-bba3641e105b
name: Train times list
value_template: "{{ value_json['Departure']|selectattr('directionFlag','eq','2')|map(attribute='time')|list }}"
scan_interval: 120