home-assistant.io/source/_components/sensor.uk_transport.markdown
Stuart McCroden 72631830da Standardize example configuration blocks (#6953)
* Standardized values in the example configuration

Removed what appear to be an actual API key from the example configuration.yaml block. And, replaced with values as described in the [developer docs](https://developers.home-assistant.io/docs/en/documentation_standards.html#component-and-platform-pages)

* Standardize example configuration-ecobee

* Standardize example configuration-coinbase

* Standardize example configuration-google assistant

* Standardize example configuration-cloudflare

* Standardize example configuration-cloudflare

* Standardize example configuration-habitica

* Standardize example configuration-ifttt

* Standardize example configuration-openalpr

* Standardize example configuration-multiple

* Standardize example configuration-instapush

* Standardize example configuration-llamalab

* Standardize example configuration-notify

* Standardize example configuration-mailgun

* Standardize example configuration-MULTIPLE

* Standardize example configuration-rtm

* Standardize example configuration-spotcrime

* Standardize example configuration-trafikverket

* Standardize example configuration-uk transport

* Standardize example configuration-wunderground

* Standardize example configuration-wsdot

* Standardize example configuration-telegram

* Standardize example configuration-tts

* Standardize example configuration-tts, vultr

* Replace email entry

* Replace IP address

* Place email address
2018-10-19 22:52:25 +02:00

151 lines
6.4 KiB
Markdown

---
layout: page
title: "UK transport"
description: "Display the current status of UK train and bus departures."
date: 2017-07-07 18:00
sidebar: true
comments: false
sharing: true
footer: true
logo: train.png
ha_category: Transport
ha_iot_class: "Cloud Polling"
ha_release: "0.50"
---
The `uk_transport` sensor 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](http://www.transportapi.com/) to query live departure data and requires a developer application ID and key which can be obtained [here](https://developer.transportapi.com/). The [free tier](http://www.transportapi.com/plans/) allows 1000 requests daily, which is sufficient for a single sensor refreshing every 87 seconds.
<p class='note warning'>
Additional sensors can be added but at the expense of a reduced refresh rate. 2 sensors can be updated every 2*87 = 174 seconds, and so on.
</p>
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](http://www.nationalrail.co.uk/times_fares/ldb.aspx) 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](https://developer.transportapi.com/docs?raml=https://transportapi.com/v3/raml/transportapi.raml##request_uk_train_station_station_code_live_json).
To add a single train departure sensor add the following to your `configuration.yaml` file:
```yaml
# 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
```
{% configuration %}
app_id:
description: Your application ID.
required: true
type: string
app_key:
description: Your application Key.
required: true
type: string
queries:
description: At least one entry required.
required: true
type: list
keys:
mode:
description: One of `bus` or `train`.
required: true
type: list
origin:
description: Specify the three character long origin station code.
required: true
type: string
destination:
description: Specify the three character long destination station code.
required: true
type: string
{% endconfiguration %}
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 is `aimed_departure_time`)
- `estimated`: (API attribute is `expected_departure_time`)
- `platform`
- `operator_name`
Refer to the [API reference webpage](https://developer.transportapi.com/docs?raml=https://transportapi.com/v3/raml/transportapi.raml##request_uk_train_station_station_code_live_json) for definitions.
Attributes can be accessed using the [template sensor](/components/sensor.template/) as per this example:
```yaml
# Example configuration.yaml entry for a template sensor to access the attributes of the next departing train.
- platform: template
sensors:
next_train_status:
friendly_name: 'Next train status'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].status}}'{% endraw %}
next_trains_origin:
friendly_name: 'Next train origin'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].origin_name}}'{% endraw %}
next_trains_estimated:
friendly_name: 'Next train estimated'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].estimated}}'{% endraw %}
next_trains_scheduled:
friendly_name: 'Next train scheduled'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].scheduled}}'{% endraw %}
next_trains_platform:
friendly_name: 'Next train platform'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].platform}}'{% endraw %}
```
Bus sensors require as their `origin` a bus stop ATCO code which can be found by browsing OpenStreetMap data as
follows:
1. On [OpenStreetMap.org](http://www.openstreetmap.org/) zoom right in on a bus stop you're interested in.
2. Click the layers picker button on the right hand side.
3. Tick the 'map data' layer, and wait for clickable objects to load.
4. 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](https://developer.transportapi.com/docs?raml=https://transportapi.com/v3/raml/transportapi.raml##bus_information). A bus sensor is added in the following `configuration.yaml` file entry:
```yaml
# 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.
```yaml
# Example configuration.yaml entry for a template sensor to access the attributes of the next departing bus.
- platform: template
sensors:
next_bus_route:
friendly_name: 'Next bus route'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].route}}'{% endraw %}
next_bus_direction:
friendly_name: 'Next bus direction'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].direction}}'{% endraw %}
next_bus_scheduled:
friendly_name: 'Next bus scheduled'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].scheduled}}'{% endraw %}
next_bus_estimated:
friendly_name: 'Next bus estimated'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].estimated}}'{% endraw %}
```
Powered by [transportAPI](http://www.transportapi.com/)