Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rejseplanen stopped working in December 2024 #133420

Open
KennethLavrsen opened this issue Dec 17, 2024 · 31 comments
Open

Rejseplanen stopped working in December 2024 #133420

KennethLavrsen opened this issue Dec 17, 2024 · 31 comments

Comments

@KennethLavrsen
Copy link

The problem

The rejseplanen integration no longer shows anything in the sensors

There are no errors or warnings in the error log.

However when I go to the URLs in the documentation Rejseplanen says that they changed to API 2.0 4th of December.

That is probably the issue

What version of Home Assistant Core has the issue?

core-2024.12.3

What was the last working version of Home Assistant Core?

core-2024.12.1

What type of installation are you running?

Home Assistant OS

Integration causing the issue

rejseplanen

Link to integration documentation on our website

https://www.home-assistant.io/integrations/rejseplanen/

Diagnostics information

Nothing in the logs. It seems the old API still answers but not with any useful data

Example YAML snippet

- platform: rejseplanen
  name: "Glostrup S Train"
  stop_id: '008600622'
  departure_type:
    - 'S'
    - 'LET'

- platform: rejseplanen
  name: "Vanløse 19"
  stop_id: '008600703'
  route:
    - 'Bus 19'
  direction: 'Glostrup St.'
 
- platform: rejseplanen
  stop_id: '000003798'
  name: "Byparken"
 
- platform: rejseplanen
  #stop_id: '38'
  stop_id: '2261'
  name: "Glostrup Busses"
  departure_type:
    - 'BUS'
    - 'EXB'

Anything in the logs that might be useful for us?

Nothing. Log is clean

Additional information

Nothing

@home-assistant
Copy link

@KennethLavrsen
Copy link
Author

I dug into the code just to see what is happening.

The integration uses a python library that implements the actual API.

There is a bug open there raised in October and zero reaction from the maintainer.

An important thing is that the new 2.0 API now cost money to use if you exceed 50000 API calls per month and you have to keep the API key non public. That means the library and integration will need to implement that each user uses their own API key and that we all have to request a key.

Sound like a dead project to me because this is not feasible for normal users.

@RKOvlesenMerkle
Copy link

RKOvlesenMerkle commented Dec 18, 2024

There are several HA integrations that require the user to get their own API key and the current setup of looking up address, copying coordinates etc is already a bit much for regular users. So I still think the project has a future. Unfortunately I don't have the Python or integration-making experience to contribute much to a solution myself.

@XanderDK
Copy link

Read into it as well. 50000 calls per month should be more than enough for regular users. Wouldnt mind a registration with my own key.

@kristianschneider
Copy link

where do you register ?

@KennethLavrsen
Copy link
Author

Here

https://labs.rejseplanen.dk/hc/da/articles/21553113674909-Adgang-til-API-GTFS-og-stoppestedsdata

I have just applied to see if they really want to start handing out 100s of API keys to private end users. It would be better if they made a limited API access with that the things you need for the HA integration. And they could throttle the access per IP address if they worry about abuse.

@Klodomir
Copy link

I have applied too. They do have the option of selecting “free service”, so I wonder if they might be open to allowing this integration to continue without individual API keys. Still, it has to be rewritten, of course.

I don’t think very many of us use it, but it provides a lot of value for my family, at least.

@KennethLavrsen
Copy link
Author

I got my API key. So others can apply too. Now we just need a Python programmer to rewrite the software. I can code stone age C but not not Python. And I am away on vacation over the holidays

@sorenisanerd
Copy link

sorenisanerd commented Dec 22, 2024

I looked at the API docs for v2, and there were references to something called HAFAS. It's apparently some kind of de facto industry standard for mass transportation services. There's a python library, pyhafas, for interacting with it. Incidentally, @eisbaw added support for Rejseplanen to pyhafas. Yay! Here's an example: https://github.com/FahrplanDatenGarten/pyhafas/blob/main/example_rejseplanen.py

No API key required. For now, at least.

I don't have the time and/or motivation to do the work, but hopefully someone can take this and run with it.

@KennethLavrsen
Copy link
Author

Looking at the old integration. It updates each sensor once per minute. One sensor is 44640 lookups per 31 days. That means you can only have 1 sensor. That sucks. I only need to update the sensor when I look at it. If I am to use the new API key, I will need to find a way to activate the sensor for e.g. 10 or 20 minutes and then it stops again automatically. I think the way most use the sensor is to look at a rejseplanen card to see when the next bus or train departs. I cannot see many use this for automations running 24/7.
I had 4 sensors running. One for my local bus stop. One for busses at by nearest station. One for busses at same station. And one for a stop I often needed a connection at. That exceeds the limit for free use by a factor 4.

@davidolrik
Copy link

davidolrik commented Dec 22, 2024

