Adios
BlogWorkflows

Workflows

Two ways to store weather data in PostgreSQL

Poll a weather API every 15 minutes or let a station push a webhook. Both Adios workflows record who reported each measurement, when, and in which unit.

Adios Team2 min read

At noon, a Madrid rooftop station reports 12.4 °C. What did the weather API report for the same place and time? Two small workflows can collect the readings, and one SQL query can put them side by side.

Pull when the provider offers a read API

Open-Meteo exposes current conditions by latitude and longitude. The scheduled recipe fetches Madrid’s temperature and relative humidity every 15 minutes. Each response carries a time for the conditions it describes. Saving that time lets a later poll recognize a reading it has already collected.

GET /v1/forecast?latitude=40.42&longitude=-3.70&current=temperature_2m,relative_humidity_2m&temperature_unit=celsius&timeformat=unixtime

Accept a push when the station has a reading

A station that supports webhooks can post both measurements as soon as it samples them. Give it a dedicated URL and shared secret. The receiving workflow labels the rows with the station’s identity, so the sender only needs to supply the time and values.

Here is the body for the noon example. The webhook acknowledges receipt immediately. Open the run to see when PostgreSQL finishes the write.

{ "timestamp": 1796299200, "temperature_c": 12.4, "humidity_pct": 68 }

Compare measurements from the two sources

Each workflow writes two rows per observation. Both call the metrics temperature and relative_humidity and use the same units. The source distinguishes the model’s estimate for Madrid from the rooftop measurement. If the timestamp and metric match a previous reading from that source, the database keeps the first value.

This query pairs temperatures recorded at the same instant. An empty result means the sources have no matching temperature timestamps. If the station samples between polling slots, group the readings into a common time window before comparing them.

SELECT api.observed_at, api.metric_value AS api_c,
       station.metric_value AS rooftop_c
FROM weather_readings AS api
JOIN weather_readings AS station
  USING (observed_at, metric_type, unit)
WHERE api.source = 'open-meteo:madrid'
  AND station.source = 'station:madrid-rooftop'
  AND api.metric_type = 'temperature'
ORDER BY api.observed_at DESC;
  All articles