briis / hass-weatherflow2mqtt

WeatherFlow to MQTT for Home Assistant. Use UDP to get local weather data in to Home Assistant using MQTT Discovery
MIT License
129 stars 29 forks source link

"forecast_template" deprecated as of 2023.08, will be removed in 2024.03 #244

Closed PARitter closed 1 year ago

PARitter commented 1 year ago

New Feature

Home assistant is changing how forecast data is retrieved from weather entities. The "forecast_template" used by hass-weatherflow2mqtt is deprecated and will be removed as of the March, 2024 release.

See HASS release update: https://www.home-assistant.io/blog/2023/09/06/release-20239/#weather-forecast-service

There is a new service in HASS, "Weather: get forecast", to retrieve forecast data but this does not appear to be implemented in hass-weatherflow2mqtt.

If this is not addressed forecast data from weatherflow hub will not be available after updating to 2024.03.

Additional context

No response

drothenberger commented 1 year ago

For what it's worth, I was able to get rid of the warning by changing the weather entity template for Tempest as follows:

weather:
  - platform: template
    name: Tempest Weather
    unique_id: tempest
    condition_template: "{{ states('sensor.tempest_hub_weather') }}"
    # condition_template: "{{ states('sensor.tempest_current_conditions') }}" # Local Only Option
    temperature_template: "{{ states('sensor.tempest_temperature') | float}}"
    humidity_template: "{{ states('sensor.tempest_humidity')| int }}"
    pressure_template: "{{ states('sensor.tempest_sea_level_pressure')| float }}"
    wind_speed_template: "{{ ( states('sensor.tempest_wind_speed_avg') | float ) | round(2) }}"
    wind_bearing_template: "{{ states('sensor.tempest_wind_bearing_avg')| int }}"
    visibility_template: "{{ states('sensor.tempest_visibility')| float }}"
    #    forecast_template: "{{ state_attr('sensor.tempest_hub_weather', 'daily_forecast') }}"
    forecast_hourly_template: >-
      {% set data = namespace(l = []) %}
      {% for e in state_attr('sensor.tempest_hub_weather', 'hourly_forecast') %}
      {%   set data.l = data.l + [ {
              'datetime': e.datetime,
              'condition': e.condition,
              'temperature': e.temperature,
              'native_apparent_temperature': e.feels_like,
              'pressure': e.pressure,
              'humidity': e.humidity,
              'precipitation': e.precipitation,
              'precipitation_probability': e.precipitation_probability,
              'wind_speed': e.wind_speed,
              'native_wind_gust_speed': e.wind_gust,
              'wind_bearing': e.wind_bearing,
              'uv_index': e.uv
            } ] %}
      {% endfor %}
      {{ data.l }}
    forecast_daily_template: >-
      {% set data = namespace(l = []) %}
      {% for e in state_attr('sensor.tempest_hub_weather', 'daily_forecast') %}
      {%   set data.l = data.l + [ {
              'datetime': e.datetime,
              'condition': e.condition,
              'temperature': e.temperature,
              'templow': e.templow,
              'precipitation': e.precipitation,
              'precipitation_probability': e.precipitation_probability,
              'wind_speed': e.wind_speed,
              'wind_bearing': e.wind_bearing
            } ] %}
      {% endfor %}
      {{ data.l }}

This replaces the "forecast_template" field with "forecast_hourly_template" and "forecast_daily_template". I found that HASS got upset if those forecasts included unknown keys, which is why those template definitions are so long. I had to filter out the keys from Tempest that were not supported.

There may be a better/cleaner way to do this, but this is working for me. I no longer get the warning, and I can see both daily and hourly forecasts in the Weather card for my Tempest.

PARitter commented 1 year ago

That addresses the short-term impact of this change and suppresses the current warning. But I presume (without knowledge) this remains deprecated and will be a breaking change in 2024.03. When the "forecast_template" is finally removed, its component parts, "forecast_hourly_template" and "forecast_daily_template" will almost certainly be removed with it.

drothenberger commented 1 year ago

Those tags for the weather template are new and I believe were added as part of this new change, so I don't think they are going away. If they were going away, I would expect a warning for using them as well.

There is no Tempest integration here that can provide a weather entity and the corresponding get_weather service, so I think we will have to continue to use the weather template.

TL;DR: I think this is the right long-term approach, but I'm no expert.

drothenberger commented 1 year ago

This is the commit in 2023.09 that added the new forecast_daily_template and forecast_hourly_template attributes to the weather template: https://github.com/home-assistant/core/commit/207e3f90a66e1b34a9dce05fc2caafc3662150d2

mjmeli commented 1 year ago

Yes @drothenberger is right, forecast_template is being deprecated because forecast_hourly_template and forecast_daily_template are replacing it.

There was a change in 2023.9.3 that exposed the erroneous keys in the log message. These are the ones that need to be removed:

Daily Only valid keys in Forecast are allowed, unallowed keys: ({'precip_icon', 'precip_type', 'wind_direction_cardinal', 'conditions'})

Hourly Only valid keys in Forecast are allowed, unallowed keys: ({'precip_icon', 'uv', 'conditions', 'wind_gust', 'precip_type', 'wind_direction_cardinal', 'feels_like'})

briis commented 1 year ago

I have released 3.2.2 that closes this issue. Thank you @mjmeli