Skip to main content

Renfe smart home integration, free and open source

Renfe integration for Gladys Assistant

Spanish trains (Renfe): AVE, long distance, Cercanías; delays, cancellations, tracks.

Overview​

This integration brings the trains of Renfe, the Spanish railway operator, into Gladys: the long and medium distance (AVE, Avlo, Alvia, Intercity, Regional, Avant…) and the Cercanías and Rodalies of every núcleo (Madrid, Barcelona, Valencia, Sevilla, Bilbao…). It gives the next trains, corrected in real time, with their delay, at the stations you choose (three in the form, up to 10 more with a button), optionally towards a destination station (with the arrival time there) and for one line. The track of a Cercanías train is given once Renfe announces it. It also follows the traffic of up to six Cercanías lines (normal, traffic information, disrupted, heavily disrupted), with the alerts of Renfe: works, strikes, road replacement services. Each station and each line becomes a device to show on a dashboard and to use in scenes.

The data come from the official open data of Renfe (data.renfe.com), under the CC BY 4.0 licence: no account, no key. The two timetables (GTFS of the long distance and of the Cercanías) are downloaded only when Renfe publishes new ones, and kept by the integration. The real time (GTFS-RT) is read in one request per network for every followed station, every minute by default (every 10 minutes while no station announces anything in the next half hour, at night). The alerts are read every 5 minutes.

A train is followed in real time once it left its first station: its estimated time and its delay are given. Before that it is the timetable, marked "(timetable)". Cancelled trains and stations not served are shown.

This is a cloud integration: it contacts ssl.renfe.com (timetables) and gtfsrt.renfe.com (real time). Nothing else leaves your network.

Requirements​

  • Gladys Assistant 5.3.0 or later.
  • Nothing else: the open data of Renfe need no account and no key.

Configuration​

FieldWhat to type
Station 1, 2, 3The station as Renfe writes it: "Madrid-Atocha Cercanías", "Aranjuez", a part of it ("Chamartín") or its code.
DestinationOnly the trains calling afterwards at this station, with their arrival there. Empty: every train leaving.
LineOnly this line: a Cercanías line ("C3", "R2N") or a long distance product ("AVE", "Avlo"). Empty: every line.
Followed linesThe Cercanías lines whose traffic you follow, six at most: "C3 Madrid, R2N".
Reading of the real timeEvery 30 seconds, minute, 2 minutes or 5 minutes.
Language of the textsNames of the devices, summaries and outputs of the scenes. Station names and traffic messages stay in Spanish.

A station is one station of Adif, served by the long distance and the Cercanías alike: "Madrid-Atocha Cercanías" gives the C2 to C10 and the regional trains calling there; the high-speed trains leave from "Madrid-Puerta de Atocha-Almudena Grandes", another station. The Find a station button gives the stations holding a few words, with their code and their lines ("Madrid-Atocha Cercanías [18000] → Regional, C3 Madrid…"). A few words are enough when only one station holds them ("chamartin").

A Cercanías line is written with its núcleo when its name exists elsewhere ("C1" runs in ten núcleos): "C3 Madrid", "C1 Sevilla", "Rodalies R2"; alone, it is the one calling at your stations. Test the connection asks for the timetables again and reads each station and each line right away.

More stations than the three of the form (home, work, a weekly trip…): Add a station takes the same three fields — station, destination, line — and follows up to 10 more stations. List the stations shows every followed station, numbered; Remove a station takes that number (or the name). The added stations are kept in the configuration of Gladys, so they follow its backups.

The timetable of the Cercanías is a big file: the first reading, and the one of each new file, takes some 10 to 30 seconds.

Usage​

Devices​

In the Discover tab, create the devices you want:

  • Renfe <station> → <destination>: the next train as text ("C3 → Aranjuez · 3 min (+2 min late) · track 2 · arr. 23:13", "AVE 3063 → Barcelona-Sants · 06:27 (timetable)"), the wait of the next train and of the one after (minutes), and the delay of the next one (minutes, published only when it is followed in real time);
  • Renfe Cercanías Madrid C3, Renfe Rodalies R2N…: the traffic as text ("Disrupted traffic: Por obras de mejora…") and the number of traffic messages under way.

Without a train in the next four hours, the device shows the first one of each route in the next 24 hours.

Traffic​

Renfe publishes alerts for the Cercanías: a Spanish text, the lines concerned and their periods. The state of a line comes from its heaviest alert under way: heavily disrupted for an interruption or a road replacement service, disrupted for works, a strike, delays, modified frequencies, traffic information otherwise (lifts out of order, tickets); normal without an alert. An alert starting in the next three days is shown as coming. The alerts about a station only (a lift, an entrance) are left out. The long distance has no alerts: its delays and cancellations are those of the trains.

Dashboard widgets​

The Renfe departures widget at Madrid-Chamartín and the Renfe traffic widget of Cercanías lines of Madrid (generated illustration, not a screenshot)

  • Renfe departures: the next trains of a station, compact. One row per line and destination, with its next trains in a row ("8 · 52 min"). A cancelled train is shown ("cancelled 22:35") and turns the row orange, like a delay of 5 minutes or more. The Routes shown setting sets the number of rows. Choose a followed station, or type any station (and a line) in the widget settings. With Several stations, one widget shows several station devices: the devices of one station are merged under its name; for different stations, each opens with a row of its own.
  • Renfe traffic: the state of each line, then the alerts under way and those of the next three days, with their period. Tap a card for the full text. The followed lines, the ones typed in the settings, or the Cercanías lines of your stations when you follow none.

