SF Bay Area Transit smart home integration, free and open source

Unofficial. Next departures and alerts at your SF Bay Area stops, data provided by 511.org.
The next departures and the service alerts at up to five stops of the San Francisco Bay Area (Muni, BART, Caltrain, AC Transit, SamTrans, VTA, Golden Gate Transit, ferries...), in Gladys. Data provided by 511.org (511.org).
This integration is unofficial: it is not affiliated with 511, MTC nor any transit operator, and it is not an official source. Check 511.org or the operator before you travel. It was never tested with a real 511 token nor on a real Gladys installation by its author: it was written from the 511 specification and tested against a simulated 511 that follows it.
Get started in 4 steps
-
Get a free 511 token on 511.org/open-data/token: you receive it by e-mail. Accepting the 511 terms is your choice: you are the one who receives the data.
-
Find your stop. You need the 511 id of the operator and the stop code:
Operator Id Muni (SFMTA) SFBART BACaltrain CTAC Transit ACSamTrans SMVTA SCGolden Gate GGThe stop code is on the sign of most bus stops (Muni: 5 digits, e.g.
15553), and in the stop list of the operator on 511.org. A parent station code gives every platform of the station. -
Install the integration from the catalog, paste the token in 511 token, type the operator and the stop code in Stop 1, and save.
-
Open the Discover tab and press Add on the stop.
One device per stop. A device belongs to a slot, its operator and its stop code: typing another stop in a slot offers a new device; the old one is no longer updated (delete it in Gladys). Changing the line filter keeps the device.
The quota of the token
A 511 token allows 60 requests per hour by default (511 can raise it on request: type your limit in Hourly limit of your token). The integration:
- reads each stop with one request per read (511 answers one stop per request), and the alerts with one request per operator every 15 minutes or more;
- plans the intervals so that no hour holds more than 90 % of your limit: with the default limit, 1 stop every 5 minutes plus its alerts is 16 requests an hour; 5 stops of 3 operators are read every 8 minutes (52 an hour). When your interval does not fit, it is lengthened and the status says so;
- counts every request it sends and never sends one when the last hour
already holds 90 % of the limit (it waits up to 2 minutes for a slot, else
that read is skipped and the status says so). The count is written to
/databefore the request leaves, so a restart knows it. When/datacannot tell it (unreadable file), the first reads wait one interval; - stops every read when 511 answers 429: for the time it asks, 10
minutes at least (doubled on the next ones), 6 hours at most, kept across a restart;
a 5xx or another refusal of the departures (403...) pauses every read 2
minutes (doubled, 6 hours at most); a failed alerts read waits 15 minutes,
then 30, 60, 120 for that operator only, also across a restart (the time of
the attempt is written to
/databefore the request leaves).
Discovery, the Show the last reads button and saving an unchanged configuration never read 511 (saving the configuration again only tries a token refused before a restart once more).
What each device holds
The name of the Next departure feature ends with "(data provided by
511.org)", the others with "(511.org)": the attribution 511 asks for, next to
the data. The minutes of a text are counted at the time of the read: with a
long interval, read the clock time (10:03), which stays right.
- Next departure and Following departure: texts with the line, the
destination, the minutes to wait (counted against the time of the 511
answer) and the clock time, e.g.
14 MISSION → Downtown: 3 min (10:03);, scheduledwhen the operator gives only the timetable time. When there is none:No predicted departure (read 10:05). They are texts so that a departure that no longer exists is never left on the dashboard as a number. - Departures within 60 min: a counter, for the scenes.
- Service alerts: how many alerts are in effect now for the stop, its lines or its whole operator.
- Alert: the text of the first one, e.g.
Line 49 detour. (+1 more), orNo alert (read 10:05).
The lines of a stop, for the alerts, are the lines you filtered, else the lines 511 showed at the stop (kept 7 days). Until a first departure is seen, the alert count of the stop waits (the status says so): a count made without the lines of the stop would miss their alerts. A line that has not called at the stop for 7 days is forgotten.
Never a made-up value
-
An alerts feed without a header time is not used (its age is unknown): no "No alert" from it.
-
A line filter that matches none of the departures 511 shows at the stop, three reads in a row, is said in the status: check the line names.
-
A read that failed, an answer that cannot be read (one departure whose time cannot be read refuses the whole answer), an answer whose time differs from the clock of the machine by more than 5 minutes: nothing is published, never 0; the status says why and since when.
-
"No predicted departure" is published only for a stop where 511 has shown a departure once: a mistyped stop code would otherwise look like an empty stop.
-
A stop that 511 answers 404 (unknown) is tried again after 30 minutes; the other stops go on.
-
A refused token (401 to a departures read) stops every read and is kept (a short fingerprint in
/data, never the token): save a new token to read again. A 401 to an alerts read is not taken as a refused token.
Privacy
The token is kept by Gladys in its database, never shown again, sent only to
511.org, never written in the logs, the status nor /data. Your stop codes are
written to /data only as salted fingerprints; the operator ids and the lines
seen at a stop are written in clear (no personal data).
Licence and data
The code is under the Apache License 2.0. The data is provided by 511.org (Metropolitan Transportation Commission) under the 511 Data Disseminator Agreement that you accept with your token: data provided by 511.org, no warranty, no operator logo. The integration does not use "511" as a brand.
Configuration settings
These are the settings SF Bay Area Transit asks for in its configuration screen in Gladys.
| Setting | Type | Required | Description |
|---|---|---|---|
| SF Bay Area transit departures and alerts | section | No | The next departures and the service alerts at up to five stops of the San Francisco Bay Area (Muni, BART, Caltrain, AC Transit, SamTrans, VTA, Golden Gate...), data provided by 511.org. You need a free 511 token (511.org/open-data/token, by e-mail). A token allows 60 requests per hour by default: the integration plans its reads to stay within 90 % of the limit you give, one request per stop and per read, the alerts one request per operator every 15 minutes or more. Each stop is a device. Check 511.org or the operator before you travel: this integration is not an official source and is not endorsed by 511 or MTC. |
| 511 token | secret | Yes | Your 511 Open Data token (the api_key of the e-mail from 511). Kept by Gladys in its database, never shown again, sent only to 511.org. |
| Language of the texts | select | No | Language of the device names, the departure texts and the status. The alerts come in this language when the operator gives it, else in English. |
| Read interval of the departures (minutes) | number | No | From 2 to 60 minutes. One request per stop at each read. Lengthened automatically when the stops and the alerts would not fit in the hourly limit (the status says so). |
| Hourly limit of your token | number | No | Requests per hour allowed to your token: 60 unless 511 raised it for you (20 to 1000). The integration never sends more than 90 % of it in any hour. |
| Service alerts | select | No | Read the service alerts of the operators of your stops (one request per operator every 15 minutes or more). |
| Stop 1 | section | No | Required. An operator id and a stop code of 511. The stop code is on the sign of the stop or in the stop list of the operator on 511.org (e.g. SF 15553 for Muni, BA for BART, CT for Caltrain, AC for AC Transit). |
| Name | string | No | Name of the device in Gladys (60 characters at most). Empty: the operator and the stop code. |
| Operator id | string | Yes | The 511 id of the operator: SF (Muni), BA (BART), CT (Caltrain), AC (AC Transit), SM (SamTrans), SC (VTA), GG (Golden Gate)... |
| Stop code | string | Yes | The stop code of 511 (letters, digits, - and _); a parent station gives every platform. |
| Lines (optional) | string | No | Only these lines, comma separated (10 at most), as 511 names them (e.g. 14, 14R). Empty: every line. |
| Stop 2 | section | No | Optional. An operator id and a stop code of 511. The stop code is on the sign of the stop or in the stop list of the operator on 511.org (e.g. SF 15553 for Muni, BA for BART, CT for Caltrain, AC for AC Transit). |
| Name | string | No | Name of the device in Gladys (60 characters at most). Empty: the operator and the stop code. |
| Operator id | string | No | The 511 id of the operator: SF (Muni), BA (BART), CT (Caltrain), AC (AC Transit), SM (SamTrans), SC (VTA), GG (Golden Gate)... |
| Stop code | string | No | The stop code of 511 (letters, digits, - and _); a parent station gives every platform. |
| Lines (optional) | string | No | Only these lines, comma separated (10 at most), as 511 names them (e.g. 14, 14R). Empty: every line. |
| Stop 3 | section | No | Optional. An operator id and a stop code of 511. The stop code is on the sign of the stop or in the stop list of the operator on 511.org (e.g. SF 15553 for Muni, BA for BART, CT for Caltrain, AC for AC Transit). |
| Name | string | No | Name of the device in Gladys (60 characters at most). Empty: the operator and the stop code. |
| Operator id | string | No | The 511 id of the operator: SF (Muni), BA (BART), CT (Caltrain), AC (AC Transit), SM (SamTrans), SC (VTA), GG (Golden Gate)... |
| Stop code | string | No | The stop code of 511 (letters, digits, - and _); a parent station gives every platform. |
| Lines (optional) | string | No | Only these lines, comma separated (10 at most), as 511 names them (e.g. 14, 14R). Empty: every line. |
| Stop 4 | section | No | Optional. An operator id and a stop code of 511. The stop code is on the sign of the stop or in the stop list of the operator on 511.org (e.g. SF 15553 for Muni, BA for BART, CT for Caltrain, AC for AC Transit). |
| Name | string | No | Name of the device in Gladys (60 characters at most). Empty: the operator and the stop code. |
| Operator id | string | No | The 511 id of the operator: SF (Muni), BA (BART), CT (Caltrain), AC (AC Transit), SM (SamTrans), SC (VTA), GG (Golden Gate)... |
| Stop code | string | No | The stop code of 511 (letters, digits, - and _); a parent station gives every platform. |
| Lines (optional) | string | No | Only these lines, comma separated (10 at most), as 511 names them (e.g. 14, 14R). Empty: every line. |
| Stop 5 | section | No | Optional. An operator id and a stop code of 511. The stop code is on the sign of the stop or in the stop list of the operator on 511.org (e.g. SF 15553 for Muni, BA for BART, CT for Caltrain, AC for AC Transit). |
| Name | string | No | Name of the device in Gladys (60 characters at most). Empty: the operator and the stop code. |
| Operator id | string | No | The 511 id of the operator: SF (Muni), BA (BART), CT (Caltrain), AC (AC Transit), SM (SamTrans), SC (VTA), GG (Golden Gate)... |
| Stop code | string | No | The stop code of 511 (letters, digits, - and _); a parent station gives every platform. |
| Lines (optional) | string | No | Only these lines, comma separated (10 at most), as 511 names them (e.g. 14, 14R). Empty: every line. |
How to install SF Bay Area Transit in Gladys
- In Gladys, open Integrations: SF Bay Area Transit appears in the catalog, next to the native integrations, with a community badge.
- Click Install. Gladys pulls the Docker image (
ghcr.io/lm1lc3n7/gladys-sf-bay-transit:0.1.1), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration). - Open the Configuration screen of the integration, fill in the settings, and save.
- You can also install it directly from its repository URL: https://github.com/LM1LC3N7/gladys-sf-bay-transit.
SF Bay Area 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
SF Bay Area 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.
- Browse all integrations, native and community
- Build and publish your own external integration
- Source code on GitHub — source of this documentation