For home assistant, I would like to expand the forecasts, so that it is easier to interpret the forecast times. More precisely, I would like to have the forecasts relative to the latest_update, so for latest_update+1 hours, latest_update+2 hours, etc. For readibility, let's floor the latest_update to the hour. I would like to add more options for hours than what the advices give, i.e. we can have forecasts for hour=1,2,3,6,9,12,18 while the advices are only for 4:00, 10:00, 16:00 and 22:00
In code, this would imply something like changing the end of the function get_forecast_array to:
dt = datetime.strptime(runtime, "%d-%m-%Y %H:%M")
localdt = dt.astimezone(pytz.timezone("Europe/Amsterdam"))
last_updated=self._last_updated.replace(second=0, microsecond=0, minute=0)
local_last_updated=last_updated.astimezone(pytz.timezone("Europe/Amsterdam"))
for offset in [1,2,3,6,9,12,18]:
gf=self.get_forecast_at_offset(localdt, local_last_updated,offset, advice)
forecast.append(gf)
and changing the function get_forecast_at_offset to:
def get_forecast_at_offset(
self, runtime: datetime, last_updated: datetime, offset: int, advice: bool
) -> dict:
"""Get forecast at a certain offset."""
offset_from_last_updated=int(offset+(last_updated-runtime).total_seconds()/3600)
offset_advice=min(18,6*(offset_from_last_updated//6))
if offset_from_last_updated>0:
dt = {"offset":offset,"datetime": (runtime + timedelta(hours=offset_from_last_updated)).isoformat()}
forecast = (
{"advice": self.get_color(self.get_property("advies_" + str(offset_advice)))}
)
dt.update(forecast)
return dt
else:
return False
An example output on 2025-02-11 14:31 could have the following raw advice:
model_runtime: 11-02-2025 10:00
advice_0: code_yellow
advice_6: code_orange
advice_12: code_red
advice_18: code_yellow
The forecast datapoints for offset=1,2,3,6,9,12 would be calculated as:
forecast_advice: [
{'offset': 1, 'datetime': '2025-02-11T15:00:00+01:00', 'advice': 'code_yellow'},
{'offset': 2, 'datetime': '2025-02-11T16:00:00+01:00', 'advice': 'code_orange'},
{'offset': 3, 'datetime': '2025-02-11T17:00:00+01:00', 'advice': 'code_orange'},
{'offset': 6, 'datetime': '2025-02-11T20:00:00+01:00', 'advice': 'code_orange'},
{'offset': 9, 'datetime': '2025-02-11T23:00:00+01:00', 'advice': 'code_red'},
{'offset': 12, 'datetime': '2025-02-12T02:00:00+01:00', 'advice': 'code_red'},
{'offset': 18, 'datetime': '2025-02-12T08:00:00+01:00', 'advice': 'code_yellow'}
]
With this information, it should be fairly easy to make attributes in the HomeAssistant sensor for forecast_1_hour_ahead,
forecast_2_hour_ahead, forecast_12_hour_ahead, etc by parsing the json.
For home assistant, I would like to expand the forecasts, so that it is easier to interpret the forecast times. More precisely, I would like to have the forecasts relative to the latest_update, so for latest_update+1 hours, latest_update+2 hours, etc. For readibility, let's floor the latest_update to the hour. I would like to add more options for hours than what the advices give, i.e. we can have forecasts for hour=1,2,3,6,9,12,18 while the advices are only for 4:00, 10:00, 16:00 and 22:00
In code, this would imply something like changing the end of the function get_forecast_array to:
and changing the function get_forecast_at_offset to:
An example output on 2025-02-11 14:31 could have the following raw advice:
model_runtime: 11-02-2025 10:00
advice_0: code_yellow
advice_6: code_orange
advice_12: code_red
advice_18: code_yellow
The forecast datapoints for offset=1,2,3,6,9,12 would be calculated as:
forecast_advice: [
{'offset': 1, 'datetime': '2025-02-11T15:00:00+01:00', 'advice': 'code_yellow'},
{'offset': 2, 'datetime': '2025-02-11T16:00:00+01:00', 'advice': 'code_orange'},
{'offset': 3, 'datetime': '2025-02-11T17:00:00+01:00', 'advice': 'code_orange'},
{'offset': 6, 'datetime': '2025-02-11T20:00:00+01:00', 'advice': 'code_orange'},
{'offset': 9, 'datetime': '2025-02-11T23:00:00+01:00', 'advice': 'code_red'},
{'offset': 12, 'datetime': '2025-02-12T02:00:00+01:00', 'advice': 'code_red'},
{'offset': 18, 'datetime': '2025-02-12T08:00:00+01:00', 'advice': 'code_yellow'}
]
With this information, it should be fairly easy to make attributes in the HomeAssistant sensor for forecast_1_hour_ahead,
forecast_2_hour_ahead, forecast_12_hour_ahead, etc by parsing the json.