New weather forecast template

Thanks. That makes sense.

The reasons sound solid, and you described them well.

I think just I and many are wondering, if there couldn’t have also been an easier/smoother “upgrade” process.

I probably have better templating skills than the average HA user, and this was non-trivial to change for me.

1 Like

There might have been easier/better ways to do it and we might see those in future versions. I know that this was decided a long time ago (and had a deprecation notice associated with it for at least 6 months). So, I mean, there was time to get it done. But I get where you are coming from.

hi, I used this code before, now I can’t understand how to create a sensor that tells me tomorrow’s minimum temperature.
I created this by looking at your examples but I don’t see the sensor.
what am I doing wrong?
Thank you

old condition in automation:

  condition:
    - condition: template
      value_template: '{{ (state_attr(''weather.casa'',''forecast'').0.templow)|float <= 2|float}}'

new:

template:
- trigger:
    - platform: time_pattern
      hours: "/1"
    - platform: state
      entity_id: weather.casa
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.casa
  sensor:
  - name: "Temperatura minima domani"
    icon: "mdi:thermometer"
    state: "{{ daily['weather.casa'].forecast[0].templow|float }}"

Where did you place the sensor configuration?

hello, inside one of my .yaml files in the package folder.

/homeassistant/packages/meteo.yaml

I didn’t see it at first… you are missing the response_variable declaration.

template:
  - trigger:
      - platform: time_pattern
        hours: "/1"
      - platform: state
        entity_id: weather.casa
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.casa
        response_variable: daily
    sensor:
      - name: "Temperatura minima domani"
        icon: "mdi:thermometer"
        state: "{{ daily['weather.casa'].forecast[0].templow|float }}"
1 Like

Thank you! so it works well :grinning:

They could’ve shipped it with a preinstalled set of templates such as: https://www.home-assistant.io/integrations/template/#trigger-based-handling-of-service-response-data

I just wasted a couple of hours also trying to figure out why many examples around don’t work. I realise though this is the problem with breaking changes, that the plethora of ‘helpful’ examples on the internet no longer work and you’re left wondering why as a beginner.

Got it working now though with template.yaml using OpenWeatherMap!

1 Like

I need some assistance getting todays and tonight’s weather forecast for NWS integration . I have set up a template sensor and it is populating the sensor with data. The issue I am having is that it seems to be pulling stale data. As you can see from the results, even though this was pulled today (4/29) the first forecast is from 4/27 instead.

Sensor template:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
      - platform: event
        event_type: event_template_reloaded
    action:
      - service: weather.get_forecasts
        target:
          entity_id:
            - weather.galveston
        data:
          type: twice_daily
        response_variable: daily
    sensor:
      - name: Galveston Forecast
        unique_id: galveston_forecast
        state: "{{ states('weather.galveston') }}"
        attributes:
          forecast: "{{ daily['weather.galveston'].forecast }}"

Results

