From a5bcfca39ae1ad3e737db06fff1fa7c962242d3b Mon Sep 17 00:00:00 2001 From: Nils Reiners Date: Tue, 7 Oct 2025 22:29:49 +0200 Subject: [PATCH] =?UTF-8?q?st=C3=BCndliche=20Speicherung=20des=20Forecasts?= =?UTF-8?q?=20angepasst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 2edccf5..46f212a 100644 --- a/main.py +++ b/main.py @@ -63,10 +63,18 @@ while True: mode_as_binary = 1 db.store_data('sg_ready', {'mode': mode_as_binary}) - if now.minute == 0 and now.second == 0: - start_hour_local = (now + dt.timedelta(hours=1)).replace(minute=0, second=0, microsecond=0) - weather = weather_forecaster.get_hourly_forecast(start_hour_local, HORIZON_DAYS) - total = pv_plant.get_power(weather) - db.store_forecasts('pv_forecast', total) + if now >= next_forecast_at: + # Start der Prognose: ab der kommenden vollen Stunde + start_hour_local = (now + dt.timedelta(hours=1)).replace(minute=0, second=0, microsecond=0) + weather = weather_forecaster.get_hourly_forecast(start_hour_local, HORIZON_DAYS) + total = pv_plant.get_power(weather) + db.store_forecasts('pv_forecast', total) + + # Nächste geplante Ausführung definieren (immer volle Stunde) + # Falls wir durch Delay mehrere Stunden verpasst haben, hole auf: + while next_forecast_at <= now: + next_forecast_at = (next_forecast_at + dt.timedelta(hours=1)).replace(minute=0, second=0, microsecond=0) + + time.sleep(0.1)