diff --git a/src/routes/api/strommix/+server.ts b/src/routes/api/strommix/+server.ts index ae40176..661bbaf 100644 --- a/src/routes/api/strommix/+server.ts +++ b/src/routes/api/strommix/+server.ts @@ -127,7 +127,7 @@ async function fetchPriceAtNow( } export const GET: RequestHandler = async ({ fetch }) => { - const [smard, energyCharts, cross, priceDe, priceFr] = await Promise.all([ + const [smardRaw, energyCharts, cross, priceDe, priceFr] = await Promise.all([ fetchSmardSnapshot(fetch), // Energy-Charts via the CMS — used as per-field fallback when SMARD // returns null for a specific filter (notably load 410 when SMARD's @@ -138,6 +138,17 @@ export const GET: RequestHandler = async ({ fetch }) => { fetchPriceAtNow("FR", fetch), ]); + // SMARD aligned-min picks the earliest "latest" across filters. If + // one filter (typically load 410) lags 12+ hours, the snapshot ends + // up labelled with a stale timestamp like "12:15 Uhr morgens" while + // newer Energy-Charts data is right there. Discard the SMARD snapshot + // when it is older than 90 min so the aggregator falls back to + // Energy-Charts entirely. 90 min lets typical 30–60 min SMARD lag + // still win. + const nowSec = Math.floor(Date.now() / 1000); + const smard = + smardRaw && nowSec - smardRaw.measuredAtUnix < 90 * 60 ? smardRaw : null; + const ec = energyCharts.data ?? {}; // Per-field fallback. SMARD value `null` = filter unavailable; we