Airport Dusseldorf - waiting time for security check

Across Germany and other European countries waiting times at airports security check are increasing due to labor shortage.

I thought it’s time to add the airports waiting time into OpenHAB. Maybe others get inspired to do the same for their local airport, if they publish this information.

Requirements:

  1. HTTP Binding
  2. JSON Path Transformation

Here is my thing:

configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  headers:
    - X-Requested-With=XMLHttpRequest
  baseURL: https://www.dus.com/api/sitecore/flightapi/WaitingTimes?lang=de
  delay: 0
  stateMethod: GET
  refresh: 600
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: WaitingTimeGateA
    channelTypeUID: http:number
    label: Waiting Time Gate A
    description: ""
    configuration:
      mode: READONLY
      stateTransformation: JSONPATH:$.data[?(@.gateTerminal=='A')].waitingTime
      unit: min
  - id: WaitingTimeGateB
    channelTypeUID: http:number
    label: Waiting Time Gate B
    description: null
    configuration:
      mode: READONLY
      stateTransformation: JSONPATH:$.data[?(@.gateTerminal=='B')].waitingTime
      unit: min
  - id: WaitingTimeGateC
    channelTypeUID: http:number
    label: Waiting Time Gate C
    description: null
    configuration:
      mode: READONLY
      stateTransformation: JSONPATH:$.data[?(@.gateTerminal=='C')].waitingTime
      unit: min
4 Likes

i get this error:
Bad Request
reponse of “https://www.dus.com/api/sitecore/flightapi/WaitingTimes?lang=de
Does this still work?

Yes, it should still work. Please make sure to set the header correctly as per the example above.

I was wondering about the same and tried to do it via curl first. Is this correct according to the thing above?

curl -X GET "https://www.dus.com/api/sitecore/flightapi/WaitingTimes?lang=de" -H "X-Requested-With=XMLHttpRequest"

Unfortunately the above command also returns a bad request :frowning:

Thanks,
Klayman

you have to use colon ( : ) instead of equal ( = ) to define the http header if you use curl on command line:

curl -X GET "https://www.dus.com/api/sitecore/flightapi/WaitingTimes?lang=de" -H "X-Requested-With:XMLHttpRequest"

Result:


{"data":[{"id":1,"name":"Sicherheitskontrolle A","waitingTime":1,"gateTerminal":"A","waitingTimeText":"1 Min"},{"id":2,"name":"Sicherheitskontrolle B","waitingTime":3,"gateTerminal":"B","waitingTimeText":"3 Min"},{"id":3,"name":"Sicherheitskontrolle C","waitingTime":3,"gateTerminal":"C","waitingTimeText":"3 Min"}],"serviceType":"Internal","hasError":false,"internalErrorMessage":"","errorCode":""}

Thanks, that did the job :slight_smile:

1 Like

Nice feature.
I created a thing as a textual configuration, as my SetUp is nearly all created with text-files.

Thing http:url:dussel "Düsseldorf" [
    baseURL="https://www.dus.com/api/sitecore/flightapi/WaitingTimes?lang=de", headers="X-Requested-With=XMLHttpRequest", refresh=600] {
        Channels:
            Type number : WaitingTimeGateA "Waiting Time Gate A" [ stateTransformation="JSONPATH:$.data[?(@.gateTerminal=='A')].waitingTime", unit="min" ]
            Type number : WaitingTimeGateB "Waiting Time Gate B" [ stateTransformation="JSONPATH:$.data[?(@.gateTerminal=='B')].waitingTime", unit="min" ]
            Type number : WaitingTimeGateC "Waiting Time Gate C" [ stateTransformation="JSONPATH:$.data[?(@.gateTerminal=='C')].waitingTime", unit="min" ]

}

I tried to find the “url” of “Stuttgart-Airport” but wasn’t successful. Does anyone know how to get this information ?

Cheers - Peter

Wasn’t able to find an API for Stuttgart either but you can extract the waiting times from their webpage using e.g. curl commands for each terminal:

curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 1" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g'

which just returned:

5 Minuten

For terminal 2

curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 2" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g'

which returned:

geschlossen

Terminal 3:

curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 3" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g'

which returned:

10 Minuten
1 Like

Hi Wolfgang,
thx a lot for your help and for the linux commands. I have to think about, how to get the results into OH. Maybe a little bash-Script, which brings them to OH via MQTT. Or via “Exec-Bindings”. But the Curl-Command(including “sed”) is quite fine.

Thx a lot and regards - Peter

Hi Peter,

depends on how / what you would like to do.
In case you would like to have the full history of data e.g. monitoring the value every n-minutes then you could use a linux cronjob that feed values via MQTT otherwise I would check ExecuteCommandLine and only if first two options do not fit then I would go for the Exex binding.

In case you need some kind of support please let me know.

1 Like

Here is the thing for Suttgart:

UID: http:url:AirportStuttgartWaitingTime
label: Airport Stuttgart - waiting time
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  headers:
    - ""
  baseURL: https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/
  delay: 0
  stateMethod: GET
  refresh: 5
  commandMethod: GET
  contentType: text/html
  timeout: 3000
  bufferSize: 2048
channels:
  - id: last-failure
    channelTypeUID: http:request-date-time
    label: Last Failure
    configuration: {}
  - id: last-success
    channelTypeUID: http:request-date-time
    label: Last Success
    configuration: {}
  - id: WaitingTimeGates
    channelTypeUID: http:string
    label: Waiting Time Gates
    description: ""
    configuration: {}

and the REGEX expression for the item

.*<tr>\s*<td>Terminal 1<\/td>\s*<td>(.*?)</td>.*

