This MagicMirror module displays upcoming bus or train times from any transit stop across 150+ transit agencies in 25 countries. See if your stop is served by Transit using their app before investing time in this module!
Use this module to see upcoming departures from a bus or train stop of interest.
Some transit agencies provide a standardized GTFS feed for real-time transit updates. But many supply their own API, or sometimes no programmatic way to access their transit times at all. Transit App partners with local transit agencies and combines it with crowdsourced data, to provide a standard, high-quality feed for public transit in most of North and South America and much of Europe.
-
If your transit agency publishes their schedule in GTFS format, MMM-transitfeed will work for you and does not need an API key. On the plus side, you can refresh departure times as frequently as you desire. The downside may be that the configuration is somewhat more complex and specific to your local public transit agency.
-
There are a few modules that use the Google Maps API: e.g., MMM-GoogleBusSchedule and MMM-LocalTransport. Unfortunately, as the Google Directions API is being deprecated, some of these may not work as intended unless the modules are re-written to use the Routes API. I have not tested which one of these still work. You will need a credit card for Google Cloud Platform, even if you limit yourself to the free tier.
If you found this module useful, please consider leaving a star on GitHub so others may find it. Thank you!
Before you begin, ensure you have:
- A working MagicMirror² installation.
- Request an API key from Transit App. See the Transit App documentation for details.
- Get the bus/train station code using the
/public/nearby_stops
endpoint through a bash terminal.
sudo apt update
sudo apt install curl jq
npm install node-fetch
API_KEY=(Your Transit App API key)
STATION_LATITUDE=(Latitude of your bus/train stop)
STATION_LONGITUDE=(Longitude of your bus/train stop)
LOCATION_PRECISION=200
curl -H "Accept-Language:en" -H "apiKey:$API_KEY" "https://external.transitapp.com/v3/public/nearby_stops?max_distance=$LOCATION_PRECISION&lat=$STATION_LATITUDE&lon=$STATION_LONGITUDE" | jq
If you don't see any results from the API response, the location you provided is not close to any stops in Transit's database. You may increase LOCATION_PRECISION
up to 1500 meters to show more nearby stops. Also, make sure you are using the location of the bus/train stop of interest and not your location.
From the JSON response, make a note of the "global_stop_id"
of your stop. It will be formatted as "ABC:12345"
. If you would like to monitor multiple stops, please use multiple instances of this module.
In your terminal, go to your MagicMirror² Module folder and clone MMM-Template:
cd ~/MagicMirror/modules
git clone https://github.com/thariq-shanavas/MMM-PublicTransit
To use this module, add it to the modules array in the config/config.js
file:
{
module: 'MMM-PublicTransit',
position: 'top_right',
header: 'Your Stop Name',
config: {
global_stop_id: 'abc:1234',
apiKey: ''
}
},
The free tier is limited to 1500 calls per month, or about one every 30 minutes. The display will update every 30 seconds, but the API calls are cached so you may see outdated information. To do more frequent API calls during your commute hours for better real-time info, consider setting the activeHours
configuration value to disable refreshing when you do not need real-time transit times.
The terms and conditions of the Transit App API requires that the Transit Logo be shown next to the feed. Transit App provides a valuable service at no cost and I feel it is a very fair ask. However, this code is MIT licensed and 'free' as in freedom, so if you feel very strongly about the logo you may hide it from the configuration file.
Option | Description | Default |
---|---|---|
global_stop_id (required) |
The global stop ID from the Transit App API. | "" |
apiKey (required) |
Your Transit App API key. | "" |
logosize |
Size of the Transit logo. | "40px" |
showlogo |
Show or hide the transit logo (true , false ) |
true |
displayed_entries |
Number of bus times to display. | 3 |
fontsize |
Font size for bus times. | "24px" |
logoLocation |
Logo alignment (flex-start , flex-end ). |
"flex-end" |
activeHoursStart |
Active hours start time (24-hour format). | 6 |
activeHoursEnd |
Active hours end time (24-hour format). | 22 |
activeDays |
Active days of the week (0 = Sunday, 6 = Saturday). | [0, 1, 2, 3, 4, 5, 6] |
updateFrequency |
Update frequency in minutes. | 30 |
cd ~/MagicMirror/modules/MMM-PublicTransit
git pull
If the module does not work as expected, please create a github issue and share the output of the following commands:
pm2 stop MagicMirror
cd ~/MagicMirror
npm start
The Transit API has a limitation where it only returns a maximum of 3 future departures for any given route. For example, if the actual departures are:
- 9:30 AM - Bus A
- 9:35 AM - Bus A
- 9:40 AM - Bus A
- 9:45 AM - Bus A
- 9:50 AM - Bus B
The API will return:
- 9:30 AM - Bus A
- 9:35 AM - Bus A
- 9:40 AM - Bus A
- 9:50 AM - Bus B
This behavior is a limitation of the Transit API and is unlikely to be fixed. The issue is partially mitigated by more frequent API calls.