NEW UK bus & train component: Beta testers required

I completed some testing. The sensor works if I put the first and last train on the scheduled route. If I put two intermediate stations on that route it does not work.

Yes the component can only handle a single route (where both stations are on the same line) and makes use of https://developer.transportapi.com/docs?raml=https://transportapi.com/v3/raml/transportapi.raml##request_uk_train_station_station_code_live_json
The actual query is query_url = 'train/station/{}/live.json'.format(station_code) with the parameters params = {'darwin': 'false', 'destination': self._destination_name, 'train_status': 'passenger'}
I suggest that for future debugging we use Github issues, and save this thread for general discussion and updates :slight_smile:

I have pushed a fix and opened an issue: https://github.com/robmarkcole/TrasportAPI-HASS/issues/1

Oh this is good news, thanks for the work. Any way to show the “train after the next one” as well as the next one?

For the next train:

Would change to

{{states.sensor.next_train_to_wat.attributes.next_trains[1].status}}

As next_train is a list of dicts.

Would be nice to add a table of upcoming trains to the front-end - not sure how to do this?

Yep a table of the next 3 or something would be very helpful

Created a feature request for tables on front end Table on front-end

I must be missing something here but i’m getting errors in my log and no updates

2017-06-14 14:51:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Next train platform, the state is unknown.
2017-06-14 14:51:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Next train status, the state is unknown.
2017-06-14 14:51:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Next train estimated, the state is unknown.
2017-06-14 14:51:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Next train origin, the state is unknown.
2017-06-14 14:51:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Next train scheduled, the state is unknown.

@tristophe Whats in your config? Have you pulled the latest commit?

I’ve just checked again and it was a syntax error, completely my fault for not checking the YAML.

All working now.

Thanks for developing!

1 Like

Is it possible to specify an offset, or get the status of more than just the immediately next train?

I live about 20 minutes from my local station, and trains are every 15 minutes, so knowing the next train isn’t helpful, but knowing about the train more than 20 minutes from now, or the next 2 or 3 trains, that’s useful.

yes, see

https://github.com/robmarkcole/TrasportAPI-HASS/blob/master/HASS%20files/sensor.uk_transport.markdown

Ah, I see it now. Thanks.

I’ve pushed a significant change in the latest commit, and hopefully will submit this version to HA. Therefore if you could test this version and give any feedback that would be great :slight_smile: Note that the config entry has changed.

Project complete

2 Likes

This is brilliant and I would love to use it for my wife, as she has to get the bus. Looks like not all towns etc have ATCO codes, as I cannot see any listed on the bus stops in my town. Or is there any other way to find them please?

Cheers
Mark

answered my own question :slight_smile:

you can by running
http://transportapi.com/v3/uk/bus/stops/near.json?lat=xxxxxx&lon=-xxxxx&app_id=xxxxx&app_key=xxxxx

1 Like

Just set this up for myself and all seems to be working - thank you @robmarkcole!

Did you ever implement the additional items you mention above, namely the polling window etc?

1 Like

Hi Dave, busy with other projects but if there is sufficient interest could add to my to do.
Basic approach is to add a service for each sensor which allows to set the SCAN_INTERVAL of that sensor. Automations can be used to set it.
If you want to have a go I’m happy to review pull requests :slight_smile:

2 Likes

Eeek! I’d love to, but wouldn’t have a clue where to start right now!

I will have a play around / read up and see if I can follow what you just said :wink:

My main reason for asking is I want to set up a notification on my return trip as well, and just worried it will hit the request limit before home time.

I am sure I have this setup correctly but getting errors in the logs

2017-10-11 13:45:59 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Next bus direction: UndefinedError: list object has no element 0
2017-10-11 13:47:32 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Next bus route: UndefinedError: list object has no element 0
2017-10-11 13:47:32 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Next bus estimated: UndefinedError: list object has no element 0
2017-10-11 13:47:32 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Next bus scheduled: UndefinedError: list object has no element 0
2017-10-11 13:47:32 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Next bus direction: UndefinedError: list object has no element 0
  - platform: uk_transport
    app_id: x
    app_key: x
    queries:
      - mode: bus
        origin: xxxx
        destination: xxx Bus Station
  - platform: template
    sensors:
      next_bus_route:
        friendly_name: 'Next bus route'
        value_template: '{{states.sensor.next_bus_to_xxxx_bus_station.attributes.next_buses[0].route}}'
      next_bus_direction:
        friendly_name: 'Next bus direction'
        value_template: '{{states.sensor.next_bus_to_xxxx_bus_station.attributes.next_buses[0].direction}}'
      next_bus_scheduled:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxxx_bus_station.attributes.next_buses[0].scheduled}}'
      next_bus_estimated:
        friendly_name: 'Next bus estimated'
        value_template: '{{states.sensor.next_bus_to_xxxx_bus_station.attributes.next_buses[0].estimated}}'

info is pulled out when using “/uk/bus/stop/{atcocode}/live.json”

any ideas please?

Cheers
Mark