HomeAssistant 2024.7: Emulating obsoleted weather forecast entities using template sensors
Since HomeAssistant 2024.7, the weather data provider integration OpenWeatherMap no longer provides forecast data as sensor entities. This mini-tutorial shows how to continue providing the sensor entities using templates with periodical service calls.
Update 2024-10-20: In Home Assistant 2024.8 services have been renamed to actions, which also changes the keyword service to action. The listing has been updated accordingly. Also the trigger has been changed from once per minute to changes of state of the weather entity, with additional trigger once per hour for fallback reasons, as the OpenWeatherMap integration does not guarantee a state change for every update.
With the release of HomeAssistant 2024.7, there were changes to the weather platform. The release notes mention that the previously deprecated service weather.get_forecast has been replaced by weather.get_forecast, but in the same context, the sensor.openweathermap_forecast_* entities of the weather provider integration OpenWeatherMap with the forecast values for the current day have also been removed.
However, these can easily be replaced by template sensors that obtain the data at regular intervals via the weather.get_forecasts service. Assuming that the OpenWeatherMap main entity is named weather.home, the following template sensor snippet emulates all the removed forecast entities. The trigger updates the values of the sensor entities once per minute from the integration's cache, since the forecast for the current day may change several times.
The procedure for activating the snippet is:
If necessary, adapt the snippet above to your local conditions, in particular the ID of the weather entity must match, and if friendly names or entity IDs of the integrated had previously been changed manually, the name: and unique_id: properties of the new sensors will need to be adapted.
In HomeAssistant, add the customized snippet to the file /homeassistant/configuration.yaml or an included split configuration. If a template: section already exists, add the templates to this existing section.
Delete the entities that are no longer available or rename their entity IDs via Settings ➔ Devices & Services ➔ Entities.
Use Developer Tools ➔ YAML to check the configuration for correctness, and if everything is OK, reload the template entities or restart HomeAssistant.
Now the forecast entities should be available again as usual, with the difference that they are listed as provided by the template integration. After the first trigger by a state change of the weather entity, or at the latest on the next full hour, the sensors should also provide the usual data again.