Skip to content

Public Transport Connection Card

Silvio Kennecke edited this page Jan 3, 2025 · 2 revisions

This card allows you to display the next two upcoming public transport connections offered by a sensor.

I designed this card to work with sensors provided by the FaserF/ha-deutschebahn and akloeckner/hacs-hafas integration. As this card should also be able to work with similar integrations, not explicitly tested, you need to configure the correct attribute and property names, exposed by your sensor. In case you use one of the suggested integrations, the default configuration should already contain the correct values.

screenshot of sample configuration

Sample Config

The card supports two different ways of retrieving the connections from a sensor:

  1. The sensor provides attributes for each connection.
  2. The sensor provides an attribute containing an array of connections.

The following samples show how to configure the card for each of the two cases.

Separate attributes per connection

type: custom:public-transport-connection-card
title: Nächste Bahn
theme: deutsche-bahn
entity: sensor.hamburg_hbf_to_berlin_hbf
departure_station: Hamburg Hbf
arrival_station: Berlin Hbf
attributes:
  description: products
  departure_time: departure
  departure_delay: delay
  arrival_time: arrival
  arrival_delay: delay_arrival
  next_departure_time: next_1
  next_arrival_time: next_1_arrival

Array of connections in one attribute

type: custom:public-transport-connection-card
title: Nächste Bahn
theme: deutsche-bahn
entity: sensor.hamburg_hbf_to_berlin_hbf
departure_station: Hamburg Hbf
arrival_station: Berlin Hbf
connections_attribute: departures # for ha-deutschebahn: departures, for hacs-hafas: connections
connection_properties:
  description: products
  departure_time: departure
  departure_delay: delay
  arrival_time: arrival
  arrival_delay: delay_arrival
displayed_connections: 3

Configuration via UI

Alternatively you can configure the card directly via the UI provided by homeassistant. Please note that currently only sensors providing an array of connections are supported.

Configuration Reference

key required type (or of attribute value) description
title N string a title that is shown in the card
theme N string the theme to use; currently supported: deutsche-bahn, homeassistant
entity Y string entity id of the sensor providing the next connection
departure_station N string a static name of the departure station
arrival_station N string a static name of the arrival station
tap_action N Action an action to be executed when the card is tapped (default: more-info)
attributes if connections_attribute is not set object contains attribute names of the configured entity, with more information about the connections; required if connections_attribute is not set
description N string a description for the connection; might contain information about the train number or train type; for ha-deutschebahn the suggested value is products
departure_time Y string|time the departure time of the current connection
departure_delay N number the current departure delay of the current connection
departure_station N string the departure station name of the current connection
arrival_time Y string|time the arrival time of the current connection
arrival_delay N number the current arrival delay of the current connection
arrival_station N string the arrival station name of the current connection
next_description N string a description for the next upcoming connection; might contain information about the train number or train type; for ha-deutschebahn the suggested value is products
next_departure_time N string|time the departure time of the next upcoming connection
next_departure_delay N number the current departure delay of the next upcoming connection
next_departure_station N string the departure station name of the next upcoming connection
next_arrival_time N string|time the arrival time of the next upcoming connection
next_arrival_delay N number the current arrival delay of the next upcoming connection
next_arrival_station N string the arrival station name of the next upcoming connection
connections_attribute if attributes is not set string the attribute containing an array of connection objects
connection_properties if connections_attribute is set object contains information about the property names, with more information about the connections;
description N string a description for the connection; might contain information about the train number or train type; for ha-deutschebahn the suggested value is products
departure_time Y string|time the departure time of the connection
departure_delay N number the current departure delay of the connection
departure_station N string the departure station name of the connection
arrival_time Y string|time the arrival time of the connection
arrival_delay N number the current arrival delay of the connection
arrival_station N string the arrival station name of the connection
displayed_connections if connections_attribute is set number the maximum number of connections to be shown; minimum 1