My weather forecast template doesnt work anymore

that code i posted above creates a sensor called sensor.temperature_forecast_next_hour. it does not create an attribute.

i asked if you would do the code above, restart home assistant then go to dev-tools->templates and enter

{{ states('sensor.temperature_forecast_next_hour') }}

and tell me what it says. could you do that please?

here is the weather sensor





i did tell ya… i mentioned to ya 2 times… it states unavailable

ill try a full reboot… and see if that makes the sensor template work

full reboot didnt help… still is unavaliable

ah right, the trigger is currently on hourly (in the trigger it has hours: /1). for now, which means it will only get the forecast at the top of the hour.

just to test it temporarily, perhaps switch it to minutes: instead of hours: restart and wait until the top of the minute…

i see @code-in-progress also glanced at this thread… don’t hesitate to jump in if you see something i don’t!!!

1 Like

apologies, it wasn’t clear to me if you had done this after the restart or not. however the hourly invocation is more likely the current culprit. also the fact that it say unavailable instead of unknown is an indicator that the sensor is created… but the value isn’t loaded.

ah ok and i rebooting…
like before the weather.petherborough_forecast was alot more full of settings or attritrbutes or states whatever you call them… but they are broken out seperately now so they no longer under the forecast… i did also try removing the enviromental canada… and re add it to see if it fix it… but it kept it seperate still

And here I thought I was being all stealthy! :ninja:

Let me test it in a few minutes and see what I can figure out (if anything) lol

As always in YAML, indentation is important target and response_variable are not children of data… all three of them should be aligned with service.

# This should be added directly to configuration.yaml or a properly merged file. 

# For merged files (AKA Split Configuration), if your configuration.yaml file contains a line like `template: !include THE_NAME_OF_THIS_FILE.yaml`,
# you need to remove the "template:" on the top line.

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

The sensors in Post #11 are a mash up of old format and new format and most do not have the required quote marks and delimiters. { is not the same as {{.

Where do you have these sensors configured… i.e. are they all directly in configuration.yaml or in some other file that is being merged using the !include tag?

The legacy format sensors need to be configured under the top-level key sensor. The current format needs to be configured under the top-level key template.

@Didgeridrew

i was trying to convert my legacy to work new format… as legacy was only 3 lines of code new format is like 15 lines of code… but also the sensors are no longer part of forecast that im trying to use as i mentioned… which i been trying to to convert
sensor into template sensor but i havent had any luck

and they are configure under the weather.yaml under packages folder… as it worked fine and dandy orginally as you see in the orginal code

i figured if i could just re code just the 1 line it fix it from

weather.peterborough_forecast.condition to sensor.peterborough_current_condition

and so on as the forecasts dont match weather page as there is no longer
a weather.peterborough_forecast.condition that weather page would make you believe you can do
so thats why i been frustrated

and your code didnt work it didnt create sensor Temperature forecast next hour
but gonna try a total reboot of HA and my internet see if your code works then

WHERE ARE YOU CONFIGURING THESE SENSORS?

no need to yell
and i told you
in the Weather.yaml in the packages folder

so i added

  - sensor:
      - name: Today's mimimal temperature
        unique_id: today_min
        state: "{{ states('sensor.peterborough_low_temperature' ) }}"

but i get unknown under template but in the dev-template i can get -5

here is my current weather,yaml file so you can see it totally…

# This is Home Assistant configuration. This goes into your configuration.yaml file (or packages folder if you have split your config)
# you need to provide your API key

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.peterborough_forecast
        response_variable: hourly
      - variables:
          ptb_forecast: "{{ hourly['weather.peterborough_forecast'].forecast }}"
    sensor:
      - name: Temperature forecast next hour2
        unique_id: temperature_forecast_next_hour
        state: "{{ ptb_forecast[0].temperature }}"
        unit_of_measurement: °C

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

        # - name: Today's rain forecast
        #   unique_id: today_rain
        #   state: "{{ minute['weather.peterborough_forecast'].forecast[0].preprecipitation_probability }}"
        #   unit_of_measurement: °C
        #        state: "{{ hourly['weather.home'].forecast[0].temperature }}"
        #        today_min:
        #          state: { { states('sensor.peterborough_low_temperature') } }
        #          friendly_name: Today's mimimal temperature
        #today_min:
        #  state: { { states('sensor.peterborough_low_temperature') } }
        #  friendly_name: Today's mimimal temperature
        #{state_attr{ sensor.peterborough_current_condition}}
        #sensor.peterborough_current_condition
        #value_template: "{{ state_attr('weather.peterborough_forecast', 'forecast')[0].templow }}"
        #value_template: "{state_attr{sensor.peterborough_low_temperature}}"
        # value_template: "{{states('sensor.peterborough_low_temperature') |int}}"
        # {{ this.attributes.test | default('Value when missing') }}"
        ##friendly_name: Today's mimimal temperature
        #availability_template: "{{ state_attr('weather.peterborough_forecast', 'forecast') is not none }}"
        #today_max:
        #sensor.peterborough_high_temperature
        #value_template: { { states('sensor.peterborough_high_temperature') } }
        # friendly_name: Today's maximal temperature
        # availability_template: "{{ state_attr('weather.peterborough_forecast', 'forecast') is not none }}"
        #today_rain:
        #sensor.peterborough_chance_of_precipitation
        #  value_template: "{{ state_attr('weather.peterborough_forecast', 'forecast')[0].precipitation_probability }}"
        #  friendly_name: Today's rain forecast
        #  availability_template: "{{ state_attr('weather.peterborough_forecast', 'forecast') is not none }}"
        today_icon:
          #sensor.peterborough_current_condition
          value_template: >-
            {% if state_attr("weather.peterborough_forecast","forecast")[0].condition =='clear-night' %}
              3
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='cloudy' %}
              5
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='fog' %}
              16
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='hail' %}
              6
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='lightning' %}
              13
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='lightning-rainy' %}
              17
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='partlycloudy' %}
              8
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='pouring' %}
              18
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='rainy' %}
              9
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='snowy' %}
              11
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='snowy-rainy' %}
              7
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='windy' %}
              14
            {% elif state_attr("weather.peterborough_forecast","forecast")[0].condition =='windy-variant' %}
              14
            {% else %}
              12
            {% endif %}
          friendly_name: Today weather forecast
          availability_template: "{{ state_attr('weather.peterborough_forecast', 'forecast') is not none }}"

  - sensor:
      - name: Today's mimimal temperature
        unique_id: today_min
        #states: "{{ states('sensor.peterborough_low_temperature' ) }}"
        value_template: "{{ states('sensor.peterborough_low_temperature' ) }}"

      - name: Today's maximal temperature
        unique_id: today_max
        value_template: "{{ states('sensor.peterborough_high_temperature' ) }}"

      - name: Today's rain forecast
        unique_id: today_rain
        value_template: "{{ states('sensor.peterborough_chance_of_precipitation' ) }}"

You are overwriting the corrected version with the prior version because you did not change the unique ID. And all of the other sensors are still a mess.

i not sure what the corrected version is… and this is what i currently have now

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.peterborough_forecast
        response_variable: hourly
      - variables:
          ptb_forecast: "{{ hourly['weather.peterborough_forecast'].forecast }}"
    sensor:
      - name: Temperature forecast next hour2
        unique_id: temperature_forecast_next_hour
        state: "{{ ptb_forecast[0].temperature }}"
        unit_of_measurement: °C

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

  - sensor:
      - name: Today's mimimal temperature
        unique_id: today_min
        #states: "{{ states('sensor.peterborough_low_temperature' ) }}"
        value_template: "{{ states('sensor.peterborough_low_temperature' ) }}"

      - name: Today's maximal temperature
        unique_id: today_max
        value_template: "{{ states('sensor.peterborough_high_temperature' ) }}"

      - name: Today's rain forecast
        unique_id: today_rain
        value_template: "{{ states('sensor.peterborough_chance_of_precipitation' ) }}"

      - name: "Today weather forecast"
        state: >
          {% if is_state("sensor.peterborough_current_condition",'clear-night') %}
            3
          {% elif is_state("sensor.peterborough_current_condition",'cloudy') %}
            5
          {% elif is_state("sensor.peterborough_current_condition",'fog') %}
            16
          {% elif is_state("sensor.peterborough_current_condition",'hail') %}
            6
          {% elif is_state("sensor.peterborough_current_condition",'lightning') %}
            13
          {% elif is_state("sensor.peterborough_current_condition",'lightning-rainy') %}
            17
          {% elif is_state("sensor.peterborough_current_condition",'partlycloudy') %}
            8
          {% elif is_state("sensor.peterborough_current_condition",'pouring') %}
            18
          {% elif is_state("sensor.peterborough_current_condition",'rainy') %}
            9
          {% elif is_state("sensor.peterborough_current_condition",'snowy') %}
            11
          {% elif is_state("sensor.peterborough_current_condition",'snowy-rainy') %}
            7
          {% elif is_state("sensor.peterborough_current_condition",'windy') %}
            14
          {% elif is_state("sensor.peterborough_current_condition",'windy-variant') %}
            14
          {% else %}
            12
          {% endif %}

so what is the corrected version i need like the exact sample

# This is Home Assistant configuration. This goes into your configuration.yaml file (or packages folder if you have split your config)
# you need to provide your API key

template:
  - trigger:
      - platform: time_pattern
        hours: /1
      - platform: homeassistant
        event: start
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.peterborough_forecast
        response_variable: hourly
      - variables:
          ptb_forecast: "{{ hourly['weather.peterborough_forecast'].forecast }}"
    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ ptb_forecast[0].temperature }}"
        unit_of_measurement: °C      
        attributes:
          forecast_0: "{{ ptb_forecast[0] }}"

  - sensor:
      - name: Today Min
        unique_id: todays_minimal_temperature
        state: "{{ states('sensor.peterborough_low_temperature' ) }}"
        availability: "{{ has_value('sensor.peterborough_low_temperature') }}"
        
      - name: Today Max
        unique_id: todays_maximal_temperature
        state: "{{ states('sensor.peterborough_high_temperature' ) }}"
        availability: "{{ has_value('sensor.peterborough_high_temperature') }}"

      - name: Today Rain
        unique_id: todays_rain_forecast
        state: "{{ states('sensor.peterborough_chance_of_precipitation') }}"
        availability: "{{ has_value('sensor.peterborough_chance_of_precipitation') }}"   
   
      - name: Today Icon
        unique_id: today_condition_icon
        state: >-
          {% set condition = states("weather.peterborough_forecast") %}
          {% set mapper = {'clear-night': 3,
          'cloudy': 5, 'fog': 16, 'hail': 6,
          'lightning': 13, 'lightning-rainy': 17, 'partlycloudy': 8,
          'pouring': 18, 'rainy': 9, 'snowy': 11,
          'snowy-rainy': 7, 'windy': 14, 'windy-variant': 14 } %}
          {{ mapper[condition] if condition in mapper.keys() else 12 }}
        availability: "{{ has_value('weather.peterborough_forecast') }}"

EDIT: Typo corrected, missing comma and quote marks