Help with the UK transport component

Hi,

I am trying to use the UK transport component but getting no luck. My current configuration is

  - platform: uk_transport
    app_id: !secret UKtransport_id
    app_key: !secret UKtransport_key
    scan_interval: 300
    queries:
      - mode: bus
        origin: !secret UKtransport_east_stop
        destination: "Bus Station"

Using the app and key I am able to use the online api to check that everything is working. This returns everything as expected.

But in HA I get the attributes in the sensor:

unit_of_measurement: min
next_buses: 
icon: mdi:bus
request_time: 2019-03-17T18:55:31+00:00
locality: XXXXXXXXX
stop_name: XXXXXXXXXX
atcocode: XXXXXXXXXXX
friendly_name: Next bus to Bus Station

redacted for privacy.

But the state remains as Unknown.

I have tried a number of different destinations, but can’t get it to work. I know all the other data works as that is needed for the online api check. I have read the python script for the component, and understand what it is doing, but frankly my python isn’t good enough to debug it.

Any help would be great.

Here’s my working config

  - platform: uk_transport
    app_id: ********
    app_key: ************************************
    queries:
      - mode: bus
        origin: 123456789
        destination: Leeds

So you could try without the quotes around Bus Station.

EEEEK! now you know I live somewhere in near Leeds, that narrows it down to about 2.2million people in West Yorkshire. :wink:

Thanks for that, still doesn’t work. My formatting seems to match yours.

I am wondering if it is something to do with the destination having a space in it, which is why I tried the quotes.

What I would really want is to make the destination an optional input, or allow it to take wildcards. Looking on the api the destinations are not consistently named (at least for the routes around me), so using a fixed destination will mean missing some busses or running multiple sensors.

Bump, anyone else able to help, or have it working with a space in the destination name?

Ok, so I got it working.

It all relates to the destination field, as I expected.

The direction shown in the API request is name of the final bus stop. That didn’t work for me. Instead what I did was.

  1. Did the API request as explained in the documentation
  2. Found the line “id”, which returns a url for that route based on the API request
  3. Navigated to that url, which is the json of the entire bus route you requested (can be very long)
  4. Scrolled to the bottom to find the terminating bus stop
  5. In the last bus stop found the field “locality” and used that as my Destination in my configuration.ymal

I have tried using the locality for stops before the last stop, but that doesn’t seem to work (based on how the component is currently written).

Hope this helps people in the future, I hope the docs get updated to reflect this and longer term someone who is good enough at python changes the component to be a little more flexible (as the API doesn’t need destination/direct, why does the component mandate it?).

2 Likes

brilliant - thank you Targettio

Does anyone else’s component look like this? Looks a bit odd…!?

04

Good Morning @Targettio I have exactly the same problem I think. The API call works and I have tried to pull the locality from the last entry as you did in step 5. but i still get the message

WARNING (SyncWorker_18) [homeassistant.components.uk_transport.sensor] Invalid response from API
 WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus estimated, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus route, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus scheduled, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus direction, the state is unknown.

this is my config.yaml (well sensor.yaml)

- platform: uk_transport
  app_id: 1234567890
  app_key: 1234567890
  queries:
    - mode: bus
      origin: 017000062
      destination: Bristol

and this is the output from the api call

{
time: "10:17",
date: "2019-11-28",
atcocode: "0100BRP90373",
name: "The Centre (C1)",
stop_name: "The Centre",
smscode: "bstgajm",
locality: "Bristol City Centre, Bristol",
bearing: "S",
indicator: "C1",
latitude: 51.45381,
longitude: -2.59696
}

I am tenatious so i want to get it to work, it worked previously until i moved house! I am considering using a scrape of the web page, but it really shouldn’t be that difficult should it.
any help greatly received.

I just want to thank everyone who has contributed to this thread. This is the first Home Assistant Automation that I’ve got to work on the start of the journey. It was really satisfying. I was getting frustrated last night as nothing was showing… I then came back this morning, and of course everything had populated… I guess as I was doing it at stupid o clock and there weren’t any immediate trains. Still got to get buses to work, but trains feels like a victory.

One query… the “… mins till next train” countdown… using the free API, I can’t set my refresh rate high, as I am trying to get a few different sensors working all at once… I am wondering if it is possible to have the countdown calculated by the difference between the system clock and the live updated time, as I am guessing at the moment, it only calculates on refreshing the update from the API?