Scenes​

Triggers, once per change (the first reading is only a baseline):

  • Renfe: departure soon: a train of a followed station leaves in 2, 3, 5, 10, 15, 20 or 30 minutes, counted on its real-time estimate.
  • Renfe: train late: a train of a followed station leaving within two hours is 5, 10, 15, 30 or 60 minutes late or more, once per train and threshold.
  • Renfe: train cancelled: a train of a followed station leaving within two hours is cancelled, or does not stop there any more.
  • Renfe: line disrupted: a followed line becomes disrupted or heavily disrupted.
  • Renfe: back to normal: no disruption under way on the line any more.
  • Renfe: new traffic message: Renfe publishes an alert about a followed line, under way or coming.

Each gives a ready-made sentence, {{triggerEvent.data.summary}}, and its values (line, train number, destination, time, delay, track, title, text, start and end…). The actions Renfe: next trains and Renfe: traffic of a line return the same kind of values, to put in a message or to test in a condition.

Examples:

  • When your C3 to Aranjuez leaves in 10 minutes → turn the hall lamp green.
  • When your AVE to Barcelona is 15 minutes late or cancelled → send the summary to your phone before you leave.
  • Every weekday at 7:30 → read the next trains of your station and have the kitchen speaker announce them.

Transport​

Cloud only: the data come from the internet. The timetables when Renfe publishes new ones, the real time of the networks of your stations in one request each, the alerts every 5 minutes.

Troubleshooting​

  • "Unknown or ambiguous": use Find a station, then copy the exact name or the code in brackets; for a Cercanías line, add its núcleo ("C1 Sevilla").
  • "(timetable)" after a train: it has not left its first station yet, or Renfe does not follow it; the time is the one of the timetable.
  • No train towards the destination: the destination must be a station the trains call at after yours; check the name with Find a station, or empty the destination to see every train.
  • A strike, many cancelled trains: Renfe announces the cancellations of the day; they are shown for the next six hours, never for the following days.
  • "The open data of Renfe do not answer": the integration tries again at each reading; meanwhile the trains come from the timetables kept, and a reading of less than 3 minutes stands in for a refused one.
  • To report a problem: press Diagnostic, then copy the lines starting with "Renfe diagnostic" from the Logs tab into a GitHub issue or a reply on the forum, with the versions of Gladys and of the integration.

Configuration settings​

These are the settings Renfe asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
Renfe open datasectionNoThe trains come from the official open data of Renfe: the timetables (GTFS) of the long and medium distance (AVE, Avlo, Alvia, Intercity, Regional…) and of the Cercanías and Rodalies of every núcleo, and their real time (GTFS-RT: delays, cancellations, tracks, alerts). No account and no key: fill in your stations and lines below, then press "Test the connection".
Station 1sectionNoThe station where you take the train: its next departures, from the timetable corrected in real time, with their delay, their track (Cercanías) and their arrival at your destination.
StationstringNoIts name as Renfe writes it ("Madrid-Chamartín-Clara Campoamor", "Aranjuez"), a part of it when only one station holds it ("Chamartín"), or its code: the "Find a station" button gives them.
DestinationstringNoOnly the trains calling at this station afterwards, with their arrival time there. Empty for every train leaving the station.
LinestringNoOnly this line: a Cercanías line ("C3", "R2N") or a product of long distance ("AVE", "Avlo", "Regional"). Empty for every line.
Station 2sectionNo
StationstringNo
DestinationstringNoOnly the trains calling at this station afterwards, with their arrival time there. Empty for every train leaving the station.
LinestringNoEmpty for every line.
Station 3sectionNoMore stations (home, work, a weekly trip…): the "Add a station" button, under the form, follows up to 10 more, "List the stations" shows them all, numbered, and "Remove a station" stops following one.
StationstringNo
DestinationstringNoOnly the trains calling at this station afterwards, with their arrival time there. Empty for every train leaving the station.
LinestringNoEmpty for every line.
Traffic of the Cercanías linessectionNoThe Cercanías and Rodalies lines whose traffic you follow: a device per line, with its state (normal, traffic information, disrupted, heavily disrupted) worked out from the alerts of Renfe, and its messages (works, strikes, road replacement services), read every 5 minutes. The long distance trains have no alerts: their delays and cancellations are on the stations.
Followed linesstringNoUp to 6, separated by commas, with their núcleo ("C3 Madrid", "C1 Sevilla", "R2N"), or without when your stations tell it.
OptionssectionNo
Reading of the real timeselectNoHow often the real time is read: one request per network for every followed station. While no station announces anything in the next half hour (at night), every 10 minutes. The timetables are read once a day.
Language of the textsselectNoNames of the devices, summaries and outputs of the scenes. Automatic: the language of your dashboard, as soon as a Renfe widget has been shown. Station names and traffic messages stay in Spanish.

How to install Renfe in Gladys​

  1. In Gladys, open Integrations: Renfe appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/william-de71/gladys-renfe:0.1.0), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/William-De71/gladys-renfe.

Renfe requires Gladys >=5.3.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

Renfe is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by William-De71, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