weather.galveston:
  forecast:
    - detailed_description: >-
        Partly sunny, with a high near 78. Southeast wind around 25 mph, with
        gusts as high as 40 mph.
      datetime: "2024-04-27T14:00:00-05:00"
      precipitation_probability: 0
      is_daytime: true
      condition: windy-variant
      wind_bearing: 135
      temperature: 78
      dew_point: 73
      wind_speed: 25
      humidity: 87
    - detailed_description: >-
        Mostly cloudy, with a low around 74. Southeast wind 25 to 30 mph, with
        gusts as high as 40 mph.
      datetime: "2024-04-27T18:00:00-05:00"
      precipitation_probability: 0
      is_daytime: false
      condition: windy-variant
      wind_bearing: 135
      temperature: 74
      dew_point: 73
      wind_speed: 27.5
      humidity: 90
    - detailed_description: >-
        A chance of showers and thunderstorms after 1pm. Mostly cloudy, with a
        high near 77. Southeast wind 15 to 25 mph, with gusts as high as 40 mph.
        Chance of precipitation is 30%. New rainfall amounts less than a tenth
        of an inch possible.
      datetime: "2024-04-28T06:00:00-05:00"
      precipitation_probability: 30
      is_daytime: true
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 77
      dew_point: 74
      wind_speed: 20
      humidity: 91
    - detailed_description: >-
        A chance of showers and thunderstorms. Mostly cloudy, with a low around
        73. Southeast wind 15 to 20 mph, with gusts as high as 30 mph. Chance of
        precipitation is 40%.
      datetime: "2024-04-28T18:00:00-05:00"
      precipitation_probability: 40
      is_daytime: false
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 73
      dew_point: 73
      wind_speed: 17.5
      humidity: 94
    - detailed_description: >-
        A chance of showers and thunderstorms. Partly sunny, with a high near
        78. South wind 10 to 15 mph, with gusts as high as 25 mph. Chance of
        precipitation is 50%.
      datetime: "2024-04-29T06:00:00-05:00"
      precipitation_probability: 50
      is_daytime: true
      condition: lightning-rainy
      wind_bearing: 180
      temperature: 78
      dew_point: 74
      wind_speed: 12.5
      humidity: 94
    - detailed_description: >-
        A chance of showers and thunderstorms. Mostly cloudy, with a low around
        74. Chance of precipitation is 50%.
      datetime: "2024-04-29T18:00:00-05:00"
      precipitation_probability: 50
      is_daytime: false
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 74
      dew_point: 73
      wind_speed: 15
      humidity: 94
    - detailed_description: >-
        A chance of showers and thunderstorms. Partly sunny, with a high near
        79. Chance of precipitation is 40%.
      datetime: "2024-04-30T06:00:00-05:00"
      precipitation_probability: 40
      is_daytime: true
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 79
      dew_point: 73
      wind_speed: 15
      humidity: 92
    - detailed_description: >-
        A chance of showers and thunderstorms before 7pm. Mostly cloudy, with a
        low around 75. Chance of precipitation is 40%.
      datetime: "2024-04-30T18:00:00-05:00"
      precipitation_probability: 40
      is_daytime: false
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 75
      dew_point: 73
      wind_speed: 15
      humidity: 91
    - detailed_description: Partly sunny, with a high near 79.
      datetime: "2024-05-01T06:00:00-05:00"
      precipitation_probability: 0
      is_daytime: true
      condition: cloudy
      wind_bearing: 135
      temperature: 79
      dew_point: 73
      wind_speed: 15
      humidity: 91
    - detailed_description: Mostly cloudy, with a low around 75.
      datetime: "2024-05-01T18:00:00-05:00"
      precipitation_probability: 0
      is_daytime: false
      condition: cloudy
      wind_bearing: 135
      temperature: 75
      dew_point: 73
      wind_speed: 17.5
      humidity: 92
    - detailed_description: >-
        A slight chance of showers and thunderstorms after 1pm. Partly sunny,
        with a high near 79. Chance of precipitation is 20%.
      datetime: "2024-05-02T06:00:00-05:00"
      precipitation_probability: 20
      is_daytime: true
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 79
      dew_point: 73
      wind_speed: 17.5
      humidity: 94
    - detailed_description: >-
        A slight chance of showers and thunderstorms. Mostly cloudy, with a low
        around 75. Chance of precipitation is 20%.
      datetime: "2024-05-02T18:00:00-05:00"
      precipitation_probability: 20
      is_daytime: false
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 75
      dew_point: 73
      wind_speed: 15
      humidity: 92
    - detailed_description: >-
        A slight chance of showers and thunderstorms. Partly sunny, with a high
        near 79. Chance of precipitation is 20%.
      datetime: "2024-05-03T06:00:00-05:00"
      precipitation_probability: 20
      is_daytime: true
      condition: lightning-rainy
      wind_bearing: 135
      temperature: 79
      dew_point: 72
      wind_speed: 15
      humidity: 90
    - detailed_description: >-
        A slight chance of showers and thunderstorms before 7pm. Mostly cloudy,
        with a low around 72. Chance of precipitation is 20%.
      datetime: "2024-05-03T18:00:00-05:00"
      precipitation_probability: 20
      is_daytime: false
      condition: lightning-rainy
      wind_bearing: 90
      temperature: 72
      dew_point: 72
      wind_speed: 10
      humidity: 91

