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
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
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!
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
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.)