A custom Home Assistant integration for the 511.org Transit API that provides real-time transit information for Bay Area transit agencies including SF Muni, BART, AC Transit, and more.
- API Key Reuse 🔑 (v1.3.0): Enter your API key once, then automatically reuse it for all future stops/vehicles - no more re-entering credentials!
- Smart Icons 🎨: Icons automatically change based on vehicle type!
- SF Muni: Letters (N, T) → 🚊 train, Numbers (7, 14) → 🚌 bus
- BART, Caltrain → Always 🚊 train
- AC Transit, SamTrans → Always 🚌 bus
- See
SMART_ICONS.mdfor details
- Device Organization: Each stop or vehicle creates a dedicated Device with all sensors grouped together
- Stop Monitoring: Track arrival and departure times at transit stops
- Vehicle Tracking: GPS tracking of individual transit vehicles via device_tracker
- Flexible Entity Creation: Choose which sensors to create for each stop
- Direction Filtering: Separate sensors for inbound/outbound directions
- Multiple Stops/Vehicles: Add as many stops or vehicles as needed
- Configurable Update Intervals: Balance freshness vs. API rate limits
Any agency available through the 511.org API, including:
- San Francisco Muni (SF)
- BART (BA)
- AC Transit (AC)
- Caltrain (CM)
- County Connection (CC)
- And many more Bay Area transit agencies
- Open HACS in Home Assistant
- Go to "Integrations"
- Click the three dots in the top right and select "Custom repositories"
- Add this repository URL and select "Integration" as the category
- Click "Install"
- Restart Home Assistant
- Copy the
custom_components/transit_511folder to your Home Assistant'scustom_componentsdirectory - Restart Home Assistant
- Visit https://511.org/open-data/token
- Register for a free API key
- Note: Free tier has a limit of 60 requests per hour
First Time Setup:
- Go to Settings → Devices & Services
- Click "Add Integration"
- Search for "511 Transit"
- Enter your 511.org API key (you'll only need to do this once!)
- Choose monitoring type:
- Stop Monitoring: For arrival/departure predictions at a stop
- Vehicle Monitoring: For GPS tracking of a specific vehicle
- Configure your stop or vehicle details
Adding Additional Stops/Vehicles:
- Go to Settings → Devices & Services
- Click "Add Integration"
- Search for "511 Transit"
- Your API key is automatically reused - you'll skip straight to monitoring type selection!
- Configure your next stop or vehicle
The integration remembers your API key from the first setup, making it quick and easy to add multiple stops and vehicles without re-entering credentials.
- Select the transit operator (e.g., SF for Muni)
- Enter the stop code (e.g., 18031 for Irving & 5th Ave)
- Optionally specify a line/route ID to filter
- The integration will create various sensors for that stop
- Select the transit operator
- Enter the vehicle ID you want to track
- A device_tracker entity will be created with GPS location
Each stop/vehicle gets its own Device in Home Assistant with:
- All related sensors grouped under the device
- Device info showing operator/agency name
- Easy organization in the Devices page
- Independent update intervals and configuration
Example workflow (v1.3.0+):
- First integration: Enter API key → Stop monitoring → N Judah @ Irving & 5th → Creates device: "SF N @ Irving St & 5th Ave"
- Second integration: API key reused automatically → Stop monitoring → N Judah @ 9th & Irving → Creates device: "SF N @ 9th Ave & Irving St"
- Third integration: API key reused automatically → Vehicle monitoring → Track vehicle 2080 → Creates device: "SF Vehicle 2080"
- Fourth integration: API key reused automatically → Stop monitoring → BART @ Embarcadero → Creates device: "BA @ Embarcadero Station"
Note: After your first setup, you'll never need to enter your API key again - it's automatically reused for all subsequent stops and vehicles!
You can monitor as many stops and vehicles as you want:
- Each requires a separate integration entry (just click "Add Integration" again)
- Your API key is automatically shared across all entries (v1.3.0+)
- Be mindful of the 60 requests/hour rate limit (see below)
- SF Muni: Stop codes are visible on stop signs and in the 511.org trip planner
- 511.org API: Use the
/transit/stopsendpoint with your operator ID - Example: For SF Muni stop "Irving St & 5th Ave", the stop code is
18031
The integration can create the following sensors for each stop:
- Count: Number of upcoming arrivals
- API Timestamp: Last API update time
- Next Arrival (minutes): Minutes until next arrival
- Next Arrival Time: Timestamp of next arrival
- Next Vehicle: Vehicle ID of next arrival
- Next Destination: Destination of next vehicle
- Next Occupancy: Crowding level (seatsAvailable, standingAvailable, full)
- Next Three: Comma-separated minutes for next 3 arrivals (e.g., "6, 14, 22")
- API OK: Binary sensor for API connectivity
For each direction (IB = Inbound, OB = Outbound):
- IB/OB Count: Count filtered by direction
- IB/OB Next Arrival (minutes): Next arrival for that direction
- IB/OB Next Arrival Time: Timestamp for that direction
- IB/OB Next Vehicle: Vehicle ID for that direction
- IB/OB Next Three: Next 3 arrivals for that direction
When monitoring a vehicle, the integration creates a device_tracker entity with:
- GPS coordinates (latitude/longitude)
- Bearing/heading
- Line/route information
- Origin and destination
- Occupancy status
- Next stop information
After setup, you can configure:
- Update Interval: How often to fetch data (30-300 seconds)
- Default: 60 seconds
- Note: 60 req/hour limit = max 1 request per minute per API key
- Enabled Entities: Which sensors to create for stop monitoring
The 511.org API has a rate limit of 60 requests per hour per API key.
- Default interval: 60 seconds = 60 requests/hour per stop (at the limit)
- Multiple stops/vehicles: Each config entry makes its own requests
- 2 stops at 60s = 120 req/hr (OVER LIMIT)
- 2 stops at 120s = 60 req/hr (at limit)
- 3 stops at 180s = 60 req/hr (at limit)
- 4 stops at 240s = 60 req/hr (at limit)
- Formula:
(3600 / interval_seconds) × number_of_stops ≤ 60 - Recommended: If monitoring multiple stops, increase intervals accordingly
- Example: 3 stops → use 180s (3 minute) intervals
- Single API key, multiple stops: Adjust intervals based on number of stops
- Multiple API keys: Get additional API keys to monitor more stops at shorter intervals
- Priority stops: Use shorter intervals (60s) for important stops, longer intervals (300s) for others
type: entities
title: N Judah @ Irving & 5th
entities:
- entity: sensor.sf_n_irving_5th_ave_next_arrival_min
name: Next Train
- entity: sensor.sf_n_irving_5th_ave_next_three
name: Next 3 Trains
- entity: sensor.sf_n_irving_5th_ave_next_destination
name: Destination
- entity: sensor.sf_n_irving_5th_ave_next_occupancy
name: Crowdingautomation:
- alias: "Train Alert"
trigger:
- platform: numeric_state
entity_id: sensor.sf_n_irving_5th_ave_ib_next_arrival_min
below: 5
action:
- service: notify.mobile_app
data:
message: "N Judah arriving in {{ states('sensor.sf_n_irving_5th_ave_ib_next_arrival_min') }} minutes!"type: map
entities:
- entity: device_tracker.sf_vehicle_2080
default_zoom: 13- Verify your API key is correct
- Check that your API key is active at https://511.org/open-data/token
- You're making more than 60 requests per hour
- Increase your update interval
- Reduce the number of monitored stops/vehicles
- Verify the stop code is correct for your operator
- Check that the stop has active service
- Some stops may not have real-time data available
- Check the "API OK" binary sensor - should be "on"
- Review Home Assistant logs for errors
- Verify internet connectivity
Full 511.org API documentation: https://511.org/open-data/transit
For issues, feature requests, or questions:
- Open an issue on GitHub
- Check the Home Assistant community forums
MIT License - see LICENSE file for details