National Rail Integration

There is already a national rail integration in the base installation of home assistant. Truth is, this is not national rail but some company trying to sell subscriptions for their API/system

But national rail offers a soap API but you need to register (with very generous limits) I wrote an integration for home assistant. I look forward to reading your feedback

7 Likes

I’ll give this a go. Thank you.

The other integration was great, until my free trial ran out.

Hi @jfparis

This is really good. Great work.

Can you tell me what the perturbation information is?

P.S. I wish there was a similar free service for busses.

Perturbation means train are not running as they should (cancellation or meaningfully late - I think I arbitrarily set that to 10 minutes)

In which city do you live?

So, is there a way to distinguish between different perturbations.

I live near Oxford.

There is (it only relate to that route the instance is monitoring - you need one instance for your morning route and another one for your evening route) and there isn’t (there is only one flag for cancellation and meaningful delays)

Looks like there is an api for buses. Not sure whether it covers oxford.
https://www.travelinedata.org.uk/traveline-open-data/nextbuses-api/

1 Like

It looks like Oxford buses use the same format as some other cities for their bus data.

You can scrape the live bus times from that.

set up a scrape integration with a resource of say Oxford, Lamarsh Road (adj) - Live Departures for example.

Then configure a sensor with the selector as div[class=“single-visit__content”] and index of 0
Add another sensor of div[class=“single-visit__time”] and index of 0

These should get you two sensors, first one with the bus and the second with the time.

Add more sensors with increasing indexes if you need more.

Add an automation with a time pattern trigger of say 20 seconds to update all the sensors.

Hope this helps…

2 Likes

That’s a great idea. Thank you. I’ll give it a go.

Just want to say thanks for creating and maintaining this. Set it all up about a week ago now and it’s been rock solid and, more importantly, accurate. Love the perturbation inclusion, especially as it’s a whole new word for me :joy:.

Still need to sit and get my dashboard setup, for at a glances updates. Tried and failed to quickly get the html Lovelace card going but that cna be a job for the weekend.

1 Like

The only odd thing about perturbations is that when it is set to true the expected departure time changes from a time to a string that is the reason for the perturbation.

If you can be a bit more specific, I can have a look. Is that the main value of the sensor or something in the template?

I can’t remember what happens with the State (main value) of the sensor. But, based on the jinja I’ve written, I do know that the ‘expected’ property (within the state attributes) is normally a dattime; however, when perturbation is true it can have a string value such as ‘delayed’.

I will keep an eye on this but as far as I can see, the national rail API will either

  • return the forecasted time of the train (and that will factor in the delays) when they know it
  • return delayed when they cannot predict anymore when the train will come
  • “cancel” well…

In your template you can refer to both the “schedule” and the “expected” times (my quick and dirty template displays both for that reason)

Thanks for the update

Great idea and work well so far, this should really replace that commercial add-on in the near future!
The HTML card also works (and offers a lot of customizability), but perhaps something like GitHub - hasl-sensor/lovelace-hasl-departure-card: Lovelace Departure Card for the HASL Platform would be a good starting point for a custom card.

1 Like

Haven’t seen that one before. Looks really good.

I followed the setup and instructions. Worked perfectly. Many thanks for the effort. The html departure boards work for me!

New version of the code is now online fixing a bug when you track multiple destinations.
It changes the attributes of the sensor so automations and display code has to be refreshed. The code for the blueprint has been updated and you will need to reinstall it as well

1 Like

Is this currently broken for anyone or just me? Set it up yesterday and it was working fine this morning.

Seems to have stopped for me too

1 Like