The deutschebahn
sensor will give you the departure time of the next train for the given connection. In case of a delay, the delay is also shown. Additional details are used to inform about, e.g., the type of the train, price, and if it is on time.
The official Deutsche Bahn Homeassistant integration got removed with release 2022.11 - therefore this custom integration exists. It got removed due to cloud scraping, but still was fully functional.
Please note that I will only give limited support on this integration.
This integration is based on the formerly official HA DB integration, see here.
This sensor stores a lot of attributes which can be accessed by other sensors, e.g., a template sensor.
Old Homeassistant documentation can be found here.
This integration is a official HACS Integration.
Open HACS then install the "Deutsche Bahn" integration or use the link below.
If you use this method, your component will always update to the latest version.
- Download the latest zip release from here
- Extract the zip file
- Copy the folder "deutschebahn" from within custom_components with all of its components to
<config>/custom_components/
where <config>
is your Home Assistant configuration directory.
NOTE: Do not download the file by using the link above directly, the status in the "master" branch can be in development and therefore is maybe not working.
- Remove any deutschebahn (or deutsche_bahn) configuration from your configuration.yaml file
- Update the Integration to the latest release
- Restart Homeassistant
- Set up the integration from the UI
Go to Configuration -> Integrations and click on "add integration". Then search for "Deutsche Bahn".
- from: The name of the start station.
- to: The name of the end/destination station.
- offset (optional): Do not display departures leaving sooner than this number of seconds. Useful if you are a couple of minutes away from the stop. The formats "HH:MM" and "HH:MM:SS" are also supported.
- only direct (optional - default is false): Only show direct connections.
- products to ignore (optional - default is empty): Filter train types, that should be excluded
- maximum connections (optional - default is 2): Specify how many next connections should be fetched
- scan interval (optional - default is 2 minutes): Specify the refresh interval in minutes
automation:
- alias: "Notification for Train Delay"
trigger:
platform: template
value_template: "{{ state_attr('sensor.fromstation_to_station', 'departures')[0].delay | int > 5 }}"
action:
- service: notify.notify
data_template:
message: >
The train departing at {{ states.sensor.fromstation_to_station.attributes.departures[0].departure_current }}
and arriving at {{ states.sensor.fromstation_to_station.attributes.departures[0].arrival_current }}
is delayed by {{ states.sensor.fromstation_to_station.attributes.departures[0].delay }}
minutes and costs {{ states.sensor.fromstation_to_station.attributes.departures[0].price }}.
Next train after that: {{ states.sensor.fromstation_to_station.attributes.departures[0].departure_current }}
Add a custom sensor in your configuration.yaml
sensor:
- platform: template
sensors:
next_train_departure:
friendly_name: "Next Train Departure"
value_template: "{{ state_attr('sensor.fromstation_to_station', 'connections')[0].departure }}"
icon_template: mdi:train
silviokennecke has created this great lovelace card for a better overview of the train departures. Be sure to check it out.
Open an issue over at github issues. Please prefer sending over a log with debugging enabled.
To enable debugging enter the following in your configuration.yaml
logger:
logs:
custom_components.deutschebahn: debug
You can then find the log in the HA settings -> System -> Logs -> Enter "deutschebahn" in the search bar -> "Load full logs"
Huge thanks to @homeassistant for the official old integration, where this one is based on! Also to @kennell for the schiene python library that this integration is using.
The data is coming from the bahn.de website.