NEW UK bus & train component: Beta testers required

Thanks @robmarkcole I see what you mean now I have read a bit more, so I should be OK without the window checking - although that would be nice to add at some point so its not pointlessly spamming the TransportAPI severs! I really couldn’t follow what needs doing, but its something I will look into again when I have more time - I really do want to learn abit more about all this, so will be a good project :slight_smile:

Must also thank you for your traffic light alerts (https://www.hackster.io/robin-cole/traffic-light-alerts-for-my-morning-train-350a27) as I (seem) to have that all working now (will find out for certain tomorrow!) - I’m using it with my Blinkt! strip on the HASS Pi.

Had to make a couple of tweaks to add EARLY as a state as well (yes, believe it or not, my test train was actually reporting early!), and am thinking how I can added a couple of other features (both morning and evening commute, and also if it can flip over to the next available service after the TOI time has passed, if it was cancelled).

I’ll let you know if I have any success! :smiley:

HI @andrewdolphin the SCAN_INTERVAL is calculated from the total number of sensors including bus and train, see the component file. SCAN_INTERVAL (seconds) = 87*number_sensors

You can use the transport API developer tools to check your usage.

You are also correct that destination is a filter is applied to the return of the API, again see the component file.

HI @davefi glad to hear you are finding this complement useful. Python scripts are a nice way to dip your toe into developing HA components. Developing for HA is enjoyable and satisfying so I recommend it. I am not a professional developer and am self-taught so is is possible with persistence.

With regard to adding functionality, there is a balance between adding new features and adding more ways for people to accidentally break the component :slight_smile:

1 Like

So how do you know where each bus is heading?

I guess it all depends on use case. Where i live every bus that goes through my nearest bus stop goes into the town centre and then to various destinations the other side of town so I’m interested in all buses.

Edit: also the destination is still available in the attributes I thInk.

This looks pretty amazing - will have a go and use it with the Manchester buses next weekend

I’m trying to make this look neater but I am at a loss at how I could do it. As you can see when multiple buses go from the same stop, it orders them on bus number and not time. Any idea how I can get it to be ordered on time of the next bus please?

I have this in the config

      - mode: bus
        origin: xxxx
        destination: xxx
  - platform: template
    sensors:
      next_bus_start:
        friendly_name: 'Bus Start'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.locality}}{{states.sensor.next_bus_to_xxx.attributes.stop_name}}'
      next_bus_direction:
        friendly_name: 'Next bus direction'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[0].direction}}'
      next_bus_route:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[0].route}}'
      next_bus_scheduled:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[0].scheduled}}'
      next_bus_route1:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[1].route}}'
      next_bus_scheduled1:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[1].scheduled}}'
      next_bus_route2:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[2].route}}'
      next_bus_scheduled2:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[2].scheduled}}'  
      next_bus_route3:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[3].route}}'
      next_bus_scheduled3:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[3].scheduled}}'  
      next_bus_route4:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[4].route}}'
      next_bus_scheduled4:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[4].scheduled}}'  
      next_bus_route5:
        friendly_name: 'Bus Number'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[5].route}}'
      next_bus_scheduled5:
        friendly_name: 'Next bus scheduled'
        value_template: '{{states.sensor.next_bus_to_xxx.attributes.next_buses[5].scheduled}}' 

output is

sensor.next_bus_direction	Bus Station Stand 1
sensor.next_bus_route	28
sensor.next_bus_route1	28
sensor.next_bus_route2	29
sensor.next_bus_route3	29
sensor.next_bus_route4	29
sensor.next_bus_route5	28A
sensor.next_bus_scheduled	07:43
sensor.next_bus_scheduled1	08:46
sensor.next_bus_scheduled2	07:56
sensor.next_bus_scheduled3	08:26
sensor.next_bus_scheduled4	09:03
sensor.next_bus_scheduled5	08:11 

Thanks
Mark

I avoid getting deep into yaml, so recommend a python script. You could modify my approach on hackster.
Cheers

well this is blowing my mind…i might have to leave it unsorted :slight_smile: you wouldn’t think I got a degree in software engineering 20 years ago :frowning:

Followed the instructions - sadly my bus route isn’t listed!
I get the error message in the API reference

Traveline timetable (not a nextbuses live region)

Any ideas/suggestions?

Perhaps:
https://data.gov.uk/dataset/nextbuses-api

or
http://nextbuses.mobi/

?

this works perfectly for me now but I wanted to make it show in the tablet you are using via a custom card.
I copied your example for trains and couldn’t get it to work… am I missing a huge piece of the puzzle please?

Hi Mark
also seeing that, hadn’t checked it in a while, would have to look into in.

ahh glad it isn’t just me thanks!

Hello. Did you manage to look into this please?

Hi @MarkR haven’t looked yet, perhaps time over Xmas. Frontend stuff isn’t my forte sadly!

This add on looks very useful. Would there be a way to just look for a specific train. E.g I get the 8.15 everyday and only really want to know whether that one.is running on time.
Thanks

Yes see https://www.hackster.io/robin-cole/traffic-light-alerts-for-my-morning-train-350a27

1 Like

Amazing, thankyou!

How do you set the scan interval for a specific time, like you metnioned? Ie. weekdays between 7-9am?