This is the template I use for my briefing which used to update for day and night, but now is stuck with data from the 27th.

It's {{ state_attr('weather.galveston', 'temperature') }}° outside. {{ state_attr('sensor.galveston_forecast', 'forecast')[0].detailed_description }}

Any assistance is greatly appreciated.

You need to get today’s two forecast objects then select one. One way to do that is as follows:

It's {{state_attr('weather.galveston','temperature')}}° outside. {% set list = state_attr('sensor.galveston_forecast','forecast')
| rejectattr('datetime', 'match', (now()|string)[0:11])
| sort(attribute='datetime')|map(attribute='detailed_description')|list %}
{{- list[0] if now().hour < 17 else list[1] }}
1 Like

Hi All,

I just updated to 2024.4 and I immediately got an error describing the deprecated forecast mentioned in the breaking changes. (overlooked it before updating).

At this point I can’t get my forecasts working again which is a bummer.

My old config:

# Weather Combination
weather:
  - platform: template
    name: "Weather Combination"
    condition_template: "{{ states('weather.openweathermap') }}"
    temperature_template: "{{ states('sensor.buiten_temperature') | float}}"
    humidity_template: "{{ states('sensor.buiten_humidity')| float }}"
    forecast_template: "{{ state_attr('weather.openweathermap', 'forecast') }}"
    pressure_template: "{{ states('sensor.openweathermap_pressure') | float }}"
    wind_speed_template: "{{ state_attr('weather.openweathermap', 'wind_speed') }}"
    wind_bearing_template: "{{ state_attr('weather.openweathermap', 'wind_bearing') }}"
    visibility_template: "{{ state_attr('weather.buienradar', 'visibility') }}"

What I’ve changed:

# Weather Combination
weather:
  - platform: template
    name: "Weather Combination"
    condition_template: "{{ states('weather.openweathermap') }}"
    temperature_template: "{{ states('sensor.buiten_temperature') | float}}"
    humidity_template: "{{ states('sensor.buiten_humidity')| float }}"
    forecast_daily_template: "{{ state_attr('weather.openweathermap', 'forecast') }}"
    pressure_template: "{{ states('sensor.openweathermap_pressure') | float }}"
    wind_speed_template: "{{ state_attr('weather.openweathermap', 'wind_speed') }}"
    wind_bearing_template: "{{ state_attr('weather.openweathermap', 'wind_bearing') }}"
    visibility_template: "{{ state_attr('weather.buienradar', 'visibility') }}"

This makes the configuration error disappear when restarting, however it still doesn’t show my forecasts in my custom: weather card.

I’ve checked this thread and I’m not sure making a triggered template will be the solution for me. Any advice would be appreciated!

update custom:weather card

Hi, Thanks for the reply. the weather card is up to date (1.5.0).

Make sure that 1.5.0 has the ability to read the forecast data. Last I checked, it was only in the beta.

Thank you for the nudge in the right direction. I had to make a couple of minor changes, but this now works. Here is the updated template

It's {{state_attr('weather.galveston','temperature')}}° outside. {% set list = state_attr('sensor.galveston_forecast','forecast')
| selectattr('datetime', 'match', (now()|string)[0:11]|trim)
| sort(attribute='datetime')|map(attribute='detailed_description')|list %}
{{- list[0] if now().hour < 17 else list[1] }}

Thanks for your assistance!

Well another fun stop on this continuing saga of ridiculousness.

No matter how I do it none of these templates pull the number in as a number. So I can’t have anything use it as a number. The float and is_number tests always fail.

I really hope the devs responsible for removing such a vital function with no similarly easy replacement read this large thread of frustrations. It should not be this hard to pull a daily temperature and test it against something. I’ve been able to do this for years with home assistant and now automations are broken. I can’t remember anything being this frustratingly difficult with home assistant before and I have been templating and using yaml since the early days.

