UK Transport component

Pretty much the same I think

{
  "atcocode": "6200201000",
  "smscode": "36235785",
  "request_time": "2019-02-25T11:44:33+00:00",
  "name": "Castle Avenue",
  "stop_name": "Castle Avenue",
  "bearing": "S",
  "indicator": "opp",
  "locality": "Corstorphine, Edinburgh",
  "location": {
    "type": "Point",
    "coordinates": [
      -3.27998,
      55.93789
    ]
  },
  "departures": {
    "1": [
      {
        "mode": "bus",
        "line": "1",
        "line_name": "1",
        "direction": "Easter Road",
        "operator": "LOB",
        "date": null,
        "expected_departure_date": "2019-02-25",
        "aimed_departure_time": null,
        "expected_departure_time": "11:47",
        "best_departure_estimate": "11:47",
        "source": "NextBuses",
        "dir": "outbound",
        "id": "https://transportapi.com/v3/uk/bus/route/LOB/1/outbound/6200201000///timetable.json?app_id=<myappid>&app_key=<myappkey>",
        "operator_name": "Lothian Buses"
      },
      {
        "mode": "bus",
        "line": "1",
        "line_name": "1",
        "direction": "Easter Road",
        "operator": "LOB",
        "date": null,
        "expected_departure_date": "2019-02-25",
        "aimed_departure_time": null,
        "expected_departure_time": "12:01",
        "best_departure_estimate": "12:01",
        "source": "NextBuses",
        "dir": "outbound",
        "id": "https://transportapi.com/v3/uk/bus/route/LOB/1/outbound/6200201000///timetable.json?app_id=<myappid>&app_key=<myappkey>",
        "operator_name": "Lothian Buses"
      },
      {
        "mode": "bus",
        "line": "1",
        "line_name": "1",
        "direction": "Easter Road",
        "operator": "LOB",
        "date": null,
        "expected_departure_date": "2019-02-25",
        "aimed_departure_time": null,
        "expected_departure_time": "12:16",
        "best_departure_estimate": "12:16",
        "source": "NextBuses",
        "dir": "outbound",
        "id": "https://transportapi.com/v3/uk/bus/route/LOB/1/outbound/6200201000///timetable.json?app_id=<myappid>&app_key=<myappkey>",
        "operator_name": "Lothian Buses"
      }
    ]
  },
  "source": "NextBuses"
}

Under Developer tools <> does your sensor “sensor.next_bus_to_easter_road” have any data in it ?

just not the next_buses it seems

Try removing the quotes from around Easter Road -

- platform: uk_transport
  app_id: <my_app_id>
  app_key: <my_app_key>
  queries:
    - mode: bus
      origin: 6200201000
      destination:  Easter Road

No change I am afraid.
If I goto the dev tools templates and put in

{{states.sensor.next_bus_to_easter_road.attributes}}

I get

{‘atcocode’: ‘6200201000’, ‘locality’: ‘Corstorphine, Edinburgh’, ‘stop_name’: ‘Castle Avenue’, ‘request_time’: ‘2019-02-25T12:18:53+00:00’, ‘next_buses’: [], ‘unit_of_measurement’: ‘min’, ‘friendly_name’: ‘Next bus to Easter Road’, ‘icon’: ‘mdi:bus’}

Even when I go to the transportapi website and use their test tool it does not populate the next buses field. Seems to me its a transportapi issue wouldnt you agree?

You may want to get a new API key once you have this fixed as you have pasted it higher up this thread. Just using your key now to see what details it pulls but TBH this is new to me as well but I will try and help (work permitting)

Using your API I don’t see any data for Easter Road - is the next bus for this stop due before 13:19 as the API is only pulling data up to that time, you may need to wait longer for Easter Road to come up. You could try “Saughton Tram Stop” as a test in your config and see if that data is pulled ?

Under Templates (4th option under developer tools from the left) do you get any data for your sensor ?

{{states.sensor.next_bus_to_easter_road.attributes.next_buses[0].route}}

Here is my train sensor pulling in the latest train data

I reckon you should have some data now as your API is pulling in Easter Road

