UK Transport component

fixed it… no idea how but thank you!

This might help you find a destination.

1 Like

where should I add this to see my timetable? :hear_no_evil:

that depends on how you’re configuring lovelace. I do it manually, so it goes in ui-lovelace.yaml.

You need to install flex-table-card - the instructions for the are in the link from my previous post.

If you’re configuring using the GUI it’s still possible, but I’ve never done it so I can’t help.

1 Like

Has anybody found a good source to pickup the info on how long a train should take to the destination? While in theory this info should be in the api it does not appear to be imstatiatef in the upstream python library. So looking to use another source to add this info…

I moved my home assistant from a pi to ubuntu and now all my buses are over an hour away, somewhere 60 mins is being added to the departures but I have changed no settings from those I had before. The time on the ubuntu machine is correct so I cannot see why this is happening.

Any ideas please?

This is an issue I am experiencing also, certainly this line needs fixing

UPDATE: this is a system wide issue https://github.com/home-assistant/home-assistant/issues/19082

Is there a way to create an automation based on the status of a specific train time in either YAML or NodeRed? Seems like it should be possible to find a specific time within the JSON object and its associated status.

Hey all,
this is a really useful but im stuck!
im trying to work out how i pull the data for the next train, PLUS the following 2 after that?

do i need to create another template?
i assume the [0] is “next” then [1] would be the following?
however how do i grab that out correctly.

im looking to create something similar to this: https://github.com/renemarc/home-assistant-config/blob/master/www/screenshots/group-transit.png

- platform: template
  sensors:
    next_train_status:
      friendly_name: 'Next train status'
      value_template: '{{states.sensor.next_train_to_wat.attributes.next_trains[0].status}}'
    next_trains_origin:
      friendly_name: 'Next train origin'
      value_template: '{{states.sensor.next_train_to_wat.attributes.next_trains[0].origin_name}}'
    next_trains_estimated:
      friendly_name: 'Next train estimated'
      value_template: '{{states.sensor.next_train_to_wat.attributes.next_trains[0].estimated}}'
    next_trains_scheduled:
      friendly_name: 'Next train scheduled'
      value_template: '{{states.sensor.next_train_to_wat.attributes.next_trains[0].scheduled}}'
    next_trains_platform:
      friendly_name: 'Next train platform'
      value_template: '{{states.sensor.next_train_to_wat.attributes.next_trains[0].platform}}'

sorry, worked it out!
i had the wrong train station code and so thats why i thought it was all broken.
i went with

  next_train_status:
    friendly_name: '1st train status'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].status}}'
  next_trains_origin:
    friendly_name: '1st train origin'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].origin_name}}'
  next_trains_estimated:
    friendly_name: '1st train estimated'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].estimated}}'
  next_trains_scheduled:
    friendly_name: '1st train scheduled'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].scheduled}}'
  next_trains_platform:
    friendly_name: '1st train platform'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].platform}}'
  next_trains_destination:
    friendly_name: '1st train destination'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].destination_name}}'
  next_trains_operator:
    friendly_name: '1st train operator'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[0].operator_name}}'

  next_train_status2:
    friendly_name: '2nd train status'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].status}}'
  next_trains_origin2:
    friendly_name: '2nd train origin'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].origin_name}}'
  next_trains_estimated2:
    friendly_name: '2nd train estimated'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].estimated}}'
  next_trains_scheduled2:
    friendly_name: '2nd train scheduled'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].scheduled}}'
  next_trains_platform2:
    friendly_name: '2nd train platform'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].platform}}'
  next_trains_destination2:
    friendly_name: '2nd train destination'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].destination_name}}'
  next_trains_operator2:
    friendly_name: '2nd train operator'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[1].operator_name}}'

  next_train_status3:
    friendly_name: '3rd train status'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].status}}'
  next_trains_origin3:
    friendly_name: '3rd train origin'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].origin_name}}'
  next_trains_estimated3:
    friendly_name: '3rd train estimated'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].estimated}}'
  next_trains_scheduled3:
    friendly_name: '3rd train scheduled'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].scheduled}}'
  next_trains_platform3:
    friendly_name: '3rd train platform'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].platform}}'
  next_trains_destination3:
    friendly_name: '3rd train destination'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].destination_name}}'
  next_trains_operator3:
    friendly_name: '3rd train operator'
    value_template: '{{states.sensor.next_train_to_btn.attributes.next_trains[2].operator_name}}'

