Need help understanding why a template has error in logs but not when I run in developer tools

The below error shows in the logs as soon as I refresh my “template entities”. However, when I go to use the template tester in developer tools no errors are produced.

Can someone show/ teach me how to fix that?

          {% if is_state('binary_sensor.overnight', 'off') %}
            {% set temp = states('sensor.todays_high_temp')|int %}
          {% else %}  
            {% set temp = states('weather.home.attributes.temperature') %}
          {% endif %}
          {%- if states('sensor.todays_high_temp')|int > 63 %}
            {%- if states('sensor.todays_high_temp')|int < 80 %}
              Nice
            {% elif states('sensor.todays_high_temp')|int > 95 %}
              Hot
            {% else %}
              Toasty
            {%- endif %}
          {% elif states('sensor.todays_high_temp')|int < 64 %}
            {%- if states('sensor.todays_high_temp')|int < 32 %}
              Freezing
            {% elif states('sensor.todays_high_temp')|int > 50 %}
              Chilly
            {% else %}
              Cold
            {%- endif %}
          {% else %}
            Unknown
          {%- endif %}
TemplateError('ValueError: Template error: int got invalid input 'unavailable' when rendering template '# {% if is_state('binary_sensor.overnight', 'off') %} # {% set temp = states('sensor.todays_high_temp')|int %} # {% else %} # {% set temp = states('weather.home.attributes.temperature') %} # {% endif %} {%- if states('sensor.todays_high_temp')|int > 63 %} {%- if states('sensor.todays_high_temp')|int < 80 %} Nice {% elif states('sensor.todays_high_temp')|int > 95 %} Hot {% else %} Toasty {%- endif %} {% elif states('sensor.todays_high_temp')|int < 64 %} {%- if states('sensor.todays_high_temp')|int < 32 %} Freezing {% elif states('sensor.todays_high_temp')|int > 50 %} Chilly {% else %} Cold {%- endif %} {% else %} Unknown {%- endif %}' but no default was specified') while processing template 'Template<template=(# {% if is_state('binary_sensor.overnight', 'off') %} # {% set temp = states('sensor.todays_high_temp')|int %} # {% else %} # {% set temp = states('weather.home.attributes.temperature') %} # {% endif %} {%- if states('sensor.todays_high_temp')|int > 63 %} {%- if states('sensor.todays_high_temp')|int < 80 %} Nice {% elif states('sensor.todays_high_temp')|int > 95 %} Hot {% else %} Toasty {%- endif %} {% elif states('sensor.todays_high_temp')|int < 64 %} {%- if states('sensor.todays_high_temp')|int < 32 %} Freezing {% elif states('sensor.todays_high_temp')|int > 50 %} Chilly {% else %} Cold {%- endif %} {% else %} Unknown {%- endif %}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.clothing_forecast'

I suggest you use this instead:

{% set t = states('sensor.todays_high_temp') | int(-99) %}
{% set feels_like= {
  -30 < t <= 32: 'Freezing', 
  32 < t <= 50: 'Cold',
  50 < t <= 64: 'Chilly',
  64 < t <= 80: 'Nice',
  80 < t <= 95: 'Toasty',
  t > 95: 'Hot' } %}
{{ feels_like.get(true, 'unknown') }}

BTW, your example sets a variable named temp but then doesn’t use it anywhere. Where did you intend to use it?

Are you using the temp variable somewhere else? There’s no reason to define it if you’re not going to use it.

If you are using it, you need to correct the else clause, it should be:

{% else %}  
  {% set temp = state_attr('weather.home', 'temperature') %}

You should also include defaults for your int filters and/or include an availability template for the sensor configuration.

The actual reason for the error is that at startup, your high_temp sensor isn’t available until it has been evaluated. Your template is asking the system to convert its unavailable state to an integer with the |int filter, and that’s generating the error.

You can supply the filter with a default value to use in such cases — you’ll see |int(0) used a lot. That’s not a very good fallback value for a temperature, though, particularly in °C.

Taras’s typically-elegant template uses -99 as a default, which will throw Unknown from the rest of the template.

If you’ve written this in YAML as opposed to the UI, you can include an availability template that basically says “if the source sensor isn’t a number, consider this sensor unavailable and don’t evaluate the state template”, thus avoiding any errors.

@123 thank you for showing me this. Yes, I’m a monkey. I will be using the temp variable in this template to handle when the temperature is asked for later in the day to ensure I don’t get a response that was actually for the high of the day that occurred hours previous. I will post that code shortly. I am replying on mobile atm. Thank you so much!

@Troon @Didgeridrew

Thank you both for the information on how I can handle the errors. I am having this same concept occurring on a good number of my templates, so your ideas will help me clean up my mess on an error log.