RESTful API integration not properly creating sensors for Public Transport data

Hey HA Community, this is my first time using this forum. Hopefully can get some answers!

I am using the RESTFul integration to call the API service to deliver me real time public transport updates for my local train station in Melbourne Victoria.

I want multiple sensors to give me next realtime depature and the ones after that. The API should return the raw data where a template that I have will convert it into a User Friendly display for a love lace dashboard.

Currently this works fine for one sensor and the attributes are displayed correctly. However when I try and add more sensors to pull relevant data none of them show attribute data.

Below is my Config File excerpt that correctly shows one sensor. The image attached shows the working setup


# Add the PTV API sensor integration below the rest of your configuration
rest:
  - scan_interval: 60  # Update every minute
    resource: "https://timetableapi.ptv.vic.gov.au/v3/departures/route_type/0/stop/HIDDENFORPRIVACY
    sensor:
      - name: "Next Train Departure at Flagstaff"
        value_template: "{{ value_json.departures[0].scheduled_departure_utc | default('Unknown') }}"
        json_attributes_path: "$.departures[0]"
        json_attributes:
          - route_id
          - platform_number
          - direction_id
          - estimated_departure_utc
          - scheduled_departure_utc

Screenshot 2025-01-30 at 9.38.15 am

Below is the config where sensors are created but no attributes are displayed

rest:
  - scan_interval: 60  # Update every minute
    resource: "https://timetableapi.ptv.vic.gov.au/v3/departures/route_type/0/stop/HIDDEN
    sensor:
      # **1. Next Real-Time Train**
      - name: "Next Train Departure at Flagstaff"
        value_template: "{{ value_json.departures[0].scheduled_departure_utc | default('Unknown') }}"
        json_attributes_path: "$.departures[0]"
        json_attributes:
          - route_id
          - platform_number
          - direction_id
          - estimated_departure_utc
          - scheduled_departure_utc

      # **2. First Train Departing in 8+ Minutes**
      - name: "Train 8+ Minutes Departure at Flagstaff"
        value_template: >
          {% for train in value_json.departures %}
            {% if train.scheduled_departure_utc is not none and (as_datetime(train.scheduled_departure_utc) - now()).total_seconds() > 480 %}
              {{ train.scheduled_departure_utc }}
              {% set found_train = train %}
              {% break %}
            {% endif %}
          {% endfor %}
        json_attributes_path: "$.departures[1]"  # Adjust to match next train in list
        json_attributes:
          - route_id
          - platform_number
          - direction_id
          - estimated_departure_utc
          - scheduled_departure_utc

      # **3. Second Train Beyond 8 Minutes**
      - name: "Train Beyond 8+ Minutes Departure 2"
        value_template: >
          {% set count = 0 %}
          {% for train in value_json.departures %}
            {% if train.scheduled_departure_utc is not none and (as_datetime(train.scheduled_departure_utc) - now()).total_seconds() > 480 %}
              {% set count = count + 1 %}
              {% if count == 2 %}
                {{ train.scheduled_departure_utc }}
                {% set found_train = train %}
                {% break %}
              {% endif %}
            {% endif %}
          {% endfor %}
        json_attributes_path: "$.departures[2]"  # Adjust to match second train beyond 8 mins
        json_attributes:
          - route_id
          - platform_number
          - direction_id
          - estimated_departure_utc
          - scheduled_departure_utc

      # **4. Third Train Beyond 8 Minutes**
      - name: "Train Beyond 8+ Minutes Departure 3"
        value_template: >
          {% set count = 0 %}
          {% for train in value_json.departures %}
            {% if train.scheduled_departure_utc is not none and (as_datetime(train.scheduled_departure_utc) - now()).total_seconds() > 480 %}
              {% set count = count + 1 %}
              {% if count == 3 %}
                {{ train.scheduled_departure_utc }}
                {% set found_train = train %}
                {% break %}
              {% endif %}
            {% endif %}
          {% endfor %}
        json_attributes_path: "$.departures[3]"  # Adjust to match third train beyond 8 mins
        json_attributes:
          - route_id
          - platform_number
          - direction_id
          - estimated_departure_utc
          - scheduled_departure_utc

I have removed the full API call URL due to it containing my developer access code and signature.

I am aware that there is a PTV integration available on HACs and have used but I want to have more control over the data.

Keen to see what the issue is! Hopefully can get the answer on here :slight_smile: