weather.yr

Fetches a forecast from the Norwegian Meteorological Institute’s Locationforecast API (yr.no).

sources:
  weather:
    source: weather.yr
    params:
      lat: 55.64277
      lon: 13.20638
      altitude: 17

Params

pydantic model todays_paper_web.widgets.weather.yr.YrParams[source]

Bases: DataSourceParams

field altitude: Number [Required]

Site altitude in meters - the API uses this to adjust the forecast.

field lat: Number [Required]

Latitude to forecast for.

field lon: Number [Required]

Longitude to forecast for.

Returns

A WeatherForecastModel, with one method:

  • .nextHour(timestamp, hour) -> WeatherForecast | None — the forecast entry closest to hour on the day of timestamp (or the next day, if hour has already passed relative to timestamp), with its own .timestamp adjusted into timestamp’s timezone.

Each WeatherForecast has:

Field

Type

Description

timestamp

datetime

When this forecast entry is for.

icon

WeatherIcon

The condition + time of day; .id() gives the string (e.g. "01d") that Image widgets: <image>, <gocomics>, <weather.icon>’s <weather.icon> expects.

airTemperature

float | None

Degrees Celsius.

windSpeed

float | None

Meters/second.

precipitation

float | None

Always None for weather.yr currently — the field exists on the model but this source doesn’t populate it.

relativeHumidity, windGustSpeed

float | None

Same — present on the model, not populated by weather.yr.

Used together with <weather.icon> in a template:

{% set forecast = source('weather').nextHour(timestamp, 8) %}
<box>
    <text valign="middle">{{ forecast.timestamp.strftime('%H:%M') }}</text>
    <weather.icon x="125" valign="middle" icon="{{ forecast.icon.id() }}" theme="erikflower" />
    <text x="225" valign="middle">{{ forecast.airTemperature }}°C</text>
    <text x="400" valign="middle">{{ forecast.windSpeed|round|int }} m/s</text>
</box>