Weather Template and Forecast

I read quite a bit on how things changed with the 2024.04 release and weather forecast attributes.

However I still have not understood the documentation of the “Template Weatger Provider”.

# Example configuration.yaml entry
weather:
  - platform: template
    name: "My Weather Station"
    condition_template: "{{ states('weather.my_region') }}"
    temperature_template: "{{ states('sensor.temperature') | float }}"
    temperature_unit: "°C"
    humidity_template: "{{ states('sensor.humidity') | float }}"
    forecast_daily_template: "{{ state_attr('weather.my_region', 'forecast_data') }}"

I am looing to have the forecast in my template sensor of hourly and daily temp min max and condition values.
All examples I found always only provide parts of the information — or more likely I think in a wrong way and dont understand it :slight_smile:

Any hints welcome :slight_smile:

This template is to create a wether entity if you already have a forecast. But I’m guessing you want the reverse? If so, you’re probably looking at the wrong documentation. In that case you want the “Example template sensor using get_forecasts” on this page:

ahh thanks :slight_smile:
may I ask more then.

1- so I need to create a sensor for every value specifically?

    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ hourly['weather.home'].forecast[0].temperature }}"
        unit_of_measurement: °C

No way to just get everything from the response and leave the rest to the Template Weather Provider?

  1. Is there a UI way to create a action or does this go to the configuration.yaml only?

Thanks

You can put it in one or more entities, split it up in attributes, etc. Yaml only. But what is it you want to do with the values exactly once you have them? because sticking them back in a template weather entity will create a sort of copy of what you already had. If you just want to display a weather card you do not need all this, you just provide the weather entity to the weather card of your choice.

I have a Weather Template Sensor.
I mixed my own sensors outside temp etc. with forecast from a cloud weather provider.

The home assistant standard weather entity (all data from met.no) shows a forecast. (left card)
The right weather card shows my own weather.local entity. I wanted to populate the forecast info there aswell. Currently I thought I have to use get_forecasts and provide it to “forcast_daily_template” of the Template Weather Provider to achieve this?

Ah, ok, that makes sense. Then you use the template in the example, and create an attribute on the sensor using:

"{{ hourly['weather.home'].forecast[0] }}"

It needs to be an attribute because it contains the whole forcast for all days (or hours, depending on which service you pick. You could also do both.). The state has limited length, attributes do not.
Then, when you create your weather entity, you supply that attribute as the forecast.

Thank you again.
For anyone stumbling over this and also wanting to have Template Weather Entity eg. to mix data from local solution like Ecowitt and cloud with forecasts … this is my working code:

Code in configuration.yaml for triggering the data and read it to the standard weather.yourcloudentity

template:
  - trigger:
      - platform: time_pattern
        hours: /1

    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: 
           - weather.home
        response_variable: daily

    sensor:
      - name: Daily Forecast
        unique_id: weather_forecast_daily
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ daily['weather.home'].forecast }}" 

  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: 
            - weather.home
        response_variable: hourly
    sensor:
      - name: Hourly Forecast
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly['weather.home'].forecast }}"

Template Weather Entitiy


- platform: template
  name: "Wetterdaten Lokal und Cloud Mix"
  unique_id: "weather.local"
  condition_template: "{{ states('weather.home') }}"
  temperature_template: "{{ states('sensor.local_ecowitt_outdoor_temperature') | float }}"
  apparent_temperature_template: "{{ states('sensor.local_ecowitt_feels_like_temperature') | float }}"
  dew_point_template: "{{ states('sensor.local_ecowitt_dewpoint') | float }}"
  humidity_template: "{{ states('sensor.local_ecowitt_humidity') | float }}"
  pressure_template: "{{ states('sensor.local_ecowitt_relative_pressure') | float }}"
  wind_speed_template: "{{ states('sensor.local_ecowitt_wind_speed') | float }}"
  wind_bearing_template: "{{ states('sensor.local_ecowitt_wind_direction') | float }}"
  visibility_template: "{{ state_attr('weather.home', 'visibility') }}"
  forecast_daily_template: "{{ state_attr('sensor.daily_forecast', 'forecast') }}"
  forecast_hourly_template: "{{ state_attr('sensor.hourly_forecast', 'forecast') }}"

The actions part is a list. So you can put both forecasts in the same time trigger if you want.