London tube status component

Please create an issue on Github

Hi @robmarkcole

Thanks for this component.

Is it possible if we could have updates on other trains in the UK like the London Midland??

Sure, checkout

So I have set up the UK transport component and everything is working well.

However when I put “LM” (London Midland) as the “operator” in the configurable variable, the component stops working.

I want to set London Midland as the operator and know the train status at a specified time. Is that possible ? If yes can you please guide me on how to do it?

At the moment this is what I have:

  - platform: uk_transport
    app_id: ******
    app_key: ********
    queries:
      - mode: train
        origin: HRW
        destination: EUS

Hi what do you mean by ‘when I put “LM” (London Midland) as the “operator” in the configurable variable, the component stops working’.?
How did you get on with the troubleshooting suggested in the docs? Cheers

So when I go to the api reference Web page to see if everything is working: from my origin station to my destination station I want to select a specific train service which i.e. not all trains like overground, underground etc.

When I specify the operator meaning the train type i.e. London midland in my case on HA it throws an error which means it’s not a query like destination station, origin station etc.

Is it possible to be more specific in HA showing only certain trains at specific departure times?

Ideally I want to use an automation to give me an update first thing in the morning regarding my 08.04 train to London Euston without me having to open HA frontend.

Assuming that is the only 8:04 train then I would advise creating a template sensor on the planned departure time which is an attribute.
Operator is also an attribute so you could add that as a filter.
I’m out fishing at the moment so can’t be more specific til I try myself at home.

Hi guys, would you be able to help me with the syntax to reference the description field from these tube line sensors? So far my automation creates a pushover notification with both the title and message showing the sesnsor status i.e. “good service” or “minor delays”, what I’d like is to be able to include the sensor description in the message body.

My automation looks like this:

> - id: '1543353858266'
>   alias: TFL (Hammersmith & City)
>   trigger:
>   - entity_id: sensor.hammersmith__city
>     from: Good Service
>     platform: state
>     to: '*'
>   condition: []
>   action:
>   - data:
>       data:
>         priority: 0
>         sound: bike
>       message: 'Hammersmith & City Line: {{ states(''sensor.hammersmith__city'') }}'
>       title: 'Hammersmith & City Line: {{ states(''sensor.hammersmith__city'') }}'
>     service: notify.notify
- id: '1543353858266'
  alias: TFL (Hammersmith & City)
  trigger:
    platform: state
    entity_id: sensor.hammersmith__city
  action:
    service: notify.notify
    data_template:
      priority: 0
      sound: bike
      message: "{{ states('sensor.hammersmith__city') }}" 
      title: "Hammersmith & City Line" 

Thanks @anon43302295 sadly that doesn’t work, I get the error

Invalid service data for notify.notify: extra keys not allowed @ data[‘priority’]. Got ‘0’
extra keys not allowed @ data[‘sound’]. Got ‘bike’

Also by using message: “{{ states(‘sensor.hammersmith__city’) }}” wouldn’t I just end up with the sensor state i.e. “good service” which is what I already get with my automation. I was assuming I would need to use state.attributes.description somehow but was unable to work out the syntax.

Apologies for two things, first I misread what you wanted to do, and second I don’t use pushover so I don’t know where the keys sit for priority and sound - try this…

  action:
    service: notify.notify
    priority: 0
    sound: bike
    data_template:
      title: "Hammersmith & City Line: {{ states('sensor.hammersmith__city') }}"
      message: "{{ state_attr('sensor.hammersmith__city' , 'NAME_OF_ATTRIBUTE') }}"

Obviously replacing the capitals appropriately :slight_smile:

Perfect, thanks @anon43302295, a little tweaking led me to this which works perfectly:

- id: '1543353858266'
  alias: TFL (Hammersmith & City)
  trigger:
  - entity_id: sensor.hammersmith__city
    from: Good Service
    platform: state
    to: '*'
  condition: []
  action:
  - data:
      data:
        priority: 0
        sound: bike
      message: '{{ state_attr(''sensor.hammersmith__city'' , ''Description'') }}'
      title: 'Hammersmith & City Line: {{ states(''sensor.hammersmith__city'') }}'
    service: notify.notify
1 Like

I know this was mentioned at the start but it kinda got dropped, but Is there any chance or plan of adding tube station train arrival times? I’ve used the awesome UK Transport component but that uses transportapi which doesn’t look like it properly supports the tube anymore so I cant see this being integrated into that. Theres the tfl api which this component uses and I know how to use it to fetch a list of upcoming trains at a specific station and how many seconds they are away and stuff but it’s just frustrating that I don’t know how to integrate it as my own component or something since I’m new totally new to json yaml and HA itself.

Like for example this returns a json object(?) of upcoming trains going southbound from Bermondsey station, with how long until each of the trains arrive.
https://api.tfl.gov.uk/line/jubilee/arrivals/940GZZLUBMY?direction=inbound

jubilee is the train line, the 940… id is the station id, and the optional direction is pretty much which platform or direction you want to see trains heading to.

I guess to integrate it as a “time until next train” badge or whatever in HA I’d have to select the train in the array with the lowest amount of seconds until arrival and then grab the time in seconds and the destination of the train and then display that info. Ideally the seconds would be divided by 60 to get a number in minutes instead of seconds too.

Hi Rob,

I’ve added your london_underground component. Works well. I’ve got a great idea for an automation. Using the ‘workday’ integration and the time sensor I could theoretically automate a notification of the status of my home tube line as I have breakfast every working day morning. I happen to have a custom integration that can pass text to speech notifications to an alexa, so I could have alexa tell me. Any idea how to pass the tube status detail from your custom component to another service call?

It is just a sensor attribute so break it out with a template sensor

Of course! Thanks. Got that working, but it only pulls back the top line info e.g. Good service. Do you know how I can access the description text that goes with it?

Good service is the description, this will change at some point :slight_smile:

Ha, undoubtedly! There is a second part to the service description though. When it’s stating good service, there is another text field of “nothing to report”. If the main description changes to e.g, “severe delays” that additional text changes to a more detailed description of the reason for the service status such as “bellend under a train because his hedge fund tanked” or something like that, so it’s a two part description. Calling the state of the sensor only gets me the first part.

Whats the config for your template sensor? You need to be accessing the Description attribute

Ah, great, thanks.i was just using the output straight from the line sensor instead of templating it to grab the description part. Don’t suppose you know a good way to string these two outputs into one instead of having to have two separate entity lines? Would be great to have a single template sensor that could output e.g. “Good service. Nothing to report” or “severe delays. Signal failure blah blah…”