Weather.get_forecasts doesn't work!

Hello, I’m trying to search for forecast information through this template:

template:
  - trigger:
      - trigger: time_pattern
        hours: /1
    action:
      - action: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.openweathermap
        response_variable: hourly
    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ hourly['weather.openweathermap'].forecast[0].temperature }}"
        unit_of_measurement: °C

This template is the same as: https://www.home-assistant.io/integations/weather#examples

However, it is not working for me and always returning unknown.

Get with good soul, can you help me?

Thanks

There are a few possible causes…

  1. Are you sure you have an entity weather.openweathermap?
  2. You have configured your sensor with only a Time Pattern trigger which is set to fire at the top of each hour. Any time you make changes to the sensor configuration and reload the template integration, the sensor will be unknown until the start of the next hour.

This is my Open Weatherman setup, and it seems to work fine. The significant difference I see is that I’m getting the daily forecast and not the hourly. The other thing you might need to check is to see if you are still using the old 2.5 API, which is depreciated. You might need to update your OpenWeatherMap account to use the 3.0 API and get a new key.

- trigger:
    - platform: time_pattern
      hours: /1
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.openweathermap
      response_variable: response
  sensor:
    - name: Weather Forecast
      unique_id: 0a7476cc-d6c1-40ba-8ae1-606518c3497a
      state: "{{ now().isoformat() }}"
      attributes:
        forecast: "{{ response['weather.openweathermap'].forecast }}"
    - name: Today High
      device_class: Temperature
      unit_of_measurement: °F
      icon: mdi:thermometer-high
      state: "{{ response['weather.openweathermap'].forecast[0].temperature }}"
    - name: Today Low
      device_class: Temperature
      unit_of_measurement: °F
      icon: mdi:thermometer-low
      state: "{{ response['weather.openweathermap'].forecast[0].templow }}"