edited again, i went with the suggestion of the table card here: GitHub - custom-cards/flex-table-card: Highly Flexible Lovelace Card - arbitrary contents/columns/rows, regex matched, perfect to show appdaemon created content and anything breaking out of the entity_id + attributes concept

UI card:

columns:

  • align: center
    attr_as_list: next_trains
    modify: x.status
    name: status
  • align: center
    attr_as_list: next_trains
    modify: x.scheduled
    name: scheduled
  • align: center
    attr_as_list: next_trains
    modify: x.estimated
    name: estimated
  • align: center
    attr_as_list: next_trains
    modify: x.platform
    name: platform
  • align: center
    attr_as_list: next_trains
    modify: x.destination_name
    name: destination
    entities:
    exclude: null
    include: sensor.next_train_to_hov
    max_rows: 10
    title: xxxto Hove Trains
    type: ‘custom:flex-table-card’

then i added 3 main checks, plus an automation to only run during the day, once every 30min, so as to not hammer the API too much

#UK Transport - Home Assistant

added automation to only call the API during the day and every 15min

#Worthing = WRH

  • platform: uk_transport
    app_id: !secret TransportID
    app_key: !secret TransportAPI
    queries:

    • mode: train
      origin: xxx
      destination: BTN
  • platform: uk_transport
    app_id: !secret TransportID
    app_key: !secret TransportAPI
    queries:

    • mode: train
      origin: xxx
      destination: HOV
  • platform: uk_transport
    app_id: !secret TransportID
    app_key: !secret TransportAPI
    queries:

    • mode: train
      origin: xxx
      destination: VIC

automation example (i have 3)

  • id: update_hov_train_times
    alias: “Update Hov Train Times every 15min in the day”
    initial_state: ‘on’
    trigger:
    • platform: time_pattern
      minutes: ‘/15’
      condition:
    • condition: time
      after: ‘06:00:00’
      before: ‘21:00:00’
      action:
    • service: homeassistant.update_entity
      entity_id: sensor.next_train_to_hov

3 Likes

Figured this out. Created a template sensor to base my automation on:

- platform: template
  sensors:
    ben_morning_train:
      friendly_name: 'Morning Train'
      value_template: '{% for x in range(5) %}
	{% if states.sensor.next_train_to_rdg.attributes.next_trains[x].scheduled == "06:49" %}
		{% set minutes_difference = (as_timestamp("1900-01-01 " + states.sensor.next_train_to_rdg.attributes.next_trains[x].estimated) - as_timestamp("1900-01-01 " + states.sensor.next_train_to_rdg.attributes.next_trains[x].scheduled)) / 60  %}
		{% if (minutes_difference) >= 5 %}
			Late
		{% else %}
			On time
		{% endif %}
    {% endif %}
{% endfor %}'

Looks for a specific train (the one scheduled for 6:49 in this case) and if it is 5 minutes or more late it shows ‘Late’, otherwise ‘On Time’. Plan is to create an automation to send an notification to me if the status changes to ‘Late’.

I guess this is still an issue? Using Hassio and everything is correct in my timetables, data etc. except when using the main sensor sensor.next_train_to_man which seems to add an hour on to the actual next stop.

@nwetp are you referring to this issue? If yes, its still open

Sorry if this got asked before (i did search), but is there anyway to schedule the component polling to maximise the 1000 API hits to active time of day?
e.g. 6am to 8pm. it would give nearly double the resolution for active working day. or twice the number of sensors.

Ah. I found the info lurking at the bottom of the component page:

Managing API requests

If you wish to manage the rate of API requests (e.g., to disable requests when you aren’t interested in travel, so that you can request updates more frequently when you do travel) set a really long scan_interval in the config options, and use the service homeassistant.update_entity to request the update of an entity, rather than waiting for the next scheduled update.

It would be helpful if this info was in the warning section at the top of the same page.

1 Like

I’m glad I was able to find this issue listed; it’s been bothering me for days. I thought it was the way I’d set the component up.

Thanks; couldn’t believe it would still be open for so long.

Until the issue is resolved, I’ve created a new sensor with the 60 minute offset:

  - platform: template
    sensors:
      next_bus_offset:
        value_template: '{{states.sensor.next_bus.state | int - 60}}'
        friendly_name: 'Next bus (Offset)'

This code does not work for me. After a long time debugging…you cannot do as_timestamp on a date in the year 1900…it causes “Unknown error rendering template”. Changing it to even 1902 fixed it.

Also the line {% for x in range(5) } causes errors. What if there aren’t 5 more services? Rather do

{% for x in range(states.sensor.next_train_to_xxx.attributes.next_trains|length) %}