My weather forecast template doesnt work anymore

@Didgeridrew so i found out
that

        friendly_name: Today weather forecast
        unique_id: today_icon
        state: >-
          {% set condition = states("sensor.peterborough_current_condition") %}
          {% set mapper = {'clear-night': 3,
          'cloudy': 5, 'fog': 16, 'hail': 6,
          'lightning': 13, 'lightning-rainy': 17, 'partlycloudy': 8,
          'pouring': 18, 'rainy': 9, 'rainy': 10,'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') }}"

doesnt work… when i thought it worked it was sunny so it was icon code 12…
but right now its raining so code weather. peterborough forecast icon number is 10 but today icon number is 12

so it should be 10 but its saving as 12… not sure i tried saving it inside the trigger for the hourly update and it erased the today_icon

so not sure… why its reporting 12 even though it should be 10?

Where is the 10 in your mapper? That code can never return 10. (edit: at least, the originally-posted version couldn’t!)

Are you copy-pasting code without even trying to understand it? Just read through it and try to follow the logic of what it’s doing.

i did a quick restart probably why it shows unavailable and unknown

See Post #45 where I told you that was an issue. The keys in the map need to exactly match what the sensor state returns.

I would just use the state of the weather entity in that sensor, as shown in the config I shared in Post #52.

Please don’t post screenshots of code, or at least also include the code as formatted text.

You’ve edited your prior post to include 10 in the mapper now, I see. That code will now never return 9, as the second rainy key overwrites the first.

ya so i was right things not working right

so double checking things
weather.peterborough_forecast is set to “cloudy”

the icon should be “5” its be reported as 12

so earlier when it was “rainy” it should been 9 but reported 12

i noticed the
10 was for [sensor.peterborough_icon_code] which i dont use so i miss read that i shouldnt have mentioned this or read that one

Your code doesn’t use that, though, it uses sensor.peterborough_current_condition. What is the state of that sensor?

thats what dideridrew wrote the code
sensor.peterborough_current_condition

Peterborough Current condition Cloudy

so i just copy and pasted…

now looking all i can see is its case sensitive? one is lower case other is upper case?

Please paste this into Developer Tools / Template and paste the result back here as correctly-formatted code, and if you want to include a screenshot too, go for it:

current:  {{ states('sensor.peterborough_current_condition') }}
forecast: {{ states('weather.peterborough_forecast') }}
icon:     {{ states('sensor.peterborough_icon_code') }}

The mapper lookup is case-sensitive, but the above templates should confirm what’s going on.

the legacy stuff was much easier lol…
here is screen shot … i did try changing this way

        ### Today weather forecast ###
      - name: today_icon
        unique_id: Today weather forecast
        #interval: 10m

        #{% set condition = states("sensor.peterborough_current_condition") %}
        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') }}"

is there a way to do this mapper to read everything ignore if it was upper or lower case incase the weather they change it to a lower case and then it goes upper case and then it buggers up…

Yes. Change the first line of the mapper template to:

          {% set condition = states("weather.peterborough_forecast")|lower %}

i gave the peterborough_current_condition as the forecast one wasnt always reporting anymore like it used it it posted in sensors now… like the precipitation one doesnt work anymore but the chance_of_precipitation one works…

and its messed the weather.home reports things my peterborough one doesnt but the home one doesnt report the values right… its so confusing at times

I have no idea what you’re talking about. Slow down, be precise in your questions, stop posting so many times and let’s solve one issue at a time.

1 Like

sorry dislexia

so i was stating when i orginally posted…
1… Legacy weather was alot better then this new stuff
2… weather.peterborough_forecast doesnt show all the attributes anymore they pusth them to sensors now no longer in the forecast… so that messes things up
3… weather.peterborough_forecast.preciptiation no longer works but the chance_of_preciptation works
4. weather.home_forecast reports it all under one not pushes under multiple sensors and shows precipation sensor.
5… weather.home sensor doesnt match values as the peterborough weather values never seem to get it the same but the forecasts report values different. so thats confusing why peteroborough one gets pushed into sensors like current_condition yet it used to be weather.peterborough_forecast. current_condition or it was condition but now its sensor.peterborough_current_condition

as the weather examples use the weather. example and not the sensor.

sorry rambling and my dislexia doesnt help sounds right in my head but may not sound right to you

and i appreciate all the help you guys give me…

and you guys know all this code… is this code specific to HA or is it this lambda or is it c++ that you guys know with mapper etc