National Rail Integration

Thanks, this is really helpful, got it working nicely for me in my dashboard, as a relative newbie to HA!

Very nice. I will add this in the docs when I have a minute. If you want to send a PR this would be even better

I’m new to HA, and finding this integration really useful. I’ve got it setup sensors setup, and have both the HTML (with some edits) and markdown (stock at present) cards working. I am however, struggling to work out one thing, I’m only getting 2 entries (occasionally 3, if a train departure time is imminent) in either card. I’d like to get more entries, and ideally only that number (e.g. 5), how do I go about that? (I’m sure this is a trivial question, so I do apologise, but I’ve scoured the code without success)

Need to dive into this further but it looks like the API I used in the code only returns the trains departing in the next 2 hours or so

My usual trains departs every 30 minutes and I get 4 trains displayed. For your frequency, 2 responses seems OK

Ah, that explains it, thanks. In general 2 hours will be more than sufficient.

Hello, I’m new to HA. I’m having difficulty displaying the train times in the dashboard. I’ve double-checked my token, and the station names (SWK & VIC) are correct. I’ve restarted (and rebooted) the HA server a few times. I’m pretty sure I followed the documentation to the letter.

Any suggestions of where to look to troubleshoot?

Hi @si1

Have you looked in Settings → System → Logs to see if there is anything related? When you set up the integrations, did you use the 3-letter abbreviations?

Hello, thank you for getting back to me. Yes, I used the three-letter station code and double-checked they were correct. SWK & VIC are correct.

The logs only say this:
2024-02-26 18:50:35.620 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration nationalrailuk which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant


2 questions

  1. Do you know how to use the “Developer Tools” ? In the “states” tab seach for “train_schedule”. Can you see some entities with the train schedule? Send a copy-paste

  2. I cannot see a lot of trains between those 2 destinations on the national rail website either for this evening or for tomorrow. This might be explained because there is a change in Hove, isn’t it? I use the departure board API so it would only display SWK to Hove

Cool integration, thanks! Just added as a custom integration in HACS.

When setting up the integration, I initially didn’t enter a value for the destination station and got ‘An unknown error occurred’. Not sure if this could be made more descriptive i.e. ‘Please ensure you have entered both a departing and destination station’.

Thank you for your quick responses!!!
So, there is usually a change at Brighton (BTN) or Hove (HOV) to get to Victoria (VIC). Are you saying the integration can only show direct trains?.. That would explain why I’m not seeing trains in the schedule.

Is there a way to show trains even if there’s a change (or two) to get to the destination?

The integration relies on the “Departure Board” API (it shows the same info you get on the platform). It will only display direct trains.

Would have to change to the Online Journey Planner Data Feeds | National Rail API

There is another intergration on the forum that might be using the API required for your use case. It displays less trains though so I am not planning to change this

Hello jfparis,

Thank you so much for this integration, it works beautifully.

Is it possible to tweak the code to provide an Arrivals board? I’ve taken a look at the GitHub but it’s well beyond my abilities (which are lacking!).

I’m looking to keep abreast of the train times for the route my wife takes home from work?

Many thanks again!

There is an issue with token validation, commented out line 46 in and I was able to successfully add the integration and monitor the train proving that the token is valid.

Thank you, I’ve also added this and it works great! I was wondering if it was possible to obtain the timetable for a custom time range? I normally plan my journeys the day before the actual trip. If not, is this something that could be added?

Is this still in HACS?