jaydeethree / Home-Assistant-weatherdotcom

Home Assistant custom component/integration for Weather.com
GNU General Public License v3.0
35 stars 5 forks source link

Use service get_forecasts for forecasts #19

Closed Ayuus closed 7 months ago

Ayuus commented 7 months ago

Hello,

Since I updated HA to 2023.12, I get the following message:

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

Please replace this service and adjust your automations and scripts and select submit to close this issue.

Woul it be possible to adapt his integration to use the new HA service?

Regards, Ronald

jaydeethree commented 7 months ago

The error message is a bit confusing, but this actually doesn't have anything to do with this integration - it means that you have an automation or a script that's calling weather.get_forecast, and that automation/script needs to be updated to use weather.get_forecasts instead. Unfortunately Home Assistant started displaying this error before they finished writing the documentation about the change, but you can view the pending documentation here:

https://github.com/home-assistant/home-assistant.io/pull/30189/files

Ayuus commented 7 months ago

For everyone who struggles with weather.get_forcasts as I did, this is what is working for me:

template: 
    # daily forcast data, trigger sensor is necessary for new HA
  - trigger:
    - platform: state
      entity_id: weather.home
    action:
      service: weather.get_forecasts
      target:
        entity_id: weather.home        
      data:
        type: daily
      response_variable: daily
    sensor:
      - name: "Daily Weather Forecast"
        unique_id: daily_weather_forecast
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily['weather.home'].forecast}}"

    # hourly forcast data, trigger sensor is necessary for new HA
  - trigger:
    - platform: time_pattern
      hours: /1
    action:
      service: weather.get_forecasts
      target:
        entity_id: weather.home        
      data:
        type: hourly
      response_variable: hourly
    sensor:
      - name: "Hourly Weather Forecast"
        unique_id: hourly_weather_forecast
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly['weather.home'].forecast}}"