MMM-PublicTransportHafas is a module for MagicMirror² to display public transport departures.
stationID
This module shows live public transport information in Germany for all stations known to the Deutsche Bahn system. Most public transportation providers in Germany providing information for that system so the coverage should be quite good. The data is provided by the fantastic hafas-client. Even in other european countries this module should work as HAFAS is widely used throughout Europe.
You can very easy adapt the shapes and line colors of your local transport companies. See Providing a custom CSS file.
After you installed MMM-PublicTransportHafas you just configure it to your needs and that’s it. The only config you really need to set is the stationID property. This determines the station you want to display. Everything else is covered by defaults but can be configured by you anyway. For instance you can enter a time you need to get to the station (timeToStation
in config). The module then only shows departures you can reach respecting the set time.
For more information see the Configuration section.
Leipzig, Goerdelerring (all directions) |
Leipzig, Goerdelerring (heading to main station) |
---|---|
Hauptbahnhof, Leipzig (displaying only trams and two unreachable departures) |
Hauptbahnhof, Leipzig (displaying only regional and national trains) |
Leuschner Platz, Leipzig (displaying departure times in relative format and reordered columns) |
Several instances in Berlin, showing the last update time
Just clone the module into your modules directory and install the dependencies:
cd ~/MagicMirror/modules
git clone https://github.com/KristjanESPERANTO/MMM-PublicTransportHafas
cd MMM-PublicTransportHafas
npm ci
Just enter the module's directory, pull the update and install the dependencies:
cd ~/MagicMirror/modules/MMM-PublicTransportHafas
git pull
npm ci
stationID
You need the stationId
for the station whose departures should be displayed.
Here's how to find out the stationId
:
~/MagicMirror/modules/MMM-PublicTransportHafas
).npm run query
.stationId
in the configuration of the module.The following example shows a query for "Leipzig, Wilhelm-Leuschner-Platz". This station is included two times in the result. You have to experiment which ID gives the best results.
Enter an address or station name: Leipzig, Wilhelm-Leuschner-Platz
Stops found for 'Leipzig, Wilhelm-Leuschner-Platz':
> Stop: Leipzig Wilhelm-Leuschner-Platz
ID: 8012202
Transport product(s): Regio, S-Bahn, Bus, Tram
> Stop: Wilhelm-Leuschner-Platz, Leipzig
ID: 955252
Transport product(s): Regio, S-Bahn, Bus, Tram
> Stop: Wilhelm-Leuschner-Platz, Weiterstadt
ID: 115849
Transport product(s): Regio, Bus
> Stop: Wilhelm-Liebknecht-Platz, Leipzig
ID: 956558
Transport product(s): Bus, Tram
By default, the module uses the db
profile of the hafas-client
. In some cases it can be advantageous to use a different profile - e.g. the default profile often does not provide platform information from local transport companies. Here you can find the name of all supported interfaces. Just add the name as a parameter to the command. Like sbb
for the profile of Swiss Railways.
npm run query sbb
The module is quite configurable. The only option you really have to set is stationID
- all other options are optional.
Option | Description | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
hafasProfile |
The name of the hafas profile. Type: Note: In most cases you don't need to change the value. You can find supported profiles and there names here. Each profile uses its own StationIDs. So if you change the profile, you have to find out the StationID again. |
||||||||||||||||||||||
stationID |
The ID you want to display departures for. REQUIRED Note: How to get the ID is described here. |
||||||||||||||||||||||
stationName |
The name of the station as it should appear on the display. Type: Note: If you leave this setting, |
||||||||||||||||||||||
headerPrefix |
The text to be prepended to the Type: Note: A blank between |
||||||||||||||||||||||
headerAppendix |
The text to be prepended to the Type: Note: A blank between |
||||||||||||||||||||||
updatesEvery |
The time in seconds when the displayed departures should be updated. Type: Note: The minimal refresh time is 30 seconds. |
||||||||||||||||||||||
direction |
An ID of a station. It is used to display only those departures heading to this station. Type: Note: It is not necessary to find the ID of the end station. Just use the next station which is on the route you are after. |
||||||||||||||||||||||
ignoredLines |
An array of strings describing the lines you want to exclude from the displayed departures. Type: Note: You need to provide the line names exactly as they are otherwise displayed. This setting is case sensitive. Blanks need to be exactly as they are display. If a line is usually displays as |
||||||||||||||||||||||
ignoreRelatedStations |
Ignore departures from related stations or not. Type: Note: Usually you don't need to touch this option. |
||||||||||||||||||||||
excludedTransportationTypes |
An array of strings describing the transportation types you want to exclude from the displayed departures. Type:
|
||||||||||||||||||||||
timeToStation |
An integer indicating how long it takes you to get to the station. Type: |
||||||||||||||||||||||
timeInFuture |
An integer indicating how far in the future a departure can be to be still included in the shown departures. Type: Note: Use this setting on stations where there is a big time gap between departures. This way you will see more than one or two departures. Don’t use this setting to limit the amount of displayed departures! The module will set this value to be at least |
||||||||||||||||||||||
marqueeLongDirections |
A boolean value indicating whether you want scrolling long destination name or not. Type: Note: If set to |
||||||||||||||||||||||
replaceInDirections |
An object defining strings which are to be replaced in the displayed directions. Type: Note: The strings which appear as the keys of the object will be replaced by their values. Given a direction |
||||||||||||||||||||||
showColoredLineSymbols |
A boolean value indicating whether the line symbols should be colored or black and white. Type: Note: If set to |
||||||||||||||||||||||
useColorForRealtimeInfo |
A boolean value indicating whether delays should be displayed in color. Type: Note: If set to |
||||||||||||||||||||||
showAbsoluteTime |
A boolean indicating whether the departure time should be displayed as an absolute value or not. Type: Note: If set to |
||||||||||||||||||||||
noRealtimeDelayString |
The string that is displayed as delay if no real-time departure time data is available. Type: Note: Set it to |
||||||||||||||||||||||
showRelativeTimeOnlyUnder |
Display the time only relatively if the departure takes place in less than 10 minutes (600000 milliseconds). Type: Note: The value is only relevant if |
||||||||||||||||||||||
showTableHeaders |
A boolean indicating whether a table header should be shown or not. Type: Note: If set to |
||||||||||||||||||||||
showTableHeadersAsSymbols |
A boolean value indicating whether table headers should be shown as symbols or text. Type: Note: If set to |
||||||||||||||||||||||
showWarningRemarks |
A boolean value indicating whether warnings attached to a trip should be shown. Type: Note: If set to |
||||||||||||||||||||||
tableHeaderOrder |
An array determining the order of the table headers. Type: Note 1: If the HAFAS API does not provide information about the platforms of your station, you can remove the column here by removing Note 2: Sort the table headings as you like it. Please keep in mind that you can only use the values |
||||||||||||||||||||||
maxUnreachableDepartures |
An integer value denoting how many unreachable departures should be displayed. Type: Note: A departure is unreachable if you can't reach the station in time for the departure with respect to your |
||||||||||||||||||||||
maxReachableDepartures |
An integer value denoting how many reachable departures should be displayed. Type: Note: A departure is reachable if you can make it to the station in time for the departure with respect to your |
||||||||||||||||||||||
fadeUnreachableDepartures |
A boolean value indicating whether unreachable departures should be dimmed. Type: |
||||||||||||||||||||||
fadeReachableDepartures |
A boolean value indicating whether reachable departures should be faded out. Type: Note: If set to |
||||||||||||||||||||||
fadePointForReachableDepartures |
A floating point value indicating where to start the fading of departure rows. Type: Note: This value is actually a percentage. The Default value of |
||||||||||||||||||||||
customLineStyles |
A string value describing the name of a custom CSS file. Type: Note: If the setting |
||||||||||||||||||||||
showOnlyLineNumbers |
A boolean value denoting whether the line name should be displayed as a number only or the full name should be used. Type: Note: If set to |
||||||||||||||||||||||
displayLastUpdate |
If true this will display the last update time at the end of the task list. See screenshot above Type: |
||||||||||||||||||||||
displayLastUpdateFormat |
Format to use for the time display if displayLastUpdate:true Type: |
||||||||||||||||||||||
animationSpeed |
Speed of the update animation. Type: |
Here is an example for an entry in the modules array in your config.js
:
{
module: "MMM-PublicTransportHafas",
position: "bottom_right",
config: {
// Departures options
stationID: "8012202", // Replace with your stationID!
stationName: "Wilhelm-Leuschner-Platz", // Replace with your station name!
direction: "", // Show only departures heading to this station. (A station ID.)
excludedTransportationTypes: [], // Which transportation types should not be shown on the mirror? (comma-separated list of types) possible values: "tram", "bus", "suburban", "subway", "regional" and "national"
ignoredLines: [], // Which lines should be ignored? (comma-separated list of line names)
timeToStation: 10, // How long do you need to walk to the next Station?
// Look and Feel
displayLastUpdate: true, // Display the last time of module update.
maxUnreachableDepartures: 0, // How many unreachable departures should be shown?
maxReachableDepartures: 7, // How many reachable departures should be shown?
showColoredLineSymbols: true, // Want colored line symbols?
customLineStyles: "", // Prefix for the name of the custom css file. ex: Leipzig-lines.css (case sensitive)
showOnlyLineNumbers: false, // Display only the line number instead of the complete name, i. e. "11" instead of "STR 11"
showTableHeadersAsSymbols: true, // Table Headers as symbols or text?
useColorForRealtimeInfo: true // Want colored real time information (timeToStation, early)?
}
},
It is possible to use multiple instances of this module just by adding another entry of the MMM-PublicTransportHafas module to the config.js
of your mirror.
You can even use the same stationID
in different instances. So you can display in one instance something like “main station heading eastbound” and in another instance “main station heading westbound”.
Note: For some cities, separate CSS files have already been created that contain the local line colors. You can look them up in the css
directory. If you create a file for another city, feel free to send it to us.
If you set showColoredLineSymbols
to true
the module will try to colorize the line symbols. This is done by appending a CSS class to the line symbol. This class is named after the line name but blanks are left out and all letters are lower case. So if the line name is “STR 11” the appended CSS class name is .str11
.
To provide your own classes create a CSS file in the css
directory of the module. It must be named like <your custom name>-lines.css
, where <your custom name>
can be any valid filename but should not contain blanks or dots. The part <your custom name>
is then used in the config file as value for the customLineStyles
property.
In the example above “leipzig” is used as value for the customLineStyles
property. Therefore there must be a file named leipzig-lines.css
inside the css
directory. If this is not the case the module won’t be started and it will not be visible. The browser’s console will show an error.
Basically you can set whatever you want in the CSS file but it is recommended to only set the foreground and background color and the width. In some cases it is useful to change the border radius too. See the file css/leipzig-lines.css
for reference and as a guideline.
In Leipzig the tram lines 2, 8 and 9 use a yellow color. Since the lines share the same settings the CSS class names are listed with commas so that the settings apply to each listed class.
.str2,
.str8,
.str9 {
background-color: #f8c623; /* yellow background */
color: black; /* text color black */
}
Some night buses in Leipzig use an orange-ish color.
.busn1,
.busn1e,
.busn5,
.busn5e,
.busn8,
.busn8e {
background-color: #ee9f2e; /* orange-ish background */
color: #164585; /* blue-ish text color */
}
Alongside the departure time a small figure displays the delay as reported by the transport provider.
Delays are displayed as red.
No delay or negative delays (the transport will arrive early) are displayed in green.
Sometimes there is no real-time data for a departure, in that case it is displayed with a question mark:
If you want to customize that include the classes mmm-pth-has-delay
and mmm-pth-to-early
in your custom CSS file and make the appropriate settings.
To limit the server request only when the module is displayed and/or the user is present, the update will be stopped when no instance of the module are displayed (module hidden e.g. by a MMM-Carousel, MMM-Pages or MMM-Remote-Control). The update will also be stopped by the use of a PIR sensor using the module MMM-PIR-Sensor (that sends the notification 'USER_PRESENCE'). No special configuration is needed for this behavior.
Thanks to @AgP42 for this functionality!
If you find any problems, bugs or have questions, please open a GitHub issue in this repository.
Pull requests are of course also very welcome 🙂
npm run lint
- Run linting and formatter checks.npm run lint:fix
- Fix linting and formatter issues.npm run test
- Run linting and formatter checks + Run spelling check.npm run test:spelling
- Run spelling check.npm run release
- Bump version for release.