HA Forecast v2

I have been lackadaisical with my Home Assistant updates, but when I updated it late December of 2024 I’ve broken all my forecast automations. I had for a short while swapped to openweathermap, but now that even seems to be broken. With summer heat at an all time peak I would like to get this working again. I’ve moderate research on this… and it’s a nightmare. As of writing my instance is 2025.6.2

Problem

{{ state_attr("weather.kmop_daynight", "forecast") }} has now been deprecated and now you have to manually call to get the forecast. From the 3-4 threads I have read, this requires a template, with a trigger and an action. The major problem right off the bat was testing anything. The forums described “Developer Tools” and the “Services” tab, I don’t have any of that.

Testing

After plenty of failures, “Services” has now been renamed to “Actions”. Going there a simple test is:

  1. Select weather.get_forecasts in the search
  2. Select the KMOP entity
  3. Forecast Type: Twice Daily

This is the YAML for the call

1
2
3
4
5
6
action: weather.get_forecasts
data:
  type: twice_daily
target:
  entity_id: weather.kmop_daynight
response_variable: response

Clicking to preform action outputs it in this format

1
2
3
4
5
6
7
weather.kmop_daynight:
  forecast:
    - datetime: ""
      precipitation_probability: 0
      is_daytime: false
    - datetime: ""
      # etc

Scrolling down you can click the COPY TO CLIPBOARD (TEMPLATE) button and this data can then be used inside the Template tab. This is also where you see that the response_variable is in fact being set to response

Automating

This is where the template part comes in. I created a new file templates.yaml and added this line template: !include templates.yaml in my main configuration

I’ve found this file was specific on action and sensor not having a dash

Path: templates.yaml
 1- trigger:
 2  - platform: time_pattern
 3    minutes: "/15"
 4  action:
 5    - service: weather.get_forecasts
 6      data:
 7        type: twice_daily
 8      target:
 9        entity_id: weather.kmop_daynight
10      response_variable: response
11  sensor:
12    - name: Weather Forecast
13      unique_id: weather_forecast
14      state: "{{ now() }}"
15      attributes:
16        forecast: "{{ response['weather.kmop_daynight'].forecast }}"

After creating this and resetting Home Assistant this new sensor appeared as unknown. I am hoping that it will configure after 15 minutes. Which happened!

Converting

Now to update the entity created in the previous post

Path: configuration.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
sensor:
 - platform: template
   sensors:
      forecast_temperature_template:
        friendly_name: "Next Temperature Forecast"
        unit_of_measurement: '°F'
        value_template: >- 
          {% if states("sensor.weather_forecast") != "unavailable" %}
            {% if now().hour >= 18 -%}
              {{ state_attr("sensor.weather_forecast", "forecast").0.temperature }}
            {%- else -%}
              {{ state_attr("sensor.weather_forecast", "forecast").1.temperature }}
            {%- endif %}
          {% else %}
            unavailable
          {% endif %}

I had added an “unavailable” if to all my templates to avoid error logs

Next

My current plans is to keep this running for a week or two to check that it’s working and then changed the trigger to a time platform. This would lower the amount of requests.

Series:
ha temperature
Post:
3/3
comments powered by Disqus