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

Hi

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 config_flow.py 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?