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.
template:
- trigger:
- platform: state
entity_id: weather.home
- platform: time_pattern
hours: /1
action:
- action: 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:
- 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, thename:
andunique_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 atemplate:
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.
