Skip to content

๐ŸšŒ Custom Home Assistant integration for Motis/Transitous public transport departures.

License

Notifications You must be signed in to change notification settings

HerrLevin/homeassistant-motis

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

80 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GitHub Release Maintainer HACS Custom GitHub Downloads

motis Logo

Home Assistant Motis Integration

This custom hacs-default integration adds support for real-time public transport departures from Transitous to Home Assistant, using the Motis API.

It allows you to monitor upcoming departures for stations, with optional filtering by platforms and lines.
Each configured station is represented as a device with separate entities for the next three departures.

Installation

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

This integration is now available as a default HACS repository!

  1. Install HACS if you haven't already.
  2. In HACS, go to Integrations โ†’ โ‹ฎ โ†’ Custom repositories.
  3. Add this repository as a custom integration repository:
  4. Restart Home Assistant

Configuration

After installation, add the integration to Home Assistant (Requesting the first access token may take a while):

Open your Home Assistant instance and start setting up a new integration.

Or manually:

  1. Go to Settings โ†’ Devices & Services โ†’ + Add Integration
  2. Search for Motis
  3. Follow the setup flow

Options

You can customize the integration after setup by managing stations through the options flow:

  1. Go to Settings โ†’ Devices & Services.
  2. Find Motis Public Transport and click the cog (โš™๏ธ) icon to open Options.

Inside the options menu, you can:

Add a station:

Enter the station name and click submit. Select the correct station from a drop down and optionally specify platforms and lines to monitor.

Remove a station:

Select a station from your saved list to remove it (this also deletes associated devices).

Save and exit:

Apply your changes and close the options menu.

Sensor Examples

Below are two examples showing upcoming Motis public transport departures in Home Assistant:

next departures

Detail Karlsruhe Hauptbahnhof

Cards

With this integration, two types of Home Assistant cards can be created to display upcoming departures.

Custom Card

Custom Card

For instructions on using the custom card, see the Motis Card repository.

Example Frontend Card

Using the markdown card in Home Assistant an overview like this can be generated:

Markdown Card

Use this code to replicate the card in Home Assistant. You only have to change the heading and your Motis sensor names:

type: markdown
content: |
  <h3>๐Ÿš Departures</h1>

  {% set sensors = [
    'sensor.motis_station_xxx_r_50_next_departure',
    'sensor.motis_station_xxx_r_50_second_departure',
    'sensor.motis_station_xxx_r_50_third_departure'
  ] %}

  <table border="1" width="100%" cellspacing="0" cellpadding="4">
    <tr>
      <th align="center">Line</th>
      <th align="center">Destination</th>
      <th align="center">Departure</th>
      <th align="center">Platform</th>
    </tr>
    {%- for s in sensors %}
      {%- set state = states[s] %}
      {%- if state %}
        <tr>
          <td align="center" style="color: {{ state.attributes.route_text_color }}">
          {{ state.attributes.label }}
          </td>
          <td align="center">{{ state.attributes.destination }}</td>
          <td align="center">
            {%- if state.attributes.time_until_departure -%}
            {{ state.attributes.time_until_departure }}
            {%- else -%}
            {{ state.attributes.realtime_time_local or (state.attributes.realtime_time | default(state.attributes.planned_time) | as_timestamp | timestamp_custom('%H:%M')) }}
            {%- endif -%}
  
          </td>
          <td align="center">{{ state.attributes.platform or '-' }}</td>
        </tr>
      {%- endif %}
    {%- endfor %}
  </table>

For a German Version:

Markdown Card in German

type: markdown
content: |
  <h3>๐Ÿš Haltestelle</h1>

  {% set sensors = [
    'sensor.motis_station_xxx_r_50_next_departure',
    'sensor.motis_station_xxx_r_50_second_departure',
    'sensor.motis_station_xxx_r_50_third_departure'
  ] %}

  <table border="1" width="100%" cellspacing="0" cellpadding="4">
    <tr>
      <th align="center">Linie</th>
      <th align="center">Ziel</th>
      <th align="center">Abfahrt</th>
      <th align="center">Steig</th>
    </tr>
    {%- for s in sensors %}
      {%- set state = states[s] %}
      {%- if state %}
        <tr>
          <td align="center" style="color: {{ state.attributes.route_text_color }}">
          {{ state.attributes.label }}
          </td>
          <td align="center">{{ state.attributes.destination }}</td>
          <td align="center">
            {%- if state.attributes.time_until_departure -%}
            {{ state.attributes.time_until_departure }}
            {%- else -%}
            {{ state.attributes.realtime_time_local or (state.attributes.realtime_time | default(state.attributes.planned_time) | as_timestamp | timestamp_custom('%H:%M')) }}
            {%- endif -%}

          </td>
          <td align="center">{{ state.attributes.platform or '-' }}</td>
        </tr>
      {%- endif %}
    {%- endfor %}
  </table>

License

This project is licensed under the MIT License,
Forked from and based on the Home Assistant RNV integration.

Disclaimer: This project is an independent community integration and is not affiliated with or endorsed by Motis / Transitous.

About

๐ŸšŒ Custom Home Assistant integration for Motis/Transitous public transport departures.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%