atcocode “6200201000”
smscode “36235785”
request_time “2019-02-25T13:09:26+00:00”
name “Castle Avenue”
stop_name “Castle Avenue”
bearing “S”
indicator “opp”
locality “Corstorphine, Edinburgh”
location
type “Point”
coordinates
0 -3.27998
1 55.93789
departures
1
0
mode “bus”
line “1”
line_name “1”
direction “Easter Road”
operator “LOB”
date
expected_departure_date “2019-02-25”
aimed_departure_time
expected_departure_time “13:16”
best_departure_estimate “13:16”
source “NextBuses”
dir “outbound”
id https://transportapi.com/v3/uk/bus/route/LOB/1/outbound/6200201000///timetable.json?app_id=&app_key=
operator_name “Lothian Buses”

So this

{{states.sensor.next_bus_to_easter_road.attributes.next_buses[0].route}}

results in
Error rendering template: UndefinedError: list object has no element 0

and this

{{states.sensor.next_bus_to_easter_road.attributes}}

results in
{‘atcocode’: ‘6200201000’, ‘locality’: ‘Corstorphine, Edinburgh’, ‘stop_name’: ‘Castle Avenue’, ‘request_time’: ‘2019-02-25T13:32:20+00:00’, ‘next_buses’: [], ‘unit_of_measurement’: ‘min’, ‘friendly_name’: ‘Next bus to Easter Road’, ‘icon’: ‘mdi:bus’}

as the next_buses object is empty I cannot request any properties of it. It really does seem to me to be a problem with the transportapi

And your atcode is 100% correct ? “6200201000” - I see that is for Castle Avenue so I guess that is correct.

Will need someone with more knowledge to help on this I’m afraid. Sorry.

I can only assume its correct otherwise it wouldn’t be returning anything I would guess.

Thanks for all your help

Hello world, I’m brand new to HA and attempting to setup this bus timer.

I’ve added the following to my configuration.yaml but I’m not seeing a new sensor in < > States section of developer tools.

I’m also getting this error in my dev info…
45

Have I miss understood the instructions? This is all very new to me. I’d really appreciate any help getting this working - or likewise some links to further reading to help understanding adding senors to HA.

Thanks,

Did you intentionally omit your api_key?

1 Like

yes - I did remove the api bits from the screengrab

Maybe some whitespace? Yaml is tricky to debug

I think the line Sensors on line 45 is not indented enough.

But I would suggest you remove the whole template until you get the basic sensor working. Once that is going you can add the template for more details

I seem to have sorted that. I’m now getting this error.

What’s the best way to test if the sensor is working correctly?

bit of progress :smile:

08

EDIT: is there any way to add a timer for all the buses from that particular stop? ie the 63 final destination is King’s Cross and the 363 is usually Elephant & Castle.

How can I list the buses departing from my stop 490007032N in one card? Apologies if that’s been covered already

1 Like

You can have more than one sensor, each checking different destinations.

But as the current way the component is written you can only check a bus/train going leaving a stop to a single destination. I wish it could check all buses/trains leaving a stop/station regardless of destination.

I only seem to get one bus per card - should it be showing more than that?

Any tips for finding the correct destination of a bus via /uk/train/station/{station_code}/live.json

The 63 always terminates at King’s Cross but the 363 which also runs from the same stop has varying destinations. I’ve not been able to get the timer working. Origin: 490007032N

Also - what’s the best way to display a time table of buses from an origin in a HA card

Not sure I can answer the rest of your questions but here’s how I display a bus timetable.

  - type: custom:flex-table-card
    sort_by: sort
    max_rows: 6
    entities:
      include: sensor.next_bus_to_leeds
    columns:
      - name: Time
        attr_as_list: next_buses
        modify: x.scheduled
      - name: Est
        attr_as_list: next_buses
        modify: x.estimated
        id: sort
      - name: Route
        attr_as_list: next_buses
        modify: x.route
        align: center
      - name: Destination
        attr_as_list: next_buses
        modify: x.direction

I just have Leeds in the destination of my sensor, maybe it acts as a wild card

3 Likes