UK Transport component

You are trying to check x.estimated against a string, whereas its likely set to null and undefined is what is rendered in that situation. So instead try:

‘if (x.estimated) { “Cancelled” } else { x.estimated }’

doing that makes the whole Est column “Cancelled”, hmmm… would it be easier to have:

‘if (x.estimated =/= ‘00:00’ {“Cancelled”} else {x.estimated}’

?

Sorry flip the order:

if (x.estimated) { x.estimated } else { “Cancelled” }

Ah! Simples, why didn’t I think of that.

Ok, will test it on a couple of cancelled trains/lines and see how we go.

Thanks

I wonder why the transportapi doesnt return number of coaches?
My train home is often shortformed so it would be great to be able to get an alert when it has e.g. 2 carriages instead of the normal 4.
You can see the number of coaches returned in XML using this service, but its beyond my ability to extract it I think:

http://iris2.rail.co.uk/tiger/#support

I wonder if anyone might be able to help. In order for me to use the UK transport API I have to append “&source_config=dws_staff” to force the api to use a different source for the data as normal data is not available for the Tyne and Wear Metro. Is there any way I can add this tag into the home assistant component?

Anyone else experience the Christmas edge case where flex-table-card has an error and stops the whole page (any other cards on the page) from loading ? Basically happens when no trains are running!

“No card type found”

Same here…

For some other poor lost soul trying to understand the stupid complexities of Lovelace formatting, this works if you paste it in a “manual card”:

type: conditional
conditions:
  - entity: sensor.next_train_to_lbg
    state_not: No departures
card:
  type: 'custom:flex-table-card'
  title: Trains to London Bridge
  icon: 'mdi:train'
  entities:
    include: sensor.next_train_to_lbg
  columns:
    - name: Time
      attr_as_list: next_trains
      modify: x.scheduled
    - name: Time
      attr_as_list: next_trains
      modify: x.scheduled
    - name: Est
      attr_as_list: next_trains
      modify: x.estimated
    - name: Status
      attr_as_list: next_trains
      prefix: '<style> cc { color: red; } </style>'
      modify: >-
        if (x.status == "LATE") { "<cc>" + x.status + "</cc>" } else { x.status
        }
    - name: Delay
      attr_as_list: next_trains
      modify: >-
        if (x.estimated ) { (parseInt(x.estimated) * 60 +
        parseInt((x.estimated).slice(3,5))) - (parseInt(x.scheduled) * 60 +
        parseInt((x.scheduled).slice(3,5))) } else { " " }
      suffix: m
      align: right

From memory I got around this with: UK Transport component

So basically when no trains are running the Vertical-Stacked-Card renders nothing, but the flex-table-card keeps plodding along - the idea is if the render fails, then only that Card fails to load, rather than your whole tab failing to load

I have read through the thread and there was brief mention of an “arrival time” function but I couldn’t see if anything was done about this.

Has anyone implemented anything like that function?

Anyway I can avoid this? :smiley: thanks

dasdsadsa

I’m pulling my hair out over this :rofl:

Using the below in configuration.yaml the sensor is returning state ‘unknown’.

  - platform: uk_transport
    app_id: MYIDHERE
    app_key: MYKEYHERE
    queries:
      - mode: bus
        origin: 0500SHILD002
        destination: 0500CCITY321

I’ve sent both of the Atco codes to uk/bus/stop/{atcocode}/live.json and they both return info correctly with status 200, but yet HA shows Unknown.

Does anyone have any clue why this doesn’t work?

TIA

1 Like

I could be wrong but I wonder if this is because the object starts with a number.

Awesome thanks for sharing this worked for me also :grinning:

So im just adding this component now but i cannot get any sensor to show up.

This is whats in my config.yaml

sensor:
  - platform: uk_transport
    app_id: 8*****d4
    app_key: bc655fe00dd3**********9266636c34
    scan_interval: 300
    queries:
      - mode: train
        origin: WYB
        destination: WAT

Most integrations ive added i also add something above like below but its not mentioned anywhere.

uk_transport:

Ive restarted HA many times now but when i go to check the states list i dont have any “sensor.next_train” etc Any thoughts? Im not even seeing an error in the log.

Solved.

I solved the “undefinedundefinedundefined” issue when reporting on estimated arrival time. Here is the code.

- name: Est.
   attr_as_list: next_trains
   modify: "x.estimated == null ? 'unk' : x.estimated"

Hi
My bus scheduling sensor has been working perfect for some time. Seems there has been a change to the way the api works and none of the scheme previously usedc works.

Is an update planned or is this an error on my end. Any help would be appreciated.

{
  "atcocode": "035085420001",
  "smscode": "wokdgwd",
  "request_time": "2020-11-09T13:46:21+00:00",
  "name": "Sunderland Close",
  "stop_name": "Sunderland Close",
  "bearing": "NW",
  "indicator": "adj",
  "locality": "Woodley",
  "location": {
    "type": "Point",
    "coordinates": [
      -0.88093,
      51.45657
    ]
  },
  "departures": {
    "13": [
      {
        "mode": "bus",
        "line": "13",
        "line_name": "13",
        "direction": "Reading Station",
        "operator": "",
        "date": "2020-11-09",
        "expected_departure_date": "2020-11-09",
        "aimed_departure_time": "14:15",
        "expected_departure_time": "14:15",
        "best_departure_estimate": "14:15",
        "status": {
          "cancellation": {
            "value": false,
            "reason": null
          }
        },
        "source": "NextBuses",
        "dir": null,
        "operator_name": null,
        "id": null
      },
      {
        "mode": "bus",
        "line": "13",
        "line_name": "13",
        "direction": "Reading Station",
        "operator": "",
        "date": "2020-11-09",
        "expected_departure_date": "2020-11-09",
        "aimed_departure_time": "14:45",
        "expected_departure_time": "14:45",
        "best_departure_estimate": "14:45",
        "status": {
          "cancellation": {
            "value": false,
            "reason": null
          }
        },
        "source": "NextBuses",
        "dir": null,
        "operator_name": null,
        "id": null
      },
      {
        "mode": "bus",
        "line": "13",
        "line_name": "13",
        "direction": "Reading Station",
        "operator": "_noc_RBUS",
        "date": "2020-11-09",
        "expected_departure_date": null,
        "aimed_departure_time": "15:15",
        "expected_departure_time": null,
        "best_departure_estimate": "15:15",
        "status": {
          "cancellation": {
            "value": false,
            "reason": null
          }
        },
        "source": "NextBuses",
        "dir": null,
        "operator_name": null,
        "id": null
      }
    ]
  },
  "source": "NextBuses"
}

I don’t see any announcements about breaking changes on https://developer.transportapi.com/
On the website you can check the bus code info I recall, so check that

Hi
Thanks for the response. See the response above. The generated schema does not work with Hassio anymore.
https://transportapi.com/v3/uk/bus/stop/490012637Y/live.json?app_id=3c89e5f8&app_key=f9fc3aee83d886fd07b0301292e6bce3&group=route&nextbuses=yes