Trafikverket Train


Retrieve train departure information from Trafikverket.

Use cases:

  • Retrieve the next departure and information connected to it for a specific train line.
  • Retrieve information for specific departure time on a specific train line.
  • Set up an alert or perform actions if your train is delayed or canceled.

Data that is retrieved:

  • Next departure for the specific train line.
  • Canceled status.
  • The number of minutes delayed.
  • Planned time if no delays occur.
  • Estimated time of arrival if delays occur.
  • Actual time - when it did arrive.
  • Other information / additional texts.
  • Deviations.

Configuration

To enable this sensor, use the following format in your configuration.yaml.

sensor:
   - platform: trafikverket_train
     api_key: TRAFIKVERKET_API
     trains:
     - name: "Morning train to Malmö"
       from: "Stockholm Central"
       to: "Malmö C"
       time: "9:25"
       
     - name: "Next train to Uppsala"
       from: "Stockholm Central"
       to: "Uppsala C"

Configuration Variables

api_key

(string)(Required)

Your personal API key from Trafikverket.

trains

(map)(Required)

Specify details on the departures to monitor.

name

(string)(Required)

The name of the departure, will be the sensor name.

from

(string)(Required)

The station from where the train departs.

to

(string)(Required)

The destination station.

time

(string)(Optional)

Departure time to monitor, if not entered it will retrieve the next departure.

weekday

(list)(Optional)

Specify which days in the week to monitor the specific departure.

Default value:

[mon, tue, wed, thu, fri, sat, sun]

Obtaining API key

Please click here and register to obtain the API key.

Train station names

Click here to see an example of train station names.

Examples

sensor:
- platform: trafikverket
  api_key: !secret trafikverket_api_key
  trains:
  - name: "Train to work"
    from: Sölvesborg
    to: Kristianstad C
    time: "07:28"
    weekday: [mon, tue, wed, thu, fri]
    
  - name: "Train from work early"
    from: Kristianstad C
    to: Sölvesborg
    time: "16:38"
    
  - name: "Train from work late"
    from: Kristianstad C
    to: Sölvesborg
    time: "17:02"
    weekday: [sat, sun]
    
  - name: "Next train to Uppsala"
    from: "Stockholm Central"
    to: "Uppsala C"