Unclear how to configure the Dutch Railway component: Nederlandse Spoorwegen (NS)

I decided to use the core component Nederlandse Spoorwegen to retrieve time table information, but I simply can’t get it to work.

According to the component page above it was introduced in release 0.57 which was a while ago. This thread from April this year mentions that the NS API was going to change. I think it did between then and my time of writing. I’m not sure whether the documentation is still up-to-date however.

Two years ago someone asked for this specific component in this Feature Request thread. @b10m created the initial component back then and the YAML configuration hasn’t changed since that time:

sensor:
  - platform: nederlandse_spoorwegen
    email: <YOUR EMAIL ADDRESS>
    password: <API PASSWORD>
    departures:
      - name: Some Name
        from: <STATION>
        to: <STATION>

He mentioned that you would need to create an account on this page, which is nowadays a page referring you to this page (I’m guessing the new API documentation). The actual Home Assistant component documentation refers you to the latter by redirecting you with this URL.

The configuration and the documentation mention you need a password, an API password. Where do I get this? When creating an account following one of the above links I create a password myself. I’m guessing this isn’t it, but I did try to use that one.

On the NS website I need to subscribe to certain API’s e.g. this one. When doing so I get an API key specifically for that API, but to which API do I need to subscribe?

When using the component I get the following error:

ERROR (SyncWorker_19) [homeassistant.components.nederlandse_spoorwegen.sensor] Couldn't fetch stations, API password correct?: 400 Client Error: Bad Request for url: http://webservices.ns.nl/ns-api-stations-v2

This API isn’t mentioned anywhere on the NS website. So, are there any users out there using this component succesfully? If so, where do I get the correct API key? Am I missing something?

For anyone running into the same issue, I just found the following Github issue which is basically the same issue I ran into.

The issue seems to be that the NS API changed earlier this year (around March 2019 apparently). From that moment on people were only able to register for the new API. The old API was still active and people with credentials to that older API could still use it. The old API has been deprecated since October 1st though, so I’m guessing no one is able to use it now.

The underlying Python library nsapi should be updated to use the new API. There actually is a pull request on Github here which does exactly that, but it has to be merged and afterwards updated in the Home Assistant integration.

2 Likes

Sorry for the long delay. Indeed I’m awaiting a patched nsapi before I can continue with the HA integration. As soon as that package has been updated, I’m happy to update my code (where needed)

New NS Api wil be active on the 31th of January of you need more info gimme a shout out

Wait? So, there’s going to be another update? Than it’s probably better to skip the current version all together and immediately use the next version since the current version hasn’t been working for 9 months or so anyway.

Otherwise we would finally be able to use the integration and than that API is deprecated which would mean we’re back at square one.

The next release seems to have an updated integration, which seems promising, but as @Mrgreen1974 already said… there’s going to be another API update on the 31st of this month, so the updated integration coming in 0.105 might already be outdated by the time it is going to be released :/.