Looking at the old integration. It updates each sensor once per minute. One sensor is 44640 lookups per 31 days. That means you can only have 1 sensor.

There is an endpoint where you can get multiple stops in one call, which would allow you to stay within the limit and have as many sensors as you want - as long as they can fit into this one call.

From the docs:

Multi Departure Board

Departure boards for multiple stations can be retrieved by a call to the multiDepartureBoard service. This method will return the next departures from a given point in time within a duration-covered period.

@daath
Copy link

daath commented Dec 28, 2024

I was wondering why the info didn't show up anymore ;P I hope someone less lazy than me fixes this issue soon :)

@LordMike
Copy link
Contributor

LordMike commented Jan 7, 2025

Querying once per minute is also crazy. I understand the need to see delays, but they’re rare - so in the normal case (people sleeping, at work, not home, ..) it’s just a waste.

Updates could be limited to once every 15-30 minutes outside peak, 5 minutes inside peak, and if a delay is identified then more often.

Here’s to hoping we get a HAFAS integration :). Also hoping that we can query a departure board based on an intended destination station, and not a direction 🤞

@zaughon
Copy link

zaughon commented Jan 15, 2025

Querying once per minute is also crazy. I understand the need to see delays, but they’re rare - so in the normal case (people sleeping, at work, not home, ..) it’s just a waste.

In general i agree, but in the case of 5C in inner Copenhagen, once a minute might be needed considering how unreliable they are.
They're supposed to go every ~4 minute in rush-hour, but it's not uncommon for them to not show up for 15+ minutes, and then there's 5 driving in a long row of each other 🙄

@madsnedergaard
Copy link
Contributor

madsnedergaard commented Feb 12, 2025

Good news: I have added Rejseplanen support to this cool HAFAS HA integration (thanks @akloeckner 🙏 ), so it is now possible to get Danish public transport info in Home Assistant :)


It is installed via HACS and with this as custom repository: https://github.com/akloeckner/hacs-hafas

And then you can create a new entity like this:

I'm considering writing a blog post with more details about how to set it up, let me know if this is something anyone would actually find useful!

@zaughon
Copy link

zaughon commented Feb 13, 2025

It looks to me like it only shows the next departure time, is that right?
I really liked the previous (broken) integration because it showed the next several departures, which is really useful in inner Cph with busses that go every couple of minutes. Seeing there's one in 2 minutes doesn't help much, but seeing there's one in 2, 4, 16, 18 and 19 minutes does

@madsnedergaard
Copy link
Contributor

madsnedergaard commented Feb 13, 2025

It looks to me like it only shows the next departure time, is that right? I really liked the previous (broken) integration because it showed the next several departures, which is really useful in inner Cph with busses that go every couple of minutes. Seeing there's one in 2 minutes doesn't help much, but seeing there's one in 2, 4, 16, 18 and 19 minutes does

That is indeed possible, it's just me who's living in the country side where the trains only run once per hour 😉

But here's an example I just threw together with runddelen to Nørreport:

Image

And here's the code (without delays or cancellations to keep things simple):

type: custom:mushroom-template-card
primary: Næste 5 forbindelser
secondary: >-
  {%- set connections =
  state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections')
  %} {%- if connections -%}
    {%- for connection in connections[:5] -%}
      {%- set departure = connection.departure | as_local -%}
      {%- if not loop.first %}
  {% endif -%}
      {{- connection.products ~ ' — ' -}}
      {{- departure.strftime('%H:%M') -}} 
      {%- if not loop.last -%}

      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}
icon: mdi:train
entity: sensor.norrebros_runddel_jagtvej_to_norreport_st
badge_icon: ""
badge_color: ""
fill_container: false
tap_action:
  action: more-info
hold_action:
  action: none
double_tap_action:
  action: none
icon_color: >-
  {% set connections =
  state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections')
  %} {% if connections and connections[0].canceled %}
    red
  {% elif connections and connections[0].delay %}
    yellow
  {% else %}
    green
  {% endif %}
grid_options:
  columns: full
multiline_secondary: true

@kp-bit
Copy link

kp-bit commented Feb 13, 2025

Good work @madsnedergaard! 👍

@XanderDK
Copy link

XanderDK commented Feb 13, 2025

  {{- connection.products ~ ' — ' -}}

First, thank you for the really nice work .

I'm trying to edit the products line. It says on the HAFAS wiki that i should be "products: comma-separated list of line names".

But I cant get it working. How do I get it to show as an example only line 350s and 6a?

I tried messing around with the names.

@Bluhme1
Copy link

Bluhme1 commented Feb 13, 2025

Great job
I live in Odder and we have both Letbane and Bus 100 going to Aarhus and return. When I make the entity I only get Bus 100.
Do nI do anything wrong?
/Lars

@madsnedergaard
Copy link
Contributor

@XanderDK:

