How to use API with Ruter Reise Norge

Hi.

I love the work people are doing on OH2 and think it is great!

I am trying to get information from: http://reisapi.ruter.no/stopvisit/getdepartures/3010013 into OH2. I have looked at http://reisapi.ruter.no/Help/ to figure out how to use this as API. My goal is to present when the next subway is coming and present in OH2.

Should I use curl, http, etc?

My problem is what goes where in OH2 to get the information. I have tried google for a couple a days now with out finding any examples of what I am looking for.

Should I create a thing in .things, and should I run the request from there. JSONPATH should be used to find the information I am looking for in the .xml file?

I tried to run the link above in .rules, but as you se below from .log, there is way to much information.

val result = executeCommandLine("curl http://reisapi.ruter.no/Travel/GetTravels?fromPlace={3011310}", 5000)
logInfo("test", result) 

Hope someone can push me in the right direction or briefly explain me how I should go on :slight_smile:

Regards

Jostein

Probably the HTTP binding with the caching configuration (see HTTP binding readme).

The HTTP binding doesn’t support Things.

Yes, and the example you have pasted below is not XML, it is JSON.

That is what the JSONPATH does, extract the indicated piece of informaiton.

Look at

1 Like

Hi.

Thank you very much for the good response!

I have managed to get values via the HTTP-binding into a item, but are still trying to get the correct syntax on the JSONPATH. I will come back with a good example when I have everything up and running :slight_smile:

I have now manged to get the information I want from Ruter (norwegian public transport) and I am calculating the number of minutes until the bus leaves.

Tried to use Openhab v2.1 but could not get the JSONPATH working, upgraded to Openhab v2.2 and it works like a charm!

I have tha following configuration:

Services->http.cfg:
Ruter_Skoy.url=http://reisapi.ruter.no/StopVisit/GetDepartures/3011324?datetime=2017-12-19T13:10&transporttypes=Bus&linenames=78B
Ruter_Skoy.updateInterval=60000

config->default.config:
DateTime Ruter_Sko0 “Godlia [%1$tH:%1$tM]”
{ http="<[Ruter_Skoy:10000:JSONPATH($.[0].MonitoredVehicleJourney.MonitoredCall.AimedDepartureTime)]" }

Number Ruter3_min “1: Minutter til Buss [%.0f min]” {mqtt=">[mosquitto:gang/display/int1:state:*:default]"}

rules->default.rules:
rule "Ruter"
when
Time cron "0/20 * * * * ?"
then
var DateTime Temp0 = new DateTime((CurrentTime.state as DateTimeType).calendar.timeInMillis)

var DateTime Temp5 = new DateTime((Ruter_Sko0.state as DateTimeType).calendar.timeInMillis)

var Number Diff5 = (Temp5.millis - Temp0.millis) /60000

postUpdate(Ruter3_min, Diff5)

Thank you for the help rlkoshak!

Hello! Sorry I didn’t see this before today. I have used Ruter API for a couple of years now, but I am not running it directly from HTTP, but rather through the script function of OpenHAB.

Please be aware that Ruter are discontinuing their service now, as all Norwegian public transport authorities are moving to EnTur. API is at https://www.entur.org/dev/ , but documentation is sparse to say the least!

I am currently working to get more information about the API, to be able to query it. It is now compliant to the European standard called “SIRI”, but that is also somewhat difficult to find good documentation on.

I have now found a working way to do this through Curl. Here is an example:

curl -X POST -H “Content-Type: application/graphql” -H “ET-Client-Name: xxxx-yyyyy” --data ‘{quay(id:“NSR:Quay:6548”){id name estimatedCalls(timeRange: 3600, numberOfDepartures: 2){expectedDepartureTime}}}’ https://api.entur.org/journeyplanner/2.0/index/graphql

This query returns json-formatted data about when the two next departures from a specified “Quay” leave. A quay seems to be track related to stop. So, outside my house, I have one stop, and two directions. So, for me, I chose the “quay” going towards town, as that is the one I am interested in.

I used the url “example” from EnTur to find my stop: https://api.entur.org/api/geocoder/1.1/autocomplete?text=Aln&categories=NO_FILTER&focus.point.lat=59.91&focus.point.lon=10.76&lang=en
Change the text to math your stop name, and you should be able to find your own stop.

Then you can use the example called “avgangstavle på et stoppested” from https://www.entur.org/dev/api/ to find your quay numbers. (Replace stopPlace ID and remove startTime to rather use “now” instead of specific time.)

Continuing the discussion from How to use API with Ruter Reise Norge:

Thank you! I will have a look when I have some spare time to implement this :slight_smile: