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.

· 2 Minuten zu lesen
HomeAssistant 2024.7: Emulating obsoleted weather forecast entities using template sensors
Forecast entities no longer available in HomeAssistant 2024.7
🇩🇪
Dieser Artikel ist auch auf Deutsch verfügbar.

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.

template:
  - trigger:
      - platform: time_pattern
        minutes: /1
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.home
        response_variable: daily
    sensor:
      - name: OpenWeatherMap Forecast Cloud coverage
        unique_id: openweathermap_forecast_cloud_coverage
        state: "{{ daily['weather.home'].forecast[0].cloud_coverage }}"
        unit_of_measurement: '%'
      - name: OpenWeatherMap Forecast Condition
        unique_id: openweathermap_forecast_condition
        state: "{{ daily['weather.home'].forecast[0].condition }}"
      - name: OpenWeatherMap Forecast Precipitation
        unique_id: openweathermap_forecast_precipitation
        state: "{{ daily['weather.home'].forecast[0].precipitation }}"
        unit_of_measurement: mm
        device_class: precipitation
      - name: OpenWeatherMap Forecast Precipitation probability
        unique_id: openweathermap_forecast_precipitation_probability
        state: "{{ daily['weather.home'].forecast[0].precipitation_probability }}"
        unit_of_measurement: '%'
      - name: OpenWeatherMap Forecast Pressure
        unique_id: openweathermap_forecast_pressure
        state: "{{ daily['weather.home'].forecast[0].pressure }}"
        unit_of_measurement: hPa
        device_class: pressure
      - name: OpenWeatherMap Forecast Temperature
        unique_id: openweathermap_forecast_temperature
        state: "{{ daily['weather.home'].forecast[0].temperature }}"
        unit_of_measurement: °C
        device_class: temperature
      - name: OpenWeatherMap Forecast Temperature Low
        unique_id: openweathermap_forecast_temperature_low
        state: "{{ daily['weather.home'].forecast[0].templow }}"
        unit_of_measurement: °C
        device_class: temperature
      - name: OpenWeatherMap Forecast Time
        unique_id: openweathermap_forecast_time
        state: "{{ daily['weather.home'].forecast[0].datetime }}"
        device_class: timestamp
      - name: OpenWeatherMap Forecast Wind bearing
        unique_id: openweathermap_forecast_wind_bearing
        state: "{{ daily['weather.home'].forecast[0].wind_bearing }}"
        unit_of_measurement: °
      - name: OpenWeatherMap Forecast Wind speed
        unique_id: openweathermap_forecast_wind_speed
        state: "{{ daily['weather.home'].forecast[0].wind_speed }}"
        unit_of_measurement: m/s
        device_class: wind_speed

YAML snippet of the template sensors emulating forecast sensors previously provided by OpenWeatherMap

The procedure for activating the snippet is:

  1. 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.
  2. 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.
  3. Delete the entities that are no longer available or rename their entity IDs via SettingsDevices & ServicesEntities.
  4. Use Developer ToolsYAML 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 on the next full minute, the sensors should also provide the usual data again.

Prediction entities emulated via template integration