Hi all! I just created my first integration that connects with the WMATA API which can be found here.
This integration creates sensors for the next trains or buses to your local stop, allowing you to always see when the next trains/buses are coming and where they’re going without needing to check an app.
Installation
To install this integration, you will need to have HACS installed. After HACS is installed, you should be able to click this button to install this integration:
- Open HACS in Home Assistant
- Select the three dots in the upper right, and select “Custom repositories”
- In the popup, enter the URL of this page in the “Repository” spot, select the type as “Integration”, and select “Add”
- Within HACS, search for WMATA
- Click the WMATA entry, and select “Download”
- Now, setup the integration by going to “Settings” > “Devices & services”
- Select “Add integration”
- Search for “WMATA”
- Enter your WMATA API key and metro station ID/bus stop ID
- Select “Submit”, and you should see the sensors appear!
Getting a WMATA API Key
To get a WMATA API key, follow these steps:
- Sign up for a new WMATA developer account here
- After your account is created, go to “Products”, and select “Default Tier”
- On this page, enter the name of your new API key (ex: “Home assistant”), agree to the terms of use, and select “Subscribe”
- After your key is created, it will show you your API key, enter that in the installation steps
If you ever lose or forget your API details, you can find it on your profile under “Subscriptions”.
Getting Your Metro Station ID
Unfortunately there’s no good way to see a list of all of the bus station stop or metro station codes online outside of using the API. I’ve provided a list of the metro station codes in the file "METRO_STATION_CODES.md in /docs. Simply open it, find your local metro station, and add the code next to it.
IMPORTANT NOTE: if you see that your “local” metro station has two entries, make sure to pick the entry with the line you want. For example, say your local metro station is “Metro Center”, and you ride the orange line. In this case, you would select the station code “C01”, not “A01”.
Getting Your Bus Stop ID
Similar to the metro station ID process, there’s no good way to get your bus stop ID. The easiest way is to check your bus stop, the sign will show a 7 digit number on the bottom right that is the bus stop ID.
Another option is to use the script in this repository in /scripts/get_closest_bus_stop.py. If you run this, you’ll enter your latitude and longitude and it will show you the closest bus stops. One of these options should be able to get you the bus stop ID you’re looking for.
Setting Up Multiple Stations/Stops
If you want to have buses/trains for multiple stations setup, follow these steps:
- Go to “Settings” > “Integrations” > “WMATA”
- Select “Add Hub”
- Enter your API key again, along with the new station/stop ID
- Select “Submit”
After this is completed, you should see the new entities appear for the new station.
Dashboards
Bubble Card
If you use bubble card, here’s a quick sample I’ve created using this integration.
type: custom:bubble-card
card_type: button
button_type: name
name: Train 1
icon: mdi:train
sub_button:
- entity: sensor.wmata_a01_train_1_destination
show_name: false
show_state: true
- entity: sensor.wmata_a01_train_1_line
show_state: true
- entity: sensor.wmata_a01_train_1_time
show_state: true
show_attribute: false
show_name: false
show_last_changed: false
show_background: true
state_background: true
Mushroom
If you use mushroom, here’s a quick sample I’ve created using this integration.
type: horizontal-stack
cards:
- type: custom:mushroom-entity-card
entity: sensor.wmata_a01_train_1_destination
- type: custom:mushroom-entity-card
entity: sensor.wmata_a01_train_1_line
- type: custom:mushroom-entity-card
entity: sensor.wmata_a01_train_1_time