Saltar al contenido principal

Integración domótica Mapbox Traffic, gratuita y de código abierto

Integración Mapbox Traffic para Gladys Assistant

Live traffic on your routes: travel time, delay, charts and traffic jam alerts via Mapbox.

info

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

Track the travel time of your usual routes (home → work, school…) with live traffic, see it as a chart and get notified of traffic jams or abnormally long trips. Data comes from the Mapbox Directions API (driving-traffic profile).

What you get​

One route device per configured route (up to 3), with:

FeatureDescription
Travel timeDuration with the current traffic, in minutes (kept in history)
Usual travel timeTypical duration at this time of the week according to Mapbox
DelayDifference between both, in minutes
DistanceLength of the recommended route, in km
Traffic level0 fluid, 1 moderate, 2 traffic jam, 3 severe jam
TrafficThe same level as a text
ViaThe main roads taken ("A86, A1")

Plus:

  • a dashboard widget "Travel time": duration, delay, chart of the current vs usual travel time, traffic status and a "Refresh" button;
  • four scene triggers: Traffic jam on a route, Traffic jam cleared, Abnormally long travel time, Travel time back to normal;
  • a scene action Get the travel time of a route, e.g. to send "32 min (+7 min) · Moderate" every morning.

Setup​

  1. Create a free account on mapbox.com and copy your default public access token (it starts with pk.). The free tier includes 100,000 route requests a month.
  2. In the integration Configuration tab, paste the token.
  3. Fill in at least route 1:
    • Name: "Work" for instance;
    • Origin: leave empty to start from the home location set in Gladys (Settings → Houses), or type an address or coordinates;
    • Destination: an address or "latitude, longitude" coordinates ("48.8924, 2.2369", as copied from Google Maps with a right click).
  4. Click Test Mapbox: the current travel time of route 1 shows under the button.
  5. Open the Discovery tab and add your routes.

Refresh​

  • Interval: 300 s by default (60 s minimum).
  • Active days / Active hours: only query Mapbox when it matters, e.g. Monday to Friday, 07:00-09:30, 16:30-19:00. Empty means always. Hours are read in the configured timezone (Europe/Paris by default).
  • Avoid: tolls, motorways, ferries.

Mapbox free plan​

The Directions API includes 100,000 free requests a month; beyond that, Mapbox bills the extra requests (see the Mapbox pricing). The integration makes one request per route at every refresh, and geocodes each address only once. Monthly usage ≈ routes × refreshes per hour × active hours per day × days.

For example, 3 routes refreshed every 5 minutes for 5 hours each working day use about 4,000 requests a month, and about 26,000 when refreshed all day long: both stay within the free plan. Refreshing 3 routes every minute, 24/7, uses about 130,000 requests and goes over it.

Your actual usage is shown in your Mapbox account.

Alerts​

  • Traffic jam: at least 10 % (configurable) of the distance is in heavy congestion according to Mapbox, or the trip is clearly longer than usual (+35 %).
  • Abnormally long: the travel time exceeds the usual one by 30 % and by at least 5 minutes (both configurable), so a short trip going from 4 to 6 minutes does not alert.

Scene examples​

  • Traffic jam alert: trigger Traffic jam on a route (route "Work"), action "Send a message": Jam to work: {{triggerEvent.data.summary}}.
  • Morning briefing: at 7 a.m. on weekdays, action Get the travel time of a route, then "Send a message" with the Summary (or Travel time (min)) variable produced by the previous action.
  • Personal threshold: the route is a standard Gladys device, so the native "Device value" trigger works too: "when Travel time (Work) > 45".

Event triggers only fire on a change (a single "Traffic jam" while the jam lasts).

Troubleshooting​

  • "Mapbox refused the access token": check the token on account.mapbox.com.
  • Address not found: use a more complete address, or coordinates.
  • "the home has no location": set the home location in Gladys, or fill in the origin.
  • The integration logs (Logs tab, or docker logs) detail every refresh; set LOG_LEVEL=debug to see the requests (the token is masked).

Parámetros de configuración​

Estos son los parámetros que Mapbox Traffic te pide en su pantalla de configuración en Gladys.

ParámetroTipoObligatorioDescripción
Mapbox accountsectionNoCreate a free Mapbox account and copy your default public access token (it starts with pk.).
Mapbox free plansectionNoThe Directions API includes 100,000 free requests a month; beyond that, Mapbox bills the extra requests. This integration makes one request per route at every refresh (addresses are geocoded only once). Monthly usage ≈ routes × refreshes per hour × active hours per day × days. Examples: 3 routes every 5 min, 5 h per working day ≈ 4,000 requests (free); 3 routes every 5 min, 24/7 ≈ 26,000 (free); 3 routes every minute, 24/7 ≈ 130,000 (over the free plan). Use the active days and hours below to stay well within it.
Mapbox access tokensecretSí
Language of the textsselectNo
Route 1sectionNoA place is either an address ("10 rue de Rivoli, Paris") or coordinates as "latitude, longitude" ("48.8566, 2.3522", as copied from Google Maps). Leave the origin empty to start from the home location set in Gladys. Leave the destination empty to disable the route.
NamestringNo
Origin (leave empty to start from your home)stringNo
DestinationstringSí
Route 2sectionNoOptional extra route, same format as route 1.
NamestringNo
Origin (leave empty to start from your home)stringNo
DestinationstringNo
Route 3sectionNoOptional extra route, same format as route 1.
NamestringNo
Origin (leave empty to start from your home)stringNo
DestinationstringNo
RefreshsectionNoRoutes are only refreshed during the active days and hours, to save your Mapbox quota. Leave them empty to refresh all the time.
Refresh interval (s)numberNo
Active days (empty = every day)multi_selectNo
Active hours (empty = all day)stringNo
TimezonestringNo
Avoidmulti_selectNo
AlertssectionNoA traffic jam is detected when at least the given share of the route is in heavy congestion. The travel time is abnormally long when it exceeds the usual one by both the given percentage and the given number of minutes. Both fire scene triggers.
Traffic jam: congested share of the route (%)numberNo
Abnormal: longer than usual by (%)numberNo
Abnormal: and at least (min) latenumberNo

Cómo instalar Mapbox Traffic en Gladys​

  1. En Gladys, abre Integraciones: Mapbox Traffic 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/quentinlegay/gladys-mapbox-traffic:1.0.3), 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/quentinlegay/Gladys-mapbox-traffic.

Mapbox Traffic 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​

Mapbox Traffic 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 quentinlegay, 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 🙂