Zum Hauptinhalt springen

Trafikverket road weather Smart-Home-Integration, kostenlos und Open Source

Trafikverket road weather-Integration für Gladys Assistant

Unofficial connector: road weather stations of Trafikverket (Sweden), read only.

Info

Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfügbar.

Unofficial connector, not affiliated with Trafikverket (the Swedish Transport Administration). It brings into Gladys the measurements of the road weather stations you choose along the Swedish roads (air and road surface temperature, dew point, humidity, wind, precipitation, ice, snow and water on the road), read through the official open API of Trafikverket with a free API key of your own.

This integration has never been tested with a real key. It follows pytrafikverket, the library of the Home Assistant integration, and the documentation of the API. Please report what you see on the Gladys forum.

What you get​

One Gladys device per station, named "Trafikverket <station>", with the sensors the station has:

SensorUnitNotes
Air temperature°C
Road temperature°Cprobe (kept out of the room average)
Dew point°Cprobe (kept out of the room average)
Humidity%
Visibilitymnot every station measures it
Wind speed, wind gust (30 min)m/s10 minute average; highest 3 s gust
Wind directiondegree
Precipitationmm/hwater of the last 30 minutes, times 2
Rain (30 min)yes/norain seen in the last 30 minutes
Snowfall (30 min)yes/nosnow seen in the last 30 minutes
Ice, snow, water on the roadyes/nowhat the road sensor sees (frost, ice)
Ice depth, snow depth, water depthmmon the road surface
  • Only what the station sends is created; a sensor once created is never removed from the device.
  • The units are those Gladys lists for each kind of sensor; the API already sends them, only the precipitation is converted (mm per 30 minutes to mm/h). The yes/no sensors are read only: nothing can switch them.
  • The names of the sensors are in English; rename them when you create them if you wish.
  • Trains, ferries and traffic cameras of Trafikverket are not part of this integration.

Installation​

  1. Create a free account on data.trafikverket.se and get an API key there.
  2. Install the integration from the Gladys catalog (Gladys 5.1 or newer).
  3. In the Configuration screen, paste the key and enter up to five stations: the name exactly as Trafikverket writes it on the map of its road weather stations ("Kungälv"), or the id of the station (it starts with "SE_STA_VVIS"). Upper and lower case do not matter.
  4. Click Test Trafikverket: the message shows the last measurement of each station and its age.
  5. Open the Discovery tab and add the devices. Their values arrive as soon as they are created, if the last measurement is recent.

Configuration​

FieldDefaultWhat it does
API keyyour key of the open API
Station 1 – 5a station name or id
Read interval10 min5 to 60 minutes; one request for all the stations each time

The API key is kept by Gladys in its database, never shown again; it is sent only to Trafikverket (api.trafikinfo.trafikverket.se), in the body of the query, never in a URL nor a log, and never written under /data.

A name shared by several stations is refused: the status then lists their ids, enter one of them. A station not found is named by its number in the status ("Station 3 not found"): what you typed is never shown again there.

How it works​

  • One request for all your stations at each interval. Nothing reads sooner: neither the test button, nor a reconnection to Gladys, nor a saved configuration, nor a restart of the container (the instant of the last request is kept under /data). A new key is tried a minute after the last request.
  • Fresh measurements only. Each measurement carries the instant the station made it. A measurement is published only when it is newer than the last one published for that station (its raw time and instant are kept under /data, so a clean restart does not publish it again) and recent: at most one hour old (two intervals if longer, never more than two hours), measured on the clock of Trafikverket. A hard stop (power cut, docker kill) within the minute after a read may publish the last measurement once more after the restart, never past that age limit. A station that stopped measuring shows "no recent measurement" in the status and publishes nothing.
  • Key refused (HTTP 401 or 403): the integration stops asking; the status says "API key refused" as long as the refusal holds. The refusal is kept under /data (only a salted fingerprint of the refused key, never the key) and survives a restart. It is lifted when you enter another key, or when the test button succeeds (it tries once, when the interval has passed).
  • Too many requests (429) or the service down (5xx): a pause, from the Retry-After of the answer, else 5 minutes doubling at each new failure, between 1 minute and 6 hours, kept under /data.
  • Other failures: tried again at the next interval. The status tells "query refused by Trafikverket" (another HTTP 4xx, or an error in the answer) from "no answer" (network, timeout); "(pause)" is shown only while a pause runs.
  • A station name holding a control character, a bidirectional control, a line separator or a character XML forbids is refused, named by its number; such characters are also removed from the names Trafikverket sends.
  • The answer is bounded (256 KB) and read as JSON; the stations are matched to your entries by their id or name.

Read only​

The integration only sends the query of the open API. It has no command and changes nothing anywhere.

Credits​

The query and the fields read come from pytrafikverket (https://github.com/gjohansson-ST/pytrafikverket, MIT license), ported to JavaScript; see THIRD_PARTY_NOTICES.md.

Konfigurationseinstellungen​

Diese Einstellungen fragt Trafikverket road weather in seinem Konfigurationsbildschirm in Gladys ab.

EinstellungTypPflichtfeldBeschreibung
Trafikverket in GladyssectionNeinUnofficial connector, not affiliated with Trafikverket (the Swedish Transport Administration). It reads the road weather stations you choose through the official open API of Trafikverket: air and road surface temperature, dew point, humidity, wind, precipitation, ice, snow and water on the road. You need a free API key of your own (data.trafikverket.se). Read only: nothing is ever sent but the query. Trains, ferries and traffic cameras are not part of this integration. Never tested with a real key yet.
API keysecretNeinYour key of the Trafikverket open API (data.trafikverket.se, free account). Kept by Gladys in its database, never shown again; sent only to Trafikverket (api.trafikinfo.trafikverket.se), in the body of the query, never in a URL nor a log.
Road weather stationssectionNeinUp to five stations: the name exactly as Trafikverket writes it on its map ("Kungälv"), or the id of the station (it starts with "SE_STA_VVIS"). A name shared by several stations is refused: the status then lists their ids.
Station 1stringNein
Station 2stringNein
Station 3stringNein
Station 4stringNein
Station 5stringNein
Read interval (minutes)numberNeinOne request for all the stations each time. Nothing reads sooner, not even the test button or a restart. The stations measure every 10 to 30 minutes.

So installierst du Trafikverket road weather in Gladys​

  1. Öffne in Gladys Integrationen: Trafikverket road weather erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
  2. Klicke auf Installieren. Gladys lädt das Docker-Image (ghcr.io/lm1lc3n7/gladys-trafikverket:0.1.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die Oberfläche der Integration (Geräte, Erkennung und Konfiguration).
  3. Öffne den Bildschirm Konfiguration der Integration, fülle die Einstellungen aus und speichere.
  4. Du kannst sie auch direkt über die URL ihres Repositorys installieren: https://github.com/LM1LC3N7/gladys-trafikverket.

Trafikverket road weather benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stündlich aktualisiert, eine neue Version ist also spätestens eine Stunde nach ihrer Veröffentlichung verfügbar.

Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.

Über externe Integrationen​

Trafikverket road weather ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und führt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LM1LC3N7 veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.

Abonniere den Newsletter von Gladys Assistant

Ein paar E-Mails im Monat zu neuen Releases und Neuigkeiten aus dem Projekt. Verschickt von Pierre-Gilles Leymarie, dem Gründer des Projekts. Jederzeit abbestellbar 🙂