Saltar al contenido principal

Integración domótica Trafikverket road weather, gratuita y de código abierto

Integración Trafikverket road weather para Gladys Assistant

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

info

La documentación de esta integración la escribe su autor y, por ahora, solo está disponible en inglés.

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.

Parámetros de configuración​

Estos son los parámetros que Trafikverket road weather te pide en su pantalla de configuración en Gladys.

ParámetroTipoObligatorioDescripción
Trafikverket in GladyssectionNoUnofficial 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 keysecretNoYour 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 stationssectionNoUp 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 1stringNo
Station 2stringNo
Station 3stringNo
Station 4stringNo
Station 5stringNo
Read interval (minutes)numberNoOne 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.

Cómo instalar Trafikverket road weather en Gladys​

  1. En Gladys, abre Integraciones: Trafikverket road weather aparece en el catálogo junto a las integraciones nativas, con una insignia de comunidad.
  2. Haz clic en Instalar. Gladys descarga la imagen Docker (ghcr.io/lm1lc3n7/gladys-trafikverket:0.1.1), la ejecuta en un entorno aislado del núcleo y genera la interfaz de la integración (dispositivos, descubrimiento y configuración).
  3. Abre la pantalla de Configuración de la integración, rellena los parámetros y guarda.
  4. También puedes instalarla directamente desde la URL de su repositorio: https://github.com/LM1LC3N7/gladys-trafikverket.

Trafikverket road weather requiere Gladys >=5.1.0. El catálogo de Gladys se actualiza cada hora, así que una nueva versión está disponible como máximo una hora después de publicarse.

¿Todavía no usas Gladys? Es gratuito y de código abierto: sigue la guía de instalación para empezar.

Sobre las integraciones externas​

Trafikverket road weather es una integración externa: una integración comunitaria empaquetada como contenedor Docker y publicada en GitHub. Gladys la instala con un clic y la ejecuta en un entorno aislado del núcleo. La publica y mantiene LM1LC3N7, no el equipo principal de Gladys.

Suscríbete a la newsletter de Gladys Assistant

Unos pocos correos al mes sobre nuevas versiones y novedades del proyecto. Enviados por Pierre-Gilles Leymarie, fundador del proyecto. Puedes darte de baja cuando quieras 🙂