Hi all,
i’ve read the post by @Petrows https://community.openhab.org/t/timetable-for-deutsche-bahn-db-and-local-ka-trains-system/112611 and since i’ve to go by train to work every day i want to have live information, especially about delays…, for all trains leaving at my local train station.
So i’ve decided to implement an binding for the DB timetable api, that’ ready to be tested now and i’m happy about feedback.
The issue for the binding can be found here:
The branch is found here:
PR is about to be opened.
The binding provides two things:
- a timetable bridge that represents the whole timetable for a station
- a train thing that represents a train within the timetable
Sample configuration
timetable.things
Bridge deutschebahn:timetable:timetableLehrte "Fahrplan Lehrte" [ accessToken="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", trainFilter="departures", evaNo="8000226" ] {
Thing deutschebahn:train:timetableLehrte:lehrteZug1 "Zug 1" [ position="1" ]
Thing deutschebahn:train:timetableLehrte:lehrteZug2 "Zug 2" [ position="2" ]
}
timetable.items
// Groups
Group zug1 "Zug 1"
Group zug1Fahrt "Zug 1 Fahrt" (zug1)
Group zug1Ankunft "Zug 1 Ankunft" (zug1)
Group zug1Abfahrt "Zug 1 Abfahrt" (zug1)
// Trip Information
String Zug1_Trip_Category "Kategorie" (zug1Fahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:trip#category"}
String Zug1_Trip_Number "Nummer" (zug1Fahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:trip#number"}
String Zug1_Trip_FilterFlags "Filter" (zug1Fahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:trip#filter-flags"}
String Zug1_Trip_TripType "Fahrttyp" (zug1Fahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:trip#trip-type"}
String Zug1_Trip_Owner "Unternehmen" (zug1Fahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:trip#owner"}
// Arrival Information
DateTime Zug1_Arrival_Plannedtime "Geplante Zeit" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-time"}
DateTime Zug1_Arrival_Changedtime "Geänderte Zeit" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-time"}
String Zug1_Arrival_Plannedplatform "Geplantes Gleis" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-platform"}
String Zug1_Arrival_Changedplatform "Geändertes Gleis" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-platform"}
String Zug1_Arrival_Line "Linie" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#line"}
String Zug1_Arrival_Plannedintermediatestations "Geplante Halte" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-intermediate-stations"}
String Zug1_Arrival_Changedintermediatestations "Geänderte Halte" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-intermediate-stations"}
String Zug1_Arrival_Plannedfinalstation "Geplanter Start-/Zielbahnhof" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-final-station"}
String Zug1_Arrival_Changedfinalstation "Geänderter Start-/Zielbahnhof" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-final-station"}
String Zug1_Arrival_Messages "Meldungen" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#messages"}
String Zug1_Arrival_Plannedstatus "Geplanter Status" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-status"}
String Zug1_Arrival_Changedstatus "Geänderter Status" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-status"}
DateTime Zug1_Arrival_Cancellationtime "Stornierungs-Zeitpunkt" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#cancellation-time"}
// Arrival advanced information
String Zug1_Arrival_Planneddistantendpoint "Geplanter entfernter Endpunkt" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-distant-endpoint"}
String Zug1_Arrival_Changeddistantendpoint "Geänderter entfernter Endpunkt" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-distant-endpoint"}
String Zug1_Arrival_Plannedpath "Geplante Route" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#planned-path"}
String Zug1_Arrival_Changedpath "Geändert Route" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#changed-path"}
Number Zug1_Arrival_Distantchange "Geänderter Zielbahnhof" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#distant-change"}
Switch Zug1_Arrival_Hidden "Versteckt" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#hidden"}
String Zug1_Arrival_Transition "Übergang" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#transition"}
String Zug1_Arrival_Wings "Wings" (zug1Ankunft) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:arrival#wings"}
// Departure Information
DateTime Zug1_Departure_Plannedtime "Geplante Zeit" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-time"}
DateTime Zug1_Departure_Changedtime "Geänderte Zeit" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-time"}
String Zug1_Departure_Plannedplatform "Geplantes Gleis" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-platform"}
String Zug1_Departure_Changedplatform "Geändertes Gleis" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-platform"}
String Zug1_Departure_Line "Linie" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#line"}
String Zug1_Departure_Plannedintermediatestations "Geplante Halte" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-intermediate-stations"}
String Zug1_Departure_Changedintermediatestations "Geänderte Halte" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-intermediate-stations"}
String Zug1_Departure_Plannedfinalstation "Geplanter Start-/Zielbahnhof" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-final-station"}
String Zug1_Departure_Changedfinalstation "Geänderter Start-/Zielbahnhof" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-final-station"}
String Zug1_Departure_Messages "Meldungen" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#messages"}
String Zug1_Departure_Plannedstatus "Geplanter Status" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-status"}
String Zug1_Departure_Changedstatus "Geänderter Status" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-status"}
DateTime Zug1_Departure_Cancellationtime "Stornierungs-Zeitpunkt" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#cancellation-time"}
// Departure advanced information
String Zug1_Departure_Planneddistantendpoint "Geplanter entfernter Endpunkt" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-distant-endpoint"}
String Zug1_Departure_Changeddistantendpoint "Geänderter entfernter Endpunkt" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-distant-endpoint"}
String Zug1_Departure_Plannedpath "Geplante Route" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#planned-path"}
String Zug1_Departure_Changedpath "Geändert Route" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#changed-path"}
Number Zug1_Departure_Distantchange "Geänderter Zielbahnhof" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#distant-change"}
Switch Zug1_Departure_Hidden "Versteckt" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#hidden"}
String Zug1_Departure_Transition "Übergang" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#transition"}
String Zug1_Departure_Wings "Wings" (zug1Abfahrt) {channel="deutschebahn:train:timetableLehrte:lehrteZug1:departure#wings"}
Example widget for displaying train details
uid: timetable_train_details
tags:
- card
props:
parameters:
- context: item
label: Geplante Zeit
name: planned_time
required: true
type: TEXT
- context: item
label: Geänderte Zeit
name: changed_time
required: true
type: TEXT
- context: item
label: Geplantes Gleis
name: planned_platform
required: true
type: TEXT
- context: item
label: Geändertes Gleis
name: changed_platform
required: true
type: TEXT
- context: item
label: Linie
name: line
required: true
type: TEXT
- context: item
label: Meldungen
name: messages
required: true
type: TEXT
- context: item
label: Geplanter Start-/Zielbahnhof
name: planned_final_station
required: true
type: TEXT
- context: item
label: Geplante Halte
name: planned_intermediate_stations
required: true
type: TEXT
- context: item
label: Geändeter Start-/Zielbahnhof
name: changed_final_station
required: true
type: TEXT
- context: item
label: Geänderte Halte
name: changed_intermediate_stations
required: true
type: TEXT
- context: item
label: Geänderter Status
name: changed_state
required: true
type: TEXT
- context: item
label: Kategorie
name: category
required: true
type: TEXT
- context: item
label: Nummer
name: number
required: true
type: TEXT
parameterGroups: []
timestamp: Oct 14, 2021, 11:24:45 AM
component: f7-card
config:
style:
padding: 10px
slots:
default:
- component: f7-row
slots:
default:
- component: f7-col
config:
width: 15
slots:
default:
- component: Label
config:
text: "=items[props.planned_time].displayState + (items[props.changed_time].state != 'NULL' && items[props.changed_time].state != items[props.planned_time].state ? ' (' + items[props.changed_time].displayState + ')' : '')"
style:
color: "=items[props.changed_time].state != 'NULL' && items[props.changed_time].state != items[props.planned_time].state ? 'red' : ''"
- component: f7-col
config:
width: 75
slots:
default:
- component: Label
config:
text: "=(items[props.changed_state].state == 'c' ? 'Zug fällt aus - ' : '') + (items[props.messages].state != 'NULL' ? items[props.messages].state : '')"
style:
color: red
- component: f7-col
config:
width: 10
slots:
default:
- component: Label
config:
text: "=items[props.changed_platform].state != 'NULL' ? items[props.changed_platform].state : items[props.planned_platform].state"
style:
color: "=items[props.changed_platform].state != 'NULL' ? 'red' : ''"
text-align: right
- component: f7-row
slots:
default:
- component: f7-col
config:
width: 15
slots:
default:
- component: Label
config:
text: "=items[props.line].state != 'NULL' ? (items[props.category].state + ' ' + items[props.line].state) : (items[props.category].state + ' ' + items[props.number].state)"
- component: f7-col
config:
width: 50
slots:
default:
- component: Label
config:
text: "=items[props.changed_intermediate_stations].state != 'NULL' ? items[props.changed_intermediate_stations].state : items[props.planned_intermediate_stations].state"
style:
color: "=items[props.changed_intermediate_stations].state != 'NULL' ? 'red' : ''"
- component: f7-col
config:
width: 35
slots:
default:
- component: Label
config:
text: "=items[props.changed_final_station].state != 'NULL' ? items[props.changed_final_station].state : items[props.planned_final_station].state"
style:
color: "=items[props.changed_final_station].state != 'NULL' ? 'red' : ''"
font-weight: bold
text-align: right
I’ve created four trains things and wrapped them into an list card:
component: oh-list-card
config:
simpleList: false
mediaList: false
accordionList: false
title: Abfahrten Hannover HBF
noBorder: true
noShadow: true
style:
margin: 0px
slots:
default:
- component: widget:timetable_train_details
config:
planned_time: Abfahrt1_Departure_Plannedtime
changed_time: Abfahrt1_Departure_Changedtime
planned_platform: Abfahrt1_Departure_Plannedplatform
changed_platform: Abfahrt1_Departure_Changedplatform
line: Abfahrt1_Departure_Line
messages: Abfahrt1_Departure_Messages
planned_final_station: Abfahrt1_Departure_Plannedfinalstation
planned_intermediate_stations: Abfahrt1_Departure_Plannedintermediatestations
changed_final_station: Abfahrt1_Departure_Changedfinalstation
changed_intermediate_stations: Abfahrt1_Departure_Changedintermediatestations
changed_state: Abfahrt1_Departure_Changedstatus
category: Abfahrt1_Kateogrie
number: Abfahrt1_Zugnummer
- component: widget:timetable_train_details
config:
planned_time: Abfahrt2_Departure_Plannedtime
changed_time: Abfahrt2_Departure_Changedtime
planned_platform: Abfahrt2_Departure_Plannedplatform
changed_platform: Abfahrt2_Departure_Changedplatform
line: Abfahrt2_Departure_Line
messages: Abfahrt2_Departure_Messages
planned_final_station: Abfahrt2_Departure_Plannedfinalstation
planned_intermediate_stations: Abfahrt2_Departure_Plannedintermediatestations
changed_final_station: Abfahrt2_Departure_Changedfinalstation
changed_intermediate_stations: Abfahrt2_Departure_Changedintermediatestations
changed_state: Abfahrt2_Departure_Changedstatus
category: Abfahrt2_Kateogrie
number: Abfahrt2_Zugnummer
- component: widget:timetable_train_details
config:
planned_time: Abfahrt3_Departure_Plannedtime
changed_time: Abfahrt3_Departure_Changedtime
planned_platform: Abfahrt3_Departure_Plannedplatform
changed_platform: Abfahrt3_Departure_Changedplatform
line: Abfahrt3_Departure_Line
messages: Abfahrt3_Departure_Messages
planned_final_station: Abfahrt3_Departure_Plannedfinalstation
planned_intermediate_stations: Abfahrt3_Departure_Plannedintermediatestations
changed_final_station: Abfahrt3_Departure_Changedfinalstation
changed_intermediate_stations: Abfahrt3_Departure_Changedintermediatestations
changed_state: Abfahrt3_Departure_Changedstatus
category: Abfahrt3_Kateogrie
number: Abfahrt3_Zugnummer
- component: widget:timetable_train_details
config:
planned_time: Abfahrt4_Departure_Plannedtime
changed_time: Abfahrt4_Departure_Changedtime
planned_platform: Abfahrt4_Departure_Plannedplatform
changed_platform: Abfahrt4_Departure_Changedplatform
line: Abfahrt4_Departure_Line
messages: Abfahrt4_Departure_Messages
planned_final_station: Abfahrt4_Departure_Plannedfinalstation
planned_intermediate_stations: Abfahrt4_Departure_Plannedintermediatestations
changed_final_station: Abfahrt4_Departure_Changedfinalstation
changed_intermediate_stations: Abfahrt4_Departure_Changedintermediatestations
changed_state: Abfahrt4_Departure_Changedstatus
category: Abfahrt4_Kateogrie
number: Abfahrt4_Zugnummer
Result looks like this:
Please have a try and leave comment