UK Transport
The uk_transport
integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] 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
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 enquiriesWAT
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集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] add the following to your configuration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file.
在更改了configuration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 文件后,重启 Home Assistant 以应用更改。 该集成现在显示在集成页面的 设置 > 设备与服务 下。其实体在集成卡片上以及实体标签上列出。
# Example configuration.yaml entry for a single sensor
sensor:
- platform: uk_transport
app_id: YOUR_APP_ID
app_key: YOUR_APP_KEY
queries:
- mode: train
origin: MAL
destination: WAT
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_name
destination_name
status
-
scheduled
: (API attribute isaimed_departure_time
) -
estimated
: (API attribute isexpected_departure_time
) platform
operator_name
Refer to the API reference webpage
Attributes can be accessed using the template sensor as per this example:
# Example configuration.yaml entry for a template sensor to access the attributes of the next departing train.
template:
- sensor:
- name: Next train status
state: >-
{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].status}}
- name: Next train origin
state: >-
{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].origin_name}}
- name: Next train estimated
state: >-
{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].estimated}}
- name: Next train scheduled
state: >-
{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].scheduled}}
- name: Next train platform
state: >-
{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].platform}}
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 webpageconfiguration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file entry:
# Example configuration.yaml entry for multiple sensors
sensor:
- platform: uk_transport
app_id: YOUR_APP_ID
app_key: YOUR_APP_KEY
queries:
- mode: bus
origin: 340000368SHE
destination: Wantage
- mode: train
origin: MAL
destination: WAT
And the template sensor for viewing the next bus attributes.
# Example configuration.yaml entry for a template sensor to access the attributes of the next departing bus.
template:
- sensor:
- name: Next bus route
state: "{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].route}}"
- name: Next bus direction
state: "{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].direction}}"
- name: Next bus scheduled
state: "{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].scheduled}}"
- name: Next bus estimated
state: "{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].estimated}}"
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实体表示 Home Assistant 中的传感器、执行器或功能。实体用于监控物理属性或控制其他实体。实体通常是设备或服务的一部分。 [Learn more], rather than waiting for the next scheduled update.
Powered by transportAPI