1 Like

Hi Wolfgang thx a lot for your help.
I first tried the exec-binding and as you predicted it was very problematic as I have to fight with the “correct syntax” and found no solution.
Th next try was a bash-script to use as a schedule(cron job). But the problem in this case is to bring the value to mosquitto(publish).
In case of a value like “5 Minuten” or only “5” (when tried to use a second ‘sed-command’) I get an error messsage from mosquitto:

hab4@raspi58:~ $ /usr/local/mqtt_rpi/mqtt_flight_waittimes.sh
5
geschlossen
'.ror: Unknown option '

Use 'mosquitto_pub --help' to see usage.

I set the second “sed-command” as I first thought that Mosquitto has a problem with the separted Characters “5 Minuten”. But it seems not to be the Problem…
When publishing “geschlossen”, everthing works fine.

The script looks like:

#!/bin/bash

# mqtt_broker_ip="192.168.178.76"
mqtt_broker_ip="localhost"
mqtt_broker_port="1883"
mqtt_topic="flight/dep_arr/latency"

Terminal_1_Stgt=$(curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 1" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g' | sed 's/Minuten//')
Terminal_2_Stgt=$(curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 2" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g' | sed 's/Minuten//')
#Terminal_3_Stgt=$(curl -s https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/ | grep "Terminal 3" -A 1  | tail -1 | sed  's!\([ ]*<td>\|</td>\)!!g')
echo $Terminal_1_Stgt
echo $Terminal_2_Stgt
#echo $Terminal_3_Stgt

mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t1stgt -m $Terminal_1_Stgt # -d
mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t2stgt -m $Terminal_2_Stgt # -d
#mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t3stgt -m $Terminal_3_Stgt # -d

So if you have any idea what is wrong or what is right I would like to have your support to get a good solution.
Thx in advance and cheers - Peter

Hi Holger,
thx for your solution.
My textual result of the thing looks like(as said, I’m a file-driven User “old-school” :upside_down_face:):

Thing http:url:stutt "Stuttgart" [
    baseURL="https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/", refresh=600] {
        Channels:
            Type string : WaitingTimeTerminal1 "Waiting Time Terminal 1"
            Type string : WaitingTimeTerminal2 "Waiting Time Terminal 2"
            Type string : WaitingTimeTerminal3 "Waiting Time Terminal 3"  
 
}            

I linked the Items via UI as you described, but I have to learn how to use them in a textual configuration :thinking:, as this is my favorite setup, so be gracious with me for my ignorance of the “new ways to handle”

Thx and cheers - Peter

Haven’t ever done http binding in textual configuration before - but this was a nice exercise using the answer from @HolBaum5 as basis:

The thing definition with a refresh once a minute ( 60 seconds ):

Thing http:url:stuttgart "stuttgart" [
    baseURL="https://www.flughafen-stuttgart.de/ankunft-abflug/wartezeiten/", 
    refresh=60] {
        Channels:
            Type string : WaitingTimes "Waiting times"
}
and the item definitions:
String WaitingTimeTerminal1 "Es dauert: [%s]"       {channel="http:url:stuttgart:WaitingTimes" [profile="transform:REGEX", function=".*<tr>\\s*<td>Terminal 1<\\/td>\\s*<td>(.*?)</td>.*"] }
String WaitingTimeTerminal2 "Es dauert: [%s]"       {channel="http:url:stuttgart:WaitingTimes" [profile="transform:REGEX", function=".*<tr>\\s*<td>Terminal 2<\\/td>\\s*<td>(.*?)</td>.*"] }
String WaitingTimeTerminal3 "Es dauert: [%s]"       {channel="http:url:stuttgart:WaitingTimes" [profile="transform:REGEX", function=".*<tr>\\s*<td>Terminal 3<\\/td>\\s*<td>(.*?)</td>.*"] }
1 Like

That’s it. :+1: :hugs:
I have had a problem with the Regex-Declaration(Escaping the Back-Slash :confused:) in my .items-File or alternatively in the .things-file, although it’s better to use the “items-profile-Solution” as one has to declare only one Channel in the Thing.

Type string : WaitingTimesRegex    "Waiting Time Terminal 1"  [ stateTransformation="REGEX:.*<tr>\\s*<td>Terminal 1<\\/td>\\s*<td>(.*?)</td>.*" ]

BTW: Do you have any idea, why I get an error in publishing a variable with two character strings like “5 Minutes” in my bash-Script above ?

Cheers -Peter

Hi Peter,

as you already implicitly wrote :slight_smile: in your post: use double quotes surrounding your variables:

mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t1stgt -m "$Terminal_1_Stgt" 
mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t2stgt -m "$Terminal_2_Stgt" 
mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t3stgt -m "$Terminal_3_Stgt"

The space makes it ( 5 Minutes ) two words. The first one is taken to be the message to be published. The second one ( Minutes ) is interpreted to be a parameter/argument for the mosquitto_pub command. As it is not a known parameter you get an error message.
The surrounding double quotes make the two words to be seen as one argument for the message to be published.

1 Like

Hi Wolfgang,
I’m just testing, using constructions like

mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t1stgt -m """$Terminal_1_Stgt""" # -d
mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t2stgt -m  """$Terminal_2_Stgt""" # -d
mosquitto_pub -h $mqtt_broker_ip -p $mqtt_broker_port -t $mqtt_topic/t3stgt -m  """$Terminal_3_Stgt""" # -d

Thx a lot for your support and lessons learned but also thx to @HolBaum5 for his hint via “http-Binding”

Cheers - Peter