Home Assistant integration to fetch public transport data for Tampere, Finland
Copy the files to your custom_components
folder or install as a HACS custom repository. More info on HACS here.
The integration can be set up from the frontend by searching for Nysse
.
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
Simple frontend examples using custom:html-template-card
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 %}
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 %}
- 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') }}
- Nysse API sometimes functions incorrectly. Errors logged with
Nysse API error
can be resolved on their own over time. - Line icons are resolved from a hardcoded list of tram lines. If new tram lines are built, the list needs to be updated in
const.py
.
If the integration is not working correctly, follow these steps as a first measure:
- Remove all files from
config/www/nysse
- Reload the integration
This forces the integration to fetch latest data from Nysse and recreates the database.