How to use API with Ruter Reise Norge

api
ruter
norge
Tags: #<Tag:0x00007fd310096cb8> #<Tag:0x00007fd310096ad8> #<Tag:0x00007fd310096998>

(Jostein) #1

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


(Rich Koshak) #2

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


(Jostein) #3

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:


(Jostein) #4

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!