warrior25 / HA-Nysse

Home Assistant integration to fetch public transport data for Tampere, Finland
MIT License
7 stars 0 forks source link
finland home-assistant nysse public-transport tampere

HA-Nysse

hacs_badge

Introduction

Home Assistant integration to fetch public transport data for Tampere, Finland

Installation

Copy the files to your custom_components folder or install as a HACS custom repository. More info on HACS here.

Setup

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

The integration can be set up from the frontend by searching for Nysse.

Usage

Each station creates a sensor which contains data for departures from that station. Explanations for non self-explanatory attributes are listed below.

realtime - Indicates if the data is pulled from realtime vehicle monitoring or timetable data

Frontend examples

Simple frontend examples using custom:html-template-card

Example

type: custom:html-template-card
title: Keskustori D
ignore_line_breaks: true
content: >
  {% set departures = state_attr('sensor.keskustori_d_0015','departures')
  %} {% for i in range(0, departures | count, 1) %}

  <div style="display:grid; grid-template-columns: 2fr 1fr; font-size: 20px;
  padding: 10px 0px 0px 0px"> <div>{{ departures[i].line }} - {{
  departures[i].destination }}</div><div style="text-align: right">{% if
  departures[i].realtime %}<ha-icon style="color:green; padding: 0px 10px 0px
  0px" icon="mdi:signal-variant"></ha-icon>{% endif %} {% if
  departures[i].time_to_station | int < 21  %} {{departures[i].time_to_station}}
  min {% else %}{{departures[i].departure}}{% endif %}</div></div>

  {% endfor %}

Service Alerts

type: custom:html-template-card
ignore_line_breaks: true
title: Service Alerts
content: >
  {% set alerts = state_attr('sensor.nysse_service_alerts','alerts')
  %} {% for i in range(0, alerts | count, 1) %}

  <b>{{ alerts[i].start.strftime('%d.%m.%Y') }} - {{ alerts[i].end.strftime('%d.%m.%Y') }}</b><br>
  {{ alerts[i].description }}<br><br>

  {% endfor %}

Advanced usage

Combine data from multiple stops

 - platform: template
    sensors:
      combined_stops:
        value_template: "{{ states('sensor.stop1') }}"
        attribute_templates:
          departures: >-
            {% set combined_data = state_attr('sensor.stop1', 'departures') + state_attr('sensor.stop2', 'departures') %}
            {{ combined_data | sort(attribute='time_to_station') }}

Known issues / limitations

Troubleshooting

If the integration is not working correctly, follow these steps as a first measure:

  1. Remove all files from config/www/nysse
  2. Reload the integration

This forces the integration to fetch latest data from Nysse and recreates the database.