Västtrafik

The vasttrafik integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] will provide you traveling details for the larger Göteborg area in Sweden from the Västtrafik public transportation service.

You must create an application here to obtain a key and a secret. Make sure to also subscribe to the API by clicking on Prenumerera på nytt API, and selecting the API Planera Resa v4.

Add the data to your configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file. 在更改了configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 文件后,重启 Home Assistant 以应用更改。 该集成现在显示在集成页面的 设置 > 设备与服务 下。其实体在集成卡片上以及实体标签上列出。

# Example configuration.yaml entry
sensor:
  - platform: vasttrafik
    key: YOUR_API_KEY
    secret: YOUR_API_SECRET
    departures:
      - from: Musikvägen

Configuration Variables

key string Required

The API key to access your Västtrafik account.

secret string Required

The API secret to access your Västtrafik account.

departures list Required

List of travel routes.

name string (Optional)

Name of the route.

from string Required

The start station name or ID.

heading string (Optional)

The destination station name or ID.

lines list | string (Optional)

Only consider these lines.

delay string (Optional, default: 0)

Delay in minutes.

The data is coming from Västtrafik.

A full configuration example could look like this:

# Example configuration.yaml entry
sensor:
  - platform: vasttrafik
    key: YOUR_API_KEY
    secret: YOUR_API_SECRET
    departures:
      - name: Mot järntorget
        from: Musikvägen
        heading: Järntorget
        lines:
          - 7
          - GRÖN
        delay: 10

Solving incorrect selected station problems

It is possible to use the full name of the station for the from/heading values, e.g., Musikvägen, Göteborg.

In cases where the wrong station is being selected, it is possible to provide the station ID instead. To do this you first need to retrieve the station ID either via Västtrafik’s API-konsole (using GET /locations/by-text) or with curl.

To retrieve the ID using curl:

  1. Login into the Västtrafik API and go to “Applikationer”

  2. Click “* Generera accesstoken”, and then “Kopiera”.

  3. Execute the following curl command, replacing “<ACCESS_TOKEN>” and “<STATION_NAME>” as necessary:

       curl -H "Authorization: Bearer <ACCESS_TOKEN>" "https://ext-api.vasttrafik.se/pr/v4/locations/by-text?q=<STATION_NAME>"
    
  4. In the output locate the key called “results”, and under this key, you will find a list of stops. Copy the ID (gid) for your desired stop and use it in your configuration.

# Example configuration.yaml entry using station ID as departure and station name as destination
sensor:
  - platform: vasttrafik
    key: YOUR_API_KEY
    secret: YOUR_API_SECRET
    departures:
      - name: To the Iron Square \o/
        from: 9021014004870000
        heading: Järntorget
        delay: 0