UK Transport
The UK Transport integration will display the time in minutes until the next departure in a specified direction from of a configured train station or bus stop. The sensor uses transportAPI to query live departure data and requires a developer application ID and key which can be obtained here. The free tier allows 30 requests a day, which is sufficient for a single sensor refreshing every 48 minutes.
Additional sensors can be added but at the expense of a reduced refresh rate. 2 sensors can be updated every 2*48 = 96 minutes, and so on. Calculating and setting this rate is automatically handles by the integration.
:::
Queries are entered as a list, with the two transport modes available being bus and train.
Train departure sensors require three character long origin and destination station codes which are searchable on the National Rail enquiries website (e.g., WAT is London Waterloo). The validity of a route can be checked by performing a GET request to /uk/train/station/{station_code}/live.json in the API reference webpage.
To add a single train departure integration add the following to your "configuration.yaml" file.
:::tip
更改配置后需要重启 Home Assistant。
A large amount of information about upcoming departures is available within the attributes of the sensor. The example above creates a sensor with ID sensor.next_train_to_wat with the attribute next_trains which is a list of the next 25 departing trains.
These attributes are available for each departing train:
origin_namedestination_namestatusscheduled: (API attribute isaimed_departure_time)estimated: (API attribute isexpected_departure_time)platformoperator_name
Refer to the API reference webpage for definitions.
Attributes can be accessed using the template sensor as per this example:
Bus sensors require as their origin a bus stop ATCO code which can be found by browsing OpenStreetMap data as
follows:
- On OpenStreetMap.org zoom right in on a bus stop you're interested in.
- Click the layers picker button on the right hand side.
- Tick the 'map data' layer, and wait for clickable objects to load.
- Click the bus stop node to reveal its tags on the left.
The destination must be a valid location in the "direction" field returned by a GET query to /uk/bus/stop/{atcocode}/live.json as described in the API reference webpage. A bus sensor is added in the following "configuration.yaml" file entry:
And the template sensor for viewing the next bus attributes.
Managing API requests
If you wish to manage the rate of API requests (e.g., to disable requests when you aren't interested in travel, so that you can request updates more frequently when you do travel) set a really long scan_interval in the configuration options, and use the homeassistant.update_entity action to request the update of an entity, rather than waiting for the next scheduled update.
Powered by transportAPI

