Skip to main content

Västra Götaland Transit smart home integration, free and open source

Västra Götaland Transit integration for Gladys Assistant

Unofficial. Next departures and disruptions at your Västra Götaland stops (Västtrafik open data).

Unofficial integration, not affiliated with Västtrafik. It shows, in Gladys, the next departures (trams, buses, boats, trains) at up to four stop areas of Västra Götaland and the traffic situations in effect there. The data comes from the open APIs of Västtrafik (CC0 1.0): Planera Resa v4 for the departures, Traffic Situations v1 for the disruptions.

This version was never tested with a real key: it was written from the official definitions of the APIs (OpenAPI of Planera Resa v4, Swagger of Traffic Situations v1, the OAuth 2 guide of the portal) and tested against simulated answers. Please report what you see with a real key.

What you need​

  1. A free account on the Västtrafik developer portal.
  2. An application registered there, subscribed to Planera Resa v4 and to Traffic Situations ("Störning"). A subscription added later is seen with the next access token (within 24 hours) or after a restart of the integration.
  3. The key and the secret of that application, copied into the configuration. Gladys keeps them in its database, does not show them again, and sends them only to Västtrafik (to ask an access token). The terms of the portal forbid giving your key to anyone else: each Gladys uses its own application.

Configuration​

  • Key and Secret: both, or nothing is sent.
  • Language of the texts: English or French for the device names and the departure texts. Stop names, destinations and traffic situations stay as Västtrafik sends them (mostly Swedish).
  • Read interval: 30 to 600 seconds (60 by default) for the departures. The traffic situations are read every 5 minutes.
  • Stop 1 to 4: the 16-digit gid of a stop area (e.g. 9021014001760000 for Brunnsparken, 9021014008000000 for Göteborg Centralstationen), an optional name, optional platforms (A, C2: only those platforms) and optional lines (6, 11, GRÖN: only those lines; a traffic situation naming other lines only is left out). The gid is the one the Planera Resa search locations/by-text gives.

Devices​

One device per stop, read-only, with:

  • Next departure and Following departure (texts): 6 → Kortedala in 4 min (09:18, platform C, 2 min late). The time is the real-time estimate when Västtrafik has one, else the timetable time (said so). A cancelled departure is left out; a partly cancelled one is marked. When there is none: No departure (read 09:14).
  • Departures (30 min) (counter): the departures within the next 30 minutes.
  • Departures (text): a summary by line and destination, with the time of the read.
  • Traffic situations in effect (counter) and Traffic situation (text: the most severe one, and how many more).

A failed or unreadable read publishes nothing: the previous values stay, with their read time in the texts, and the status of the integration says since when nothing was published. A stop area that Västtrafik does not know (or that has no traffic soon: the API gives the same answer, 404) is asked again 30 minutes later; once Västtrafik has answered for that gid, a 404 means "no departure".

Scene trigger​

New traffic situation at a stop: a situation in effect appears for the first time at a watched stop, started within the last 24 hours. The first read after a start, or after a change of the stop, only learns what is there. Optional filter on the severity (severe, normal, slight). Variables: title, description, severity, situation number, lines.

Pace and courtesy​

The terms of the portal ask to keep the use to what the purpose needs; Västtrafik publishes no numeric quota.

  • One request at a time, 1 second at least between two.
  • One departures request per stop and per read; the traffic situations every 5 minutes per stop.
  • One access token, kept in memory (not in /data) and used until it expires (24 hours, renewed when less than 30 seconds are left). Two token requests are 60 seconds apart at least; after a restart, a new token is asked.
  • A 401 on a token that the same API answered before: one new token and one retry. A 401 or 403 on a new token means the application lacks the subscription: that API is asked again later (2 minutes, doubled up to 1 hour), the key and secret are not taken as refused.
  • 429 and server errors pause that service (the Retry-After of Västtrafik when longer, 1 minute to 6 hours, doubled each time), kept in /data over a restart.
  • Refused key and secret (the token server answers 401 or invalid_client): nothing is sent with them until they change, or until the button Show the last read / retry the key gets a token (one token request per press, 30 seconds apart at least). Only two salted 8-bit prints of the pair are kept in /data, never the key, the secret nor the token.
  • A restart, a reconnection, a saved unchanged configuration, Discovery or the button do not read sooner than the interval (the time of the last read is kept in /data).