4 Likes

You don’t need to use is_number for any of this…

I didn’t say I was. I said I was running it as a test against the sensor value.

I completely understand that there are valid, important technical reasons for this change. I’m in favor of seeing Home Assistant make progress! This change makes a significant improvement “under the hood”, and we all benefit from it. No argument there.

I also want to acknowledge — and say thank you! — to the volunteers in this thread and elsewhere in these discussions who are helping folks who are having difficulties with the change. You guys are awesome! We are grateful that you’re here and helping. I hope you’ll understand and forgive when frustrations boil over a bit and someone (me!) gets snippy in our comments here. It’s the problem with our config, not the discussion. Again, thank you!

That said, I want to offer some (hopefully) constructive feedback. I hope this will be seen as friendly and useful, rather than a complaint.

First, in the commercial software world where I work, when we roll out a feature change and it generates a slew of unexpected customer complaints and cases, we look at that as signal. Our customers are telling us something; what is it?

  • Sometimes the feature is a bad idea. (Not the case here!)
  • Sometimes the feature is buggy.
  • Sometimes the feature is poorly documented (my job), and customers can’t fix the problem themselves by reading it.
  • Sometimes the feature is great, but the transition was problematic. We didn’t understand the impact or effort customers would have to go through to adopt the change.
  • Sometimes the feature misses one or more important customer use cases.
  • And so on.

I hope that the folks who manage this feature area will take the time to read through this whole thread, and think about what signal is being sent. What does it mean? What improvements can we make, either to this feature, or to our rollout process, or whatever?

Second, a couple thoughts about specific comments here:

My use case is that I want to use my local backyard temperature instead of the “local” current temperature provided by the integration. That’s it. One value, from one sensor, “pushed” into the weather data used by all the rest of my Home Assistant install. Scripts, dashboards, etc.

The Template Weather Provider seems (seemed) like the perfect way to handle this. It worked great for months. It was easy to understand, and straightforward to implement.

It was not, in my opinion, a “high level” use case or advanced configuration. Certainly, I think that taking your local weather forecast but using your backyard temperature in displays doesn’t seem like an uncommon thing for people to want to do. Temperature sensors are among the easiest and most common devices added to any smart home, and “what temperature is it outside right now?” is probably the second most important weather-related question that people regularly ask. (After, “will it rain today?”, and setting aside hazardous conditions like tornados and lightning.)

So, the signal I’m sending is that the new feature design makes an important use case harder to understand and harder to implement. (The weather template docs are also…not helping.)

I very much hope that there’s zero expectation that “normal users” will hang out in the developer forums and repos, trying to parse out useful information from technical conversations that make zero sense to them.

Maybe this discussion was great, and would address end user concerns with understanding the change and its impact. But, uh, yeah, we don’t hang out there. How would any non-HA dev ever have even come across this discussion? If a tree falls in a forest…

Final thoughts:

  • Regardless of the completeness, thoroughness, and best intentions of the folks who designed and implemented this feature change, this and other discussions suggest that the full impact of the change on end users was not fully understood. I think it would be worth ask, why not? How could we do better?

  • Regardless of the quality of the implementation, and the number of deprecation and repair notices, many end users didn’t understand the implications of this change. We upgraded, things that worked before broke, and fixing it was hard. That wasn’t a good experience. How can repair notifications be made more understandable?

  • There’s no doubt in my mind that the documentation wasn’t fully updated for this change. Some doc was updated, but not all of it, or without clear and complete explanations of the new feature design and how to use it. Why not? What process changes could be made to ensure all doc for an affected feature is updated and complete in the future?

If you made it this far, what signal do you think this discussion thread is sending? What signal do you want to send? (Be constructive, please!)

9 Likes

I’m a “non-HA dev” (a user, not a developer) but I know just enough about Github to know where to find Home Assistant’s Issues, PRs, Discussions, etc (because they don’t have those technical discussions here).

BTW, I posted that link to dispel the notion that the change was the product of short-sightedness (because that accusation has been made more than once).