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
-
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
-
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?
Hiya - this is exactly the card Iām looking for! Really lovely design, would you mind posting the YAML please?
Iām trying to make links to the national rail live train details page, which uses a url param āsidā. For example, here is a train from Gatwick to Brighton https://www.nationalrail.co.uk/live-trains/details/?sid=202410117150533&type=departures&targetCrs=BTN&filterCrs=GTW
Do you have any idea how to get that āsidā?
I was also curious about this, so Iāve done some trial and error and think Iāve worked it out.
The first part of the āsidā is year month date (with no spaces), in your example ā20241011ā.
The next part of the āsidā uses the service uid, but with a twist. This uid is in the form of a letter (A-Z), followed by 5 digits. Itās a key, value
pair for each train service within the next_trains
attribute of each sensor created by the integration. So for the first service in the sensorās list, you would access it in a template via:
state_attr('sensor.your_sensor_object_id', 'next_trains')[0]['service_uid']
The twist is that for the sid, the letter appears to be replaced by a 2 digit number, where A=65, through to Z=80. So for your example, Iām deducing that the service uid was G50533
.
By converting the letter to the two-digit number, you should be able to deduce the āsidā and then build the entire url.
Iāve written a custom macro that generates a list of urlās for a given Real Time Trains sensor, and the results it produces do seem to work so far. I guess my next project is working out how to turn this into something that could be clicked through to from a dashboard!
Oh, and welcome to the community by the way.
Thanks for the tips. However, I couldnāt find next_trains
and service_uid
in my sensor state attributes. Are we talking about the same integration?