Template all of the sudden started reporting "unknown". Hoping for help on figuring out what's causing it

Hello all,

I imagine the below has a simple solution as I am very new to home assistant.

I’m hoping someone can help me figure out why some sensors have started reporting unknown in the GUI which also causes them to report the “unknown” in a morning weather report I have been using for months. – But in developer tools when using the states area, the template editor shows that the sensor has a value.

Current forecast, high temp is the one I am focusing on but am providing my whole sensor template below.

The attribute “high temp” of the current forecast sensor contains a value when using developer states:

          high_temp: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
            {{ forecast.temperature }}

but when trying to recite the high temp value by using the code snippet below. It says it is “None”

            expect a high of {{ state_attr('sensor.current_forecast','high_temp') }}

Please see full template below (the above are excerpts of it). Thank you all! for any help you can provide!!

Sensor template:

  - platform: template
    sensors:
      current_forecast:
        friendly_name: Current Forecast
        unit_of_measurement: ""
        icon_template: mdi:weather-sunny
        value_template: >-
          {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
          {{ forecast.condition }}
        attribute_templates:
          high_temp: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
            {{ forecast.temperature }}
          overnight_low: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[1] %}
            {{ forecast.templow }}
          wind_bearing: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
            {{ forecast.wind_bearing }}
          wind_speed: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
            {{ forecast.wind_speed }}
          precipitation: >-
            {% set forecast = state_attr('weather.turner_house','forecast')[0] %}
            {{ forecast.precipitation }}
      current_forecast_detail:
        friendly_name: Current Forecast Detail
        unit_of_measurement: ""
        icon_template: mdi:weather-sunny
        value_template: >-
          {%- macro getReport() -%}
            {{ [
              'Today in Morristown ', 
              'Later Today ',
              'For the rest of the day'
              ] | random }}
            expect a high of {{ state_attr('sensor.current_forecast','high_temp') }}
            {%- if states('sensor.current_forecast') == 'sunny' and is_state('binary_sensor.night','off')%}
              {{ [
                  'and sunny.', 
                  'with sun.',
                  'with sunny conditions prevailing.'
                  ] | random }}
            {%- elif states('sensor.current_forecast') == 'sunny' and is_state('binary_sensor.night','on') %}
              {{ [
                'and clear.', 
                'with clear skies.'
                ] | random }}
            {%- elif states('sensor.current_forecast') == 'clear-night' %}
              {{ [
                'and clear.', 
                'with clear skies.'
                ] | random }}
            {%- elif states('sensor.current_forecast') == 'rainy' %}
              {{ [
                'with rain.', 
                'with showers.',
                'and rainy.'
                ] | random }}
              {{ [
                'Rainfall accumulations ', 
                'Total Rainfall amounts '
                ] | random }}
                near {{ state_attr('sensor.current_forecast','precipitation') }} inches
                possible.
            {%- elif states('sensor.current_forecast') == 'snowy' %}
              {{ [
                'with snow.', 
                'with snow showers.'
                ] | random }}
              {{ [
                'Snowfall accumulations ', 
                'Total snowfall amounts '
                ] | random }}
                near {{ state_attr('sensor.current_forecast','precipitation') }} inches
                possible.
            {%- elif states('sensor.current_forecast') == 'snowy-rainy' %}
              {{ [
                  'with mix preciptation possible.', 
                  'with snow and rain showers.'
                  ] | random }}
              Total accumulation near {{ state_attr('sensor.current_forecast','precipitation') }} inches
                possible.    
            {%- elif states('sensor.current_forecast') == 'windy' %}
              {{ [
                'and windy.', 
                'with lots of wind.'
                ] | random }}
            {%- elif states('sensor.current_forecast') == 'fog' %}
              {{ [
                'and foggy.', 
                'with some fog.'
                ] | random }}
            {% elif states('sensor.current_forecast') == 'cloudy' %}
              {{ [
                'with clouds.', 
                'with cloudy skies.'
                ] | random }}
            {% elif states('sensor.current_forecast') == 'partlycloudy' %}
              {{ [
                  'with some clouds.', 
                  'with partly cloudy skies.',
                  'with scattered clouds'
                  ] | random }}
            {%- elif states('sensor.current_forecast') == 'hail' %}
              {{ [
                'with severve thunderstorms possible.', 
                'with hail possible.'
                ] | random }}
              {{ [
                'Rainfall accumulations ', 
                'Total Rainfall amounts '
                ] | random }}
                near {{ state_attr('sensor.current_forecast','precipitation') }} inches
                possible.
            {%- elif states('sensor.current_forecast') == 'lightning' %}
              {{ [
                'with thunderstorms possible.', 
                'with the potential of thunderstorms.'
                ] | random }}
              {{ [
                'Rainfall accumulations ', 
                'Total Rainfall amounts '
                ] | random }}
                near {{ state_attr('sensor.current_forecast','precipitation') }} inches
                possible.
            {% endif -%}

            {{ [
                'Later tonight expect a low of ', 
                'Overnight expect a low of '
                ] | random }}
            {{ state_attr('sensor.current_forecast','overnight_low') }} degrees. 
          {%- endmacro -%}
          {# a macro that removes all newline characters, empty spaces, and returns formatted text  #}
            {%- macro cleanup(data) -%}
              {%- for item in data.split("\n")  if item | trim != "" -%}
                {{ item | trim }} {% endfor -%}
          {%- endmacro -%}

          {# a macro to call all macros :)  #}
            {%- macro mother_of_all_macros() -%}
              {{ getReport() }}
            {%- endmacro -%}
            
            {# Call the macro  #}
            {{- cleanup(mother_of_all_macros()) -}}
1 Like

Remove this:

Non numeric sensors can no longer have a unit of measurement. Even a null one.

Ahhh, thank you for this information. I had read that on a previous release and had fixed it in other places but didn’t think about that was going on also here.

Thank you for your help Tom!!

1 Like

Soo that’s why. Thank you!