FL550 / dwd_weather

Deutscher Wetterdienst integration for Home-Assistant
MIT License
188 stars 12 forks source link

`weather.get_forecast` is being deprecated in favor of `weather.get_forecasts` #112

Closed Qhilm closed 10 months ago

Qhilm commented 10 months ago

Version of home_assistant

2023.12.0

Version of the custom_component

2.0.13

Describe the bug

Error message in Home Assistant:

"Detected use of deprecated service weather.get_forecast" "Use weather.get_forecasts instead which supports multiple entities."

FL550 commented 10 months ago

This is probably not related to the integration, but rather with the weather card you are using.

Qhilm commented 10 months ago

ah, right. Ignore, I use this code in my configuration.yaml, I just need to figure out how to migrate it.

The error was very misleading, it really looks like it's a problem with the integration, it nowhere says "the yaml code must be updated"...

template:
  - trigger:
    - platform: time
      at: "00:02:00"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    action:
      - service: weather.get_forecast
        data:
          type: daily
        target:
          entity_id: weather.dwd_12345
        response_variable: weather_data
    sensor:
      - name: "Max temp today"
        unique_id: max_temp_today
        state: >-
          {{ weather_data.forecast[0].temperature }}
        unit_of_measurement: "°C"
      - name: "Min temp today"
        unique_id: min_temp_today
        state: >-
          {{ weather_data.forecast[0].templow }}
        unit_of_measurement: "°C"
RealKoenisch commented 10 months ago

ah, right. Ignore, I use this code in my configuration.yaml, I just need to figure out how to migrate it.

The error was very misleading, it really looks like it's a problem with the integration, it nowhere says "the yaml code must be updated"...

template:
  - trigger:
    - platform: time
      at: "00:02:00"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    action:
      - service: weather.get_forecast
        data:
          type: daily
        target:
          entity_id: weather.dwd_12345
        response_variable: weather_data
    sensor:
      - name: "Max temp today"
        unique_id: max_temp_today
        state: >-
          {{ weather_data.forecast[0].temperature }}
        unit_of_measurement: "°C"
      - name: "Min temp today"
        unique_id: min_temp_today
        state: >-
          {{ weather_data.forecast[0].templow }}
        unit_of_measurement: "°C"

It's hard to see. The service you hav to call is weather.get_forecasts with an "s" at the end. And the templating in your case should be {{ weather_data['weather.dwd_12345'].forecast[0].temperature }}

  - service: weather.get_forecasts

sensor:
  - name: "Max temp today"
    unique_id: max_temp_today
    state: >-
      {{ weather_data['weather.dwd_12345'].forecast[0].temperature }}
    unit_of_measurement: "°C"
Qhilm commented 10 months ago

Thanks, I was struggling, I was at weather.dwd_12345.forecast[0].temperature and it wasn't working.

Your solution works for me. Full snippet, for reference:

template:
  - trigger:
    - platform: time
      at: "00:02:00"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.dwd_12345
        response_variable: weather_data
    sensor:
      - name: "Max temp today"
        unique_id: max_temp_today
        state: >-
          {{ weather_data['weather.dwd_12345'].forecast[0].temperature }}
        unit_of_measurement: "°C"
      - name: "Min temp today"
        unique_id: min_temp_today
        state: >-
          {{ weather_data['weather.dwd_12345'].forecast[0].templow }}
        unit_of_measurement: "°C"