National Rail Integration Fork of jfparis

So this is a card update?
Are you looking at stopping at different destinations? Or is your route one start to one end? PM me stations if you dont want to post publically.

If you start and end locations are the same, the card should give you all trains on that route

so yes, that’s the challenge, the destinations could be different. WLW is my starting point, but depending on my train, I change at FPK, KGX or STP. Same for return. There are some express services that are KGX to WLW non-stop, but not many, so more often I get the KGX train stopping at FPK, but sometimes I get a STP train stopping at FPK.

I will have a look and see what I can do. Maybe provide tabs at the top to allow you to switch between multiple destinations all configured via one card? Or maybe showing as one list.

1 Like

Just for context of how I ended up here - I was originally looking to see if I could add something like this to my wall mounted HA Tablet: https://ukdepartureboards.co.uk/store/product/desktop-departures/?srsltid=AfmBOor_41KOJe7RTIXvoE_u1mRKZlhKSgQUnEgXiNex13VCpk-DIhZP

I am also getting this exact same error. Running the latest version (v1.0.1) with a valid key. Tried with Wolverhampton as the departure station and birmingham new street as the destination (Although also tried some random others.

Logger: custom_components.nationalrailuk.config_flow
Source: custom_components/nationalrailuk/config_flow.py:99
integration: National Rail UK (documentation, issues)
First occurred: 18 January 2025 at 21:28:59 (5 occurrences)
Last logged: 13:30:53

Unexpected exception
Traceback (most recent call last):
File “/config/custom_components/nationalrailuk/config_flow.py”, line 99, in async_step_user
info = await validate_input(self.hass, user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/nationalrailuk/config_flow.py”, line 51, in validate_input
res = await my_api.async_get_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/nationalrailuk/client.py”, line 373, in async_get_data
raw_data = await self.get_raw_arrivals_departures()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/config/custom_components/nationalrailuk/client.py”, line 127, in get_raw_arrivals_departures
res[each][ft[“keyName”]] = batch[“trainServices”][“service”]

TypeError: ‘NoneType’ object is not subscriptable

I have just set up Wolverhampton → Birmingham new street. without issues. Can you confirm you still get issues?

I have updated the card to allow you to switch between the multiple destinations supplied by a single entity. I plan to update it further to allow multiple entities on one card

image

1 Like

@plutomedia987 Really impressive integration and card. Thank you!

1 Like

Hi, sorry, missed this notification! Yes it has since worked a couple of days later. Didn’t change anything so assume something was down somewhere when I originally tried.

This is a great integration and it’s working really well for me but I have started seeing a problem in the logs:

  • State attributes for sensor.train_schedule_edb_bts exceed maximum size of 16384 bytes. This can cause database performance issues; Attributes will not be stored

Any idea what I can do to fix?

This is due to the amount of info stored in the attributes for the trains. There is a setting I need to set on the sensors to tell it not to store the attributes in the db. Ill try to put this in the new version.

This warning had always been there and wont affect the schedules. Something I will need to update in the integration.

There is another warning due to zeep using synchronous calls to the api. I cant remember if I fixed this one though.

1 Like

Hello. Completely new to HA. Been trying to set up a morning automation to send a notification to my phone and also possibly have a card on a dashboard showing the next couple of trains. I tried to download the lovelace card but getting an error:

Repository plutomedia987/lovelace-nationalrail not found

Is this no longer available?

Thanks.

1 Like

Card is available here:

I’ve been trying to set up an automation that uses the sensor at a specific time in the morning to check the status of one train in particular, but the automation isn’t able to access the attributes of the sensor as they exceed the 16KB limit. Is there any way around this?

Essentially I’m looking to run an automation at 0630 that checks the expected time of the 06:53 train and ping a notification to a mobile telling me whether it’s on time, running late or cancelled.

I will have a look in to it. The automation is a hang over from the fork and I havent touched it since updating bits.

Ive been made aware of an new issue with zeep and HA 2025.2.0. I will look at fixing this issue this weekend.

1 Like

Hi Dan,

For the past week I was having issues with the created sensors showing any information, so deleted them to setup the integration again (they were orphaned). Now, when adding a line, the integration dialogue shows ‘Unexpected Error’. National Rail key is the same I was using previously.

Are you aware of any issues preventing setup? Latest version installed through HACS.

System logs:

This error originated from a custom integration.

Logger: custom_components.nationalrailuk.config_flow
Source: custom_components/nationalrailuk/config_flow.py:99
integration: National Rail UK (documentation, issues)
First occurred: 08:58:27 (3 occurrences)
Last logged: 09:01:57

Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/nationalrailuk/config_flow.py", line 99, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nationalrailuk/config_flow.py", line 50, in validate_input
    my_api = NationalRailClient(data[CONF_TOKEN], "STP", ["ZFD"])
  File "/config/custom_components/nationalrailuk/client.py", line 81, in __init__
    self.client = AsyncClient(wsdl=WSDL, settings=settings, plugins=[self.history])
                  ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/zeep/client.py", line 71, in __init__
    transport if transport is not None else self._default_transport()
                                            ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/zeep/transports.py", line 186, in __init__
    self.wsdl_client = wsdl_client or httpx.Client(
                                      ~~~~~~~~~~~~^
        verify=verify_ssl,
        ^^^^^^^^^^^^^^^^^^
        proxies=proxy,
        ^^^^^^^^^^^^^^
        timeout=timeout,
        ^^^^^^^^^^^^^^^^
    )
    ^
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'

I dont think you have the latest version of the integration. This was fixed in V1.0.3. The latest version is V1.0.5. Can you confirm you have this version?

Can you also confirm you are using my integration or jfparis’

I redownloaded the latest version in HACS and can confirm it now works - looks like the new version did indeed fix it. Thank you.

1 Like

I feel like I’m doing something really basic wrong…

I’ve accessed the Rail Data Marketplace and subscribed to the Live Departure Board API. However, when I copy the consumer key into the integration set up in HA, it errors with Invalid National Rail token

What am I missing?