Adding Efa Bus Timetable to Home Assistant


If you are using the EFA bus timetable you can add a Departure Bus Timetable like this to your Home Assistant instance:

First up we need to configure a Rest Sensor in Home Assistant that will return the JSON response from the EFA API. Add this code to your configuration.yaml file. You will need to replace the "nameInfo_dm" with your desired station ID. You can find a list of station IDs here.

- platform: rest unique_id: '7ed6dfcd3dbc7544c7c880d265b4bc54' resource: https://www.efa-bw.de/bvb3/XML_DM_REQUEST?laguage=de&typeInfo_dm=stopID&deleteAssignedStops_dm=1&useRealtime=1&mode=direct&outputFormat=rapidJSON&limit=4&nameInfo_dm=53032154&version=10.5.17.3 scan_interval: 60 json_attributes: - "stopEvents" name: "Abfahrten"

Then we need to add the sensor to our lovelace UI:

type: vertical-stack cards: - type: custom:mushroom-title-card title: Abfahrten - type: horizontal-stack cards: - square: false columns: 2 type: grid cards: - type: custom:mushroom-template-card primary: >- {{state_attr('sensor.abfahrten','stopEvents')[0].transportation.destination.name}} secondary: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[0].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t > 0) %} in {{t | round }}' {% elif (t < 0) %} Verpasst {% elif (t > 59) %} Später {% elif (t > 120) %} Morgen {% endif %} icon: mdi:bus entity: sensor.abfahrten layout: horizontal tap_action: action: none hold_action: action: none double_tap_action: action: none icon_color: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[0].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t < 5) %} red {% elif (t < 9) %} orange {% elif (t > 8) %} green {% endif %} badge_icon: '' badge_color: '' - type: custom:mushroom-template-card primary: >- {{state_attr('sensor.abfahrten','stopEvents')[1].transportation.destination.name}} secondary: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[1].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t > 0) %} in {{t | round }}' {% elif (t < 0) %} Verpasst {% elif (t > 59) %} Später {% elif (t > 120) %} Morgen {% endif %} icon: mdi:bus entity: sensor.abfahrten layout: horizontal tap_action: action: none hold_action: action: none double_tap_action: action: none icon_color: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[1].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t < 5) %} red {% elif (t < 9) %} orange {% elif (t > 8) %} green {% endif %} badge_icon: '' badge_color: '' - type: custom:mushroom-template-card primary: >- {{state_attr('sensor.abfahrten','stopEvents')[2].transportation.destination.name}} secondary: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[2].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t > 0) %} in {{t | round }}' {% elif (t < 0) %} Verpasst {% elif (t > 59) %} Später {% elif (t > 120) %} Morgen {% endif %} icon: mdi:bus entity: sensor.abfahrten layout: horizontal tap_action: action: none hold_action: action: none double_tap_action: action: none icon_color: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[2].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t < 5) %} red {% elif (t < 9) %} orange {% elif (t > 8) %} green {% endif %} badge_icon: '' badge_color: '' - type: custom:mushroom-template-card primary: >- {{state_attr('sensor.abfahrten','stopEvents')[3].transportation.destination.name}} secondary: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[3].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t > 0) %} in {{t | round }}' {% elif (t < 0) %} Verpasst {% elif (t > 59) %} Später {% elif (t > 120) %} Morgen {% endif %} icon: mdi:bus entity: sensor.abfahrten layout: horizontal tap_action: action: none hold_action: action: none double_tap_action: action: none icon_color: >- {% set t = ((state_attr('sensor.abfahrten','stopEvents')[3].departureTimeEstimated | as_datetime - now()).total_seconds() // 60) %} {% if (t < 5) %} red {% elif (t < 9) %} orange {% elif (t > 8) %} green {% endif %} badge_icon: '' badge_color: ''

I am using the "mushroom-template-card" from the Mushroom repository.

And that's all there is to this.

Want departures without Home Assistant? Try EFA-CLI in your terminal or EVA-PWA on your phone.