Add support for Norwegian Public Transport (Ruter)


#1

Ruter, the Norwegian Public Transport, have an open API for travel planning/stops and also for deviation of routes. Adding this to HA would be great.
Link to travelplan/stops API: http://reisapi.ruter.no/help
Link ot deviation API: http://sirisx.ruter.no/help
The license is found here: http://data.norge.no/nlod/en

A typical implementation could be to initially choose your favourite route(s), and based on HA local time, display the next bus/train + the next hour) and also get any deviation info. This woudl be a great feature for any commuter, or even in-frequent travellers.


#2

@geirmork
I have this one: https://github.com/custom-components/sensor.ruter


#3

Hi Ludeeus. Still got the custom component for Ruter?


#4

Yep, have updated the link now :slight_smile:


#5

@ludeeus
I can’t get this to work for some reason.
In the log it looks like this.

Error while setting up platform ruter
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sensor/ruter.py", line 42, in setup_platform
    add_devices([RuterSensor(stopid, destination)])
  File "/config/custom_components/sensor/ruter.py", line 55, in __init__
    self.update()
  File "/config/custom_components/sensor/ruter.py", line 60, in update
    self._defined_destination)
  File "/config/deps/lib/python3.6/site-packages/pyruter/__init__.py", line 31, in getDepartureInfo
    departureResponse = departureRequest[count]['MonitoredVehicleJourney']
IndexError: list index out of range
2018-09-28 19:14:22 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 336, in _async_add_entity
    msg)

#6

What is your config for it?


#7

@ludeeus
The config is:

sensor:
  platform: ruter
  stopid: 2130501
  destination: 'Langhus stasjon [buss] (Ski)'

#8

Is it line 510 you are trying to get information about?
If so you need to use destination: 'Bøleråsen'


#9

It should be 510 Drøbak-Seiersten


#10

@ludeeus

Is this the correct way then?

sensor:
  platform: ruter
  stopid: 2130501
  destination: 'Drøbak-Seiersten'

#11

Oh, you wanted the other way xD
Yes, your example should work


#12

Not working.
I am getting this error:
2018-09-28 21:00:48 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations.yaml contains duplicate key "data". Check lines 73 and 77.

The other sensor it is talking about is this one:

# Weather prediction
sensor:
  - platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:
      - temperature
      - precipitation
      - windSpeed
      - humidity

#13

Wrong file mate :wink:


#14

It works now :slight_smile:
Great stuff, thanks a lot!


#15

@ludeeus
No, wait it does not work properly.
The log is saying:

2018-09-28 21:36:26 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/configuration.yaml contains duplicate key "sensor". Check lines 56 and 109.

It is telling me I have to sensors in the config, which is true. One is for the buss timetable the other one is for Yr weather forecast. The buss timetable shows and works, but the weather does not show after including the second sensor (which is the sensor for ruter).

One is:

# Weather prediction
sensor:
  - platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:
      - temperature
      - precipitation
      - windSpeed
      - humidity

The other one is:

# Buss timetable
sensor:
  platform: ruter
  stopid: 2130501
  destination: 'Drøbak-Seiersten'

Because it is two sensors in the configuration one of them does not work. How should\could I fix that?


#16

like this:

# Weather prediction
sensor:
  - platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:
      - temperature
      - precipitation
      - windSpeed
      - humidity

# Buss timetable
  - platform: ruter
    stopid: 2130501
    destination: 'Drøbak-Seiersten'

or like this:

# Weather prediction
sensor weather:
  - platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:
      - temperature
      - precipitation
      - windSpeed
      - humidity

# Buss timetable
sensor buss:
  platform: ruter
  stopid: 2130501
  destination: 'Drøbak-Seiersten'

#17

Works great, thank you! Would be nice to set how many departures to display, to display the next two or three departures e.g. Also interesting to see how people use this sensor in Lovelace.


#18

I like that idea!
https://github.com/custom-components/sensor.ruter/issues/1


#19

https://github.com/custom-components/sensor.ruter/releases/tag/3.0.0


#20

That was fast! Nice!
I get the same time for both sensors, no error messages I could find now.
I just added another duplicate sensor like:

sensor:
  - platform: ruter
    stopid: 3010641
    destination: 'Nydalen T'
  - platform: ruter
    stopid: 3010641
    destination: 'Nydalen T'

I get two unique sensors from the same destination and stopid like you, but also the same departure time. What did I do wrong?