How to (prepare to) integrate public transport departure data using HAFAS REST API?

Not the simplest newbie question but solving would empower openHAB by a very useful feature…

My idea is to integrate public transport departure times into openHAB to display (and voice output) the next departure times of interesting vehicles.

I found the OneBusAway Binding but dit not try it because it’s not usable for me.
In my case (VBB) we need to use the HAFAS REST API.

The request would be like

And we need to parse a list of JSON like this:

“JourneyDetailRef”: {
“ref”: “1|23533|25|86|24112017”
“Product”: {
“name”: "Bus TXL ",
“num”: “51076”,
“line”: “TXL”,
“catOut”: “Bus”,
“catIn”: “B”,
“catCode”: “3”,
“catOutS”: “B”,
“catOutL”: “Bus”,
“operatorCode”: “BVG”,
“operator”: “Berliner Verkehrsbetriebe”,
“admin”: “BVB—”
“name”: "Bus TXL ",
“type”: “S”,
“stop”: “S+U Alexanderplatz Bhf/Memhardstr. (Berlin)”,
“stopid”: “A=1@O=S+U Alexanderplatz Bhf/Memhardstr. (Berlin)@X=13410962@Y=52523099@U=86@L=900100031@”,
“stopExtId”: “900100031”,
“prognosisType”: “PROGNOSED”,
“time”: “18:15:00”,
“date”: “2017-11-24”,
“rtTime”: “18:44:00”,
“rtDate”: “2017-11-24”,
“direction”: “Flughafen Tegel Airport”,
“trainNumber”: “51076”,
“trainCategory”: “B”

Configuration would contain:

  • apiKey
  • station id’s to query
  • update interval
  • optional additional ‎query param’s (e.g. maxJourneys)
  • optional line numbers to filter
  • optional direction names to filter

Filtering should be possible by black or white list.

Result of the new service would be a list of data to display or voice output.
In this case the result would be like “18:44:00 TXL Flughafen Tegel Airport”.

How to achieve this feature?
Is it possible to use an existing binding (e.g. HTTP Binding) or do we need to implement a special binding?

Who is interested in using such feature?
Who is interested in helping to get such feature to work?

Possible future extensions:

  • Make querying, displaying and voice output dependent on constraints. E.g. in the morning on weekdays and if somebody is at home.
  • ‎Add events on delays and disruptions. E.g. to use for some (light or bell) indicator.
  • Add offset from schedule time to result to respect walk duration to get to the stop.

It might be possible to hack something together using existing bindings, but given the extensive feature list here, it would probably be better to implement a new binding.



May i throw in here?
I have already an apikey for testing and it seems we have overlapping ideas.

Maybe some kind of “generic schedule” binding would be from interest.
One could work woth several bridges for different apis. (VBB-Bridge, DB-Bridge)

Since the data is read-only in nearly all cases, this is very similar to something like tankerkoenig or airquality.
Both bindigs provide readable API data.
I am already playing around with another binding for using a meter (gas, water, electric) api.
No rocket science, but a bit of effort needed to bring different api services together.

And when you have readable channels, the voice stuff can be done easily with rules.

Take a look at this example: Examples of HABPanel Solutions

Yes, some generic departure binding would be appropriate…

First I need to get familiar with openHAB development, since there are several restrictions…

I have concerns about the required apikey…

@Confectrician: Where did you got the apikey from?

I fear the VBB will not give apikeys to private persons. Maybe openHAB will get an apikey for development. But any openHAB instance will need an own apikey for running…

There is no dedicated central openHAB server to act as proxy to access such resources from one single point with one (not publicly shared) apikey?

You can register your own account @ Deutsche Bahn Developer Portal and follow different apis they provide.
There was no check or something so I think it is usable for private users too.

1 Like

Hey @voomdoon, do you have success on this binding since 3 years? :slight_smile: I am also thinking about to introduce it, it looks a pretty easy for me. I have working solution: Timetable for Deutsche Bahn (DB) and local KA trains system using python script placing timetable data via MQTT.

@Confectrician , yes, API key is usable and could be obtained in one-click, Tier is 20 requests per minute (my script caches replies and actual rate is 1 request per hour normally).