Privacy​

The key, the secret and the access token travel in HTTP headers to ext-api.vasttrafik.se only. They are not written in the logs, in /data, in the status nor in an error. /data holds the time of the last read, the pauses, the prints of refused credentials, and salted fingerprints of the stops with the numbers of the traffic situations already announced.

Data and license​

Västtrafik data is published under CC0 1.0. Västtrafik provides its APIs "as is", without guarantee of availability or accuracy. The integration is not a ticket app and uses no logo nor brand of Västtrafik.

Configuration settings​

These are the settings Västra Götaland Transit asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
Västtrafik departures and traffic situationssectionNoUnofficial, not affiliated with Västtrafik. Data from the open APIs of Västtrafik (CC0 1.0): the next departures at up to four stop areas of Västra Götaland (Planera Resa v4) and the traffic situations in effect there (Traffic Situations). Create a free account on the Västtrafik developer portal, register an application, subscribe it to "Planera Resa v4" and "Traffic Situations", and copy its key and secret here. The integration keeps its use to what it needs, as the portal's terms ask: one request per stop and per read, the traffic situations every 5 minutes, one access token for 24 hours.
Key of the applicationsecretNoThe key (client identifier) of your application on the Västtrafik portal, kept by Gladys in its database, never shown again, sent only to Västtrafik.
Secret of the applicationsecretNoThe secret of the same application, kept by Gladys in its database, never shown again, sent only to Västtrafik.
Language of the textsselectNoThe language of the device names and the departure texts (stop names, destinations and traffic situations stay as Västtrafik sends them, mostly in Swedish).
Read interval (s)numberNoHow often the departures are read, in seconds (30 to 600). The traffic situations are read every 5 minutes.
Stop 1sectionNoThe 16-digit gid of a stop area (e.g. 9021014001760000 for Brunnsparken, 9021014008000000 for Göteborg Centralstationen). It is the stop area id in the address of a stop on vasttrafik.se, or the gid that the Planera Resa "locations/by-text" search gives.
Name (optional)stringNo
Stop area gidstringNo
Platforms (optional)stringNoOnly these platforms (Läge), comma separated, as Västtrafik names them (e.g. A, C2). Empty: every platform.
Lines (optional)stringNoOnly these lines, comma separated, as shown to travellers (e.g. 6, 11, GRÖN). Empty: every line. A traffic situation naming other lines only is left out.
Stop 2sectionNo
Name (optional)stringNo
Stop area gidstringNo
Platforms (optional)stringNoOnly these platforms (Läge), comma separated, as Västtrafik names them (e.g. A, C2). Empty: every platform.
Lines (optional)stringNoOnly these lines, comma separated, as shown to travellers (e.g. 6, 11, GRÖN). Empty: every line. A traffic situation naming other lines only is left out.
Stop 3sectionNo
Name (optional)stringNo
Stop area gidstringNo
Platforms (optional)stringNoOnly these platforms (Läge), comma separated, as Västtrafik names them (e.g. A, C2). Empty: every platform.
Lines (optional)stringNoOnly these lines, comma separated, as shown to travellers (e.g. 6, 11, GRÖN). Empty: every line. A traffic situation naming other lines only is left out.
Stop 4sectionNo
Name (optional)stringNo
Stop area gidstringNo
Platforms (optional)stringNoOnly these platforms (Läge), comma separated, as Västtrafik names them (e.g. A, C2). Empty: every platform.
Lines (optional)stringNoOnly these lines, comma separated, as shown to travellers (e.g. 6, 11, GRÖN). Empty: every line. A traffic situation naming other lines only is left out.

How to install Västra Götaland Transit in Gladys​

  1. In Gladys, open Integrations: Västra Götaland Transit appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/lm1lc3n7/gladys-vastra-gotaland-transit:0.1.1), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/LM1LC3N7/gladys-vastra-gotaland-transit.

Västra Götaland Transit requires Gladys >=5.3.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

Västra Götaland Transit is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by LM1LC3N7, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