I'm trying to edit the products line. It says on the HAFAS wiki that i should be "products: comma-separated list of line names".

But I cant get it working. How do I get it to show as an example only line 350s and 6a?

I tried messing around with the names.

How about only displaying info based on the products like this, could that work for your use case? Otherwise I'd need to know more details to help :)

  {%- set connections = state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections') -%}
  {%- if connections -%}
    {%- for connection in connections[:5] -%}
      {%- if connection.products == "Bus 6A" or connection.products == "Bus 350S" -%}
        {%- set departure = connection.departure | as_local -%}
        {{'\n'}}
        {{- connection.products ~ ' — ' ~ departure.strftime('%H:%M') -}}
        {%- if not loop.last -%}
        {%- endif -%}
      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}

Image


@Bluhme1:

I live in Odder and we have both Letbane and Bus 100 going to Aarhus and return. When I make the entity I only get Bus 100.
Do nI do anything wrong?

I digged further into this, and it turns out the Rejseplanen profile in Pyhafas does not support "letbane" as a transport mode :)
I have made a PR to add support for it here: FahrplanDatenGarten/pyhafas#56

@Bluhme1
Copy link

Bluhme1 commented Feb 14, 2025

Great. Just a question. Perhaps stupid. Can I change something local, while waiting for a merge?

/Lars

@XanderDK
Copy link

@XanderDK:

I'm trying to edit the products line. It says on the HAFAS wiki that i should be "products: comma-separated list of line names".
But I cant get it working. How do I get it to show as an example only line 350s and 6a?
I tried messing around with the names.

How about only displaying info based on the products like this, could that work for your use case? Otherwise I'd need to know more details to help :)

  {%- set connections = state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections') -%}
  {%- if connections -%}
    {%- for connection in connections[:5] -%}
      {%- if connection.products == "Bus 6A" or connection.products == "Bus 350S" -%}
        {%- set departure = connection.departure | as_local -%}
        {{'\n'}}
        {{- connection.products ~ ' — ' ~ departure.strftime('%H:%M') -}}
        {%- if not loop.last -%}
        {%- endif -%}
      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}

Image

@Bluhme1:

I live in Odder and we have both Letbane and Bus 100 going to Aarhus and return. When I make the entity I only get Bus 100.
Do nI do anything wrong?

I digged further into this, and it turns out the Rejseplanen profile in Pyhafas does not support "letbane" as a transport mode :) I have made a PR to add support for it here: FahrplanDatenGarten/pyhafas#56

@XanderDK:

I'm trying to edit the products line. It says on the HAFAS wiki that i should be "products: comma-separated list of line names".
But I cant get it working. How do I get it to show as an example only line 350s and 6a?
I tried messing around with the names.

How about only displaying info based on the products like this, could that work for your use case? Otherwise I'd need to know more details to help :)

  {%- set connections = state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections') -%}
  {%- if connections -%}
    {%- for connection in connections[:5] -%}
      {%- if connection.products == "Bus 6A" or connection.products == "Bus 350S" -%}
        {%- set departure = connection.departure | as_local -%}
        {{'\n'}}
        {{- connection.products ~ ' — ' ~ departure.strftime('%H:%M') -}}
        {%- if not loop.last -%}
        {%- endif -%}
      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}

Image

@Bluhme1:

I live in Odder and we have both Letbane and Bus 100 going to Aarhus and return. When I make the entity I only get Bus 100.
Do nI do anything wrong?

I digged further into this, and it turns out the Rejseplanen profile in Pyhafas does not support "letbane" as a transport mode :) I have made a PR to add support for it here: FahrplanDatenGarten/pyhafas#56

Thank you so much, this works for me :)

@madsnedergaard
Copy link
Contributor

Great. Just a question. Perhaps stupid. Can I change something local, while waiting for a merge?

/Lars

I don't actually know, but since it's a dependency of a dependency it'll probably prove a bit tricky - I think you'd have to fork both projects to make an integration that would point at a specific branch :)

@Bluhme1
Copy link

Bluhme1 commented Feb 14, 2025

OK. I’ll wait for you PR to merge

@pccaredk
Copy link

Hej, jeg kan ikke finde ud af at slette rejseplanen integrationen, Nogle tips?
P.S Tak for det nye trick med HaFAS..

@anes300
Copy link

anes300 commented Feb 20, 2025

Hej, jeg kan ikke finde ud af at slette rejseplanen integrationen, Nogle tips? P.S Tak for det nye trick med HaFAS..

Har du tjekket din configuration.yaml fil (eller anden fil, som bliver refereret) og sikret, at du har fjernet alle sensorer, der benytter 'rejseplanen' platform?

@Soren47
Copy link

Soren47 commented Feb 25, 2025

