weather: fetch and expose precipitation and snowfall

This commit is contained in:
Richard Zink committed 2026-10-12 22:15:16 +02:00
1 parent e3250a34da
commit c769a6dff3
2 files changed
+62 -2

No files matched your search

+49 -2
View File
@@ -2131,10 +2131,21 @@ window.weatherThemes = {
}
function fetchWeather() {
var WEATHER_CFG = (window.CONFIG && window.CONFIG.weather) || {};
var currentFields = ['temperature_2m', 'relative_humidity_2m', 'weather_code', 'wind_speed_10m', 'wind_direction_10m'];
var hourlyFields = ['temperature_2m', 'weather_code', 'wind_speed_10m', 'wind_direction_10m'];
if (WEATHER_CFG.precipitation !== false) {
currentFields.push('precipitation');
hourlyFields.push('precipitation');
}
if (WEATHER_CFG.snowfall !== false) {
currentFields.push('snowfall');
hourlyFields.push('snowfall');
}
var url = 'https://api.open-meteo.com/v1/forecast?latitude=' + WEATHER_LAT +
'&longitude=' + WEATHER_LON +
'&current=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m,wind_direction_10m' +
'&hourly=temperature_2m,weather_code,wind_speed_10m,wind_direction_10m' +
'&current=' + currentFields.join(',') +
'&hourly=' + hourlyFields.join(',') +
'&daily=weather_code,temperature_2m_max,temperature_2m_min' +
'&timezone=Europe/Berlin&forecast_days=5';
@@ -2151,6 +2162,15 @@ window.weatherThemes = {
speedKmh: Number(data.current.wind_speed_10m || 0),
dirDeg: Number(data.current.wind_direction_10m || 0)
};
window.__currentWeather = {
code: Number(data.current.weather_code || 0),
tempC: Number(data.current.temperature_2m || 0),
humidity: Number(data.current.relative_humidity_2m || 0),
precipMm: Number(data.current.precipitation || 0),
snowMm: Number(data.current.snowfall || 0),
windKmh: Number(data.current.wind_speed_10m || 0),
windDirDeg: Number(data.current.wind_direction_10m || 0)
};
// while the weather sim runs it owns the theme - a live
// poll must not override the configured test weather
if (!__weatherSimActive)
@@ -2171,6 +2191,15 @@ window.weatherThemes = {
speedKmh: Number(rec.json.current.wind_speed_10m || 0),
dirDeg: Number(rec.json.current.wind_direction_10m || 0)
};
window.__currentWeather = {
code: Number(rec.json.current.weather_code || 0),
tempC: Number(rec.json.current.temperature_2m || 0),
humidity: Number(rec.json.current.relative_humidity_2m || 0),
precipMm: Number(rec.json.current.precipitation || 0),
snowMm: Number(rec.json.current.snowfall || 0),
windKmh: Number(rec.json.current.wind_speed_10m || 0),
windDirDeg: Number(rec.json.current.wind_direction_10m || 0)
};
if (!__weatherSimActive)
setWeatherTheme(getWeatherThemeName(currentWeatherCode));
updateWeatherDisplay();
@@ -2234,6 +2263,15 @@ window.weatherThemes = {
dirDeg: Number(hourly.wind_direction_10m[curIdx] || 0)
};
}
window.__currentWeather = {
code: Number(curCode || 0),
tempC: Number(curTemp || 0),
humidity: Number(current.relative_humidity_2m || 0),
precipMm: Number((hourly.precipitation && hourly.precipitation[curIdx]) || 0),
snowMm: Number((hourly.snowfall && hourly.snowfall[curIdx]) || 0),
windKmh: Number(window.__currentWind ? window.__currentWind.speedKmh : 0),
windDirDeg: Number(window.__currentWind ? window.__currentWind.dirDeg : 0)
};
if (!__weatherSimActive && curCode !== currentWeatherCode) {
currentWeatherCode = curCode;
setWeatherTheme(getWeatherThemeName(curCode));
@@ -2256,6 +2294,15 @@ window.weatherThemes = {
speedKmh: Number(curWindSpeed || 0),
dirDeg: Number(curWindDir || 0)
};
window.__currentWeather = {
code: Number(curCode || 0),
tempC: Number(curTemp || 0),
humidity: Number(current.relative_humidity_2m || 0),
precipMm: Number(current.precipitation || 0),
snowMm: Number(current.snowfall || 0),
windKmh: Number(curWindSpeed || 0),
windDirDeg: Number(curWindDir || 0)
};
var windDisplay = currentUnits === 'imperial'
? Math.round(curWindSpeed * 0.621371) + ' mph'
: Math.round(curWindSpeed) + ' km/h';