Västtrafik
The vasttrafik
integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] will provide you traveling details for the larger Göteborg area in Sweden from the Västtrafik
You must create an application herekey
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.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes. The integration is now shown on the integrations page under Settings > Devices & services. Its entities are listed on the integration card itself and on the Entities tab.
# Example configuration.yaml entry
sensor:
- platform: vasttrafik
key: YOUR_API_KEY
secret: YOUR_API_SECRET
departures:
- from: Musikvägen
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-konsolecurl
.
To retrieve the ID using curl
:
-
Login into the Västtrafik API and go to “Applikationer”
-
Click “* Generera accesstoken”, and then “Kopiera”.
-
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>"
-
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