Tak for tilføjelsen af Rejseplanen til HAFAS HA!
Jeg bor et sted hvor togene tit ikke kører hele vejen, ændrer destination mm., så jeg ville gerne kunne vise togets endestation.
Dette ville også kunne simulere en afgangstavle fra en bestemt station.

Jeg kan ikke helt se om det er en del af HAFAS.

Eksempel:
Start: Roskilde St.
Destination: København H

18:21 Mod Helsingør
18:30 Mod Nørreport

@madsnedergaard
Copy link
Contributor

Tak for tilføjelsen af Rejseplanen til HAFAS HA!
Jeg bor et sted hvor togene tit ikke kører hele vejen, ændrer destination mm., så jeg ville gerne kunne vise togets endestation.
Dette ville også kunne simulere en afgangstavle fra en bestemt station.

Jeg kan ikke helt se om det er en del af HAFAS.

Eksempel:
Start: Roskilde St.
Destination: København H

18:21 Mod Helsingør
18:30 Mod Nørreport

Der virker ikke umiddelbart som om det understøtter det:

image

image

@Soren47
Copy link

Soren47 commented Mar 2, 2025

Tak for kigget og øv! :)

@kimvonmullen
Copy link

kimvonmullen commented Mar 2, 2025

It looks to me like it only shows the next departure time, is that right? I really liked the previous (broken) integration because it showed the next several departures, which is really useful in inner Cph with busses that go every couple of minutes. Seeing there's one in 2 minutes doesn't help much, but seeing there's one in 2, 4, 16, 18 and 19 minutes does

That is indeed possible, it's just me who's living in the country side where the trains only run once per hour 😉

But here's an example I just threw together with runddelen to Nørreport:

Image

And here's the code (without delays or cancellations to keep things simple):

type: custom:mushroom-template-card
primary: Næste 5 forbindelser
secondary: >-
  {%- set connections =
  state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections')
  %} {%- if connections -%}
    {%- for connection in connections[:5] -%}
      {%- set departure = connection.departure | as_local -%}
      {%- if not loop.first %}
  {% endif -%}
      {{- connection.products ~ ' — ' -}}
      {{- departure.strftime('%H:%M') -}} 
      {%- if not loop.last -%}

      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}
icon: mdi:train
entity: sensor.norrebros_runddel_jagtvej_to_norreport_st
badge_icon: ""
badge_color: ""
fill_container: false
tap_action:
  action: more-info
hold_action:
  action: none
double_tap_action:
  action: none
icon_color: >-
  {% set connections =
  state_attr('sensor.norrebros_runddel_jagtvej_to_norreport_st', 'connections')
  %} {% if connections and connections[0].canceled %}
    red
  {% elif connections and connections[0].delay %}
    yellow
  {% else %}
    green
  {% endif %}
grid_options:
  columns: full
multiline_secondary: true

Hi everyone,
Really great work, @madsnedergaard . It is much appreciated.
For everyone else, just sharing my card with a few tweaks, as it adds the number of minutes delayed to the departure time and includes a correction to the color of the icon.

type: custom:mushroom-template-card
primary: Bus 7A mod ZOO
secondary: >-
  {%- set connections =
  state_attr('sensor.vaernedamsvej_frederiksberg_alle_to_zoologisk_have_roskildevej',
  'connections') -%} {%- if connections -%}
    {%- for connection in connections[:5] -%}
    {%- set departure = connection.departure | as_local -%}
    {{'\n'}}
      {%- if connection.ontime == false -%}
      {%- set delay = connection.legs[0].delay if connection.legs else "0:00:00" -%}
      {%- set delay_minutes = delay.split(':')[1] | int -%}
      {%- set new_departure = departure + timedelta(minutes=delay_minutes) -%}
      {{ new_departure.strftime('%H:%M') ~ ' — Forsinket ' ~ delay_minutes ~ ' min - tidspunkt er korrigeret' }}
      {%- else -%}
        {%- set departure = connection.departure | as_local -%}
        {{- departure.strftime('%H:%M') -}}
        {%- if not loop.last -%}
        {%- endif -%}
      {%- endif -%}
    {%- endfor -%}
  {%- else -%}
    Ingen afgange fundet
  {%- endif -%}
icon: mdi:bus
badge_icon: ""
badge_color: ""
fill_container: false
tap_action:
  action: more-info
hold_action:
  action: none
double_tap_action:
  action: none
icon_color: >-
  {% set connections =
  state_attr('sensor.vaernedamsvej_frederiksberg_alle_to_zoologisk_have_roskildevej',
  'connections') %} {% if connections and connections[0].canceled %}
    red
  {% elif connections and not connections[0].ontime %}
    yellow
  {% else %}
    green
  {% endif %}
grid_options:
  columns: full
multiline_secondary: true
entity: sensor.vaernedamsvej_frederiksberg_alle_to_zoologisk_have_roskildevej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests