My weather forecast template doesnt work anymore

so i i think i did it right… but its not working… i setup the
icon, temperature low, temperature high, and precipitation… but none work…
the icon one i trying a couple ways… as there is another sensor that shows up so i trying to link but thats not working that way either…
so i def doing something wrong

 ### Template For Todays Icon ###
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.peterborough_forecast
      response_variable: hourly
  sensor:
    - name: Today weather forecast
      unique_id: today_icon
      state: sensor.peterborough.icon_code
      # state: "{{ hourly['weather.peterborough_forecast[0]'].condition }}"
      #unit_of_measurement: °C

  ### Template For High Temperature ###
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.peterborough_forecast
      response_variable: hourly
  sensor:
    - name: Today's maximal temperature
      unique_id: today_max
      state: "{{ hourly['weather.peterborough_forecast[0]'].temperature }}"
      unit_of_measurement: °C

  ### Template For Low Temperature ###
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.peterborough_forecast
      response_variable: hourly
  sensor:
    - name: Today's minimal temperature
      unique_id: today_min
      state: "{{ hourly['weather.peterborough_forecast[0]'].templow }}"
      unit_of_measurement: °C

  ### Template For Precipitation ###
- trigger:
    - platform: time_pattern
      hours: /1
  action:
    - service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.peterborough_forecast
      response_variable: hourly
  sensor:
    - name: Today's rain forecast
      unique_id: today_rain
      state: "{{ hourly['weather.peterborough_forecast[0]'].precipitation_probability }}"
      #unit_of_measurement: °C

I managed to get what I needed without the template.

          - type: custom:weather-card
            entity: weather.kitchener_waterloo
            name: K-W
          - type: weather-forecast
            show_current: false
            show_forecast: true
            entity: weather.kitchener_waterloo
            forecast_type: hourly
          - type: weather-forecast
            show_current: false
            show_forecast: true
            entity: weather.kitchener_waterloo
            forecast_type: daily

ah for me im sending it to a 2.4" nextion screen so it takes the icon and changes … but if i do a webpage ya that would be the way id go

1 Like

oh and love the commander keen icon (:

1 Like

@tom_l im stuck… i cant seem to convert the sensors to my template sensors… i took your link you sent… and i tried different things… ive tried stats states_attr multiple different ways i can not get the sensor value into the template sensor

      today_min:
        state: { states('sensor.peterborough_low_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 }}"```

so the sensor is no longer 
```weather.peterborough_forecast```
but its 
```sensor.peterborough_current_condition```
yet the current condition is in the states of the forecast

so i trying to add 
sensor.peterborough_current_condition to my  today_min: sensor
sensor.peterborough_high_temperature to my today_max: sensor
sensor.peterborough_chance_of_precipitation to my today_rain: sensor

and the multiple if statements for the Icon
today_icon::
        #sensor.peterborough_current_condition
        value_template: >-
          {% if state_attr("weather.peterborough_forecast","forecast")[0].condition =='clear-night' %}

Ive been fiddling all day yesterday and here and there today... and nothing works  i just get errors  or unavaliable.. i dont know the right combination... i could use some more help  i stuck.  frustrated

Try posting in this thread. Lots of help there for the subject of triggered template sensors and weather forecasts.
https://community.home-assistant.io/t/new-weather-forecast-template/

1 Like

could you post all of your relevant code as you currently have it? it’s a bit hard to piece together.

however one error i see is this:

      attributes:
        forecast: "{{ hourly['weather.peterborough_forecast[0]'].condition }}"

i think it should be this:

      attributes:
        forecast: "{{ hourly['weather.peterborough'].forecast[0].condition }}"

need to fix this format for all of your sensors… ones like this are also wrong i think:

  sensor:
    - name: Today's rain forecast
      unique_id: today_rain
      state: "{{ hourly['weather.peterborough_forecast[0]'].precipitation_probability }}"

when you create your sensor you should then go to dev-tool->template and see if the sensor is loading properly. something like:

{{ states('sensor.today_min') }} 
{{ states('sensor.today_rain') }} 

and make sure that gives you what you expect.

@FredTheFrog ok i can post in there

@armedad
this is my code… it used to be
weather.peterborough_forecast for it all… but now its only some of it and now its sensors… but ya here is the code… but if i need to post in other form i can too

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
          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:
      today_min:
        state: { states('sensor.peterborough_low_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: "{{ state_attr('weather.peterborough_forecast', 'forecast')[0].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 }}"

so you can see

value_template: "{{ state_attr(‘weather.peterborough_forecast’, ‘forecast’)[0].templow }
no longer exists its now
sensor.peterborough_low_temperature

you can see
weather.peterborough_forecast’, ‘forecast’)[0].temperature
no longer exists
its now
sensor.peterborough_high_temperature

you can see
weather.peterborough_forecast’, ‘forecast’)[0].precipitation_probability
no longer exisits
its replaced with
sensor.peterborough_chance_of_precipitation

and you can see
weather.peterborough_forecast",“forecast”)[0].condition ==
no longer exisits
its replaced with
sensor.peterborough_current_condition

and i been having issues getting a number… i did get a value and the value was
sensor.peterborough_current_condition as a state

just eyeballing it, this part looks close to right… i may be missing something since i’m not running the code, but it looks reasonable to me.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
          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

the rest of the stuff is wrong. but let’s get this part working first.
if you just reduce down to this code (get rid of the rest for now). are you getting the proper temperature when you put this into dev-tools->template:

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

?

the whole second part (everyting from this down:)

  - sensor:
      today_min:

it all looks like you just took the legacy format and threw it underneath the newer template header… and you didn’t actually convert it to the new format.

take a look at the doc that tom gave and follow the new format:

@armedad ok response i get from the template is unavaliable.

as for legacy… from my orginal post i been using the legacy as you call it… and i been spending last couple days trying to convert it… but it doesnt make sense… and since the weather.peterborough_forecast is now a Sensor not a weather for the 4 sensors i needed… the examples dont show it… the weather page for home assistant doesnt show it… as… as its removed from the weather.peterborough_forecast attributes states whatever you call it… so i been frustrated there

so when you send me the template page i dont really know what i looking at … i have the one where you see i have the

  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
          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

the new format

but the 4 sensors i need are no longer in that and the templating doesnt show nothing about that

        unique_id: current_condition
        state: "{{ hourly['sensor.peterborough'].current_condition }}"
        unit_of_measurement: °C

if i do it that way… it gave me errors and uknown error it didnt work either

i even tried this one and it didnt like it either

      - name: test
          state: "{{ sensor.peterborough_low_temperature | default('0') }}"
        # not: "{{ state_attr('sensor.test', 'test') }}"
          attributes:
            test: "{{ now() }}"

i’m having a bit of a hard time understanding your english, so apologies if i’m not getting what you’re saying…

this:

is incorrect. it is not following the format above.
the right way of doing this is to use the weather.get_forecasts, that will put the results in the response_variable, and then pull the information out of that response variable with this format:

"{{ hourly['weather.peterborough_forecast'].forecast[0].temperature }}"

let’s just get the first one working. once we have that working, we can have confidence that the data is being fetched right, then it’s just a matter of getting the info out of the data.

to verify what you said, if you just do the one block of code

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
          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

then try this:

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

do you get sensor unavailable?

if so, let’s fix that. first, where did you put this code?
and also after you made your edits, did you hit the “check confugation” button to make sure it’s all good? then restart home assistant. it won’t load this code automatically…

you’re welcome to try random things as much as you want… eventually a million monkeys in a million years may write shakespear. but i’d suggest that you’ll get a faster result if you don’t try random things and really try to understand the proper format that i’m trying to walk you through…

1 Like

well they dont give you enough examples. and they only show example to the forecast but like i mentioned 4 sensors have been removed from the forecast and independent sensors… but
forecast next hour is unavaliable it doesnt exist in the list of attributes

sorry i have disxlexia so what i type sound good to me not always to someone else

and what i was trying to say is
Low temperature
High Temperature
Condition
precitpition_probably
are no longer weather sensors

there are plain sensors
they been removed from the Weather sensor and put in there own sensor

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