Template issues after 0.115

Hi all,
I’m stumbling around a template problem and would love to hear from you.
I have two sensors based on a template that provide the state of two covers. Starting from version 0.115, these sensors sometime works well after startup, and sometime fail. I most cases (75% of the time), they operate perfectly, in the rest 25%, I got the following errors when starting my Raspberry Pi:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 261, in _async_template_startup
    result_info = async_track_template_result(
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 933, in async_track_template_result
    tracker.async_setup(raise_on_template_error)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 740, in async_setup
    self._info[template] = template.async_render_to_info(variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 401, in async_render_to_info
    render_info._result = self.async_render(variables, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 332, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 3, in top-level template code
TypeError: '<' not supported between instances of 'NoneType' and 'int'
2020-10-07 12:52:58 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 261, in _async_template_startup
    result_info = async_track_template_result(
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 933, in async_track_template_result
    tracker.async_setup(raise_on_template_error)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 740, in async_setup
    self._info[template] = template.async_render_to_info(variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 401, in async_render_to_info
    render_info._result = self.async_render(variables, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 332, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 3, in top-level template code
TypeError: '<' not supported between instances of 'NoneType' and 'int'

The two sensors are identical, this is how they are setup:

sensor:
  - platform: template
    sensors:
      br_blinds:
        friendly_name: "Bedroom blinds"
        value_template: >-
          {% if is_state('cover.shelly_shsw_25_c45e58', 'closed') %}
            closed
          {% elif state_attr('cover.shelly_shsw_25_c45e58', 'current_position') < 39%}
            shade
          {% else %}
            Open
          {% endif %}

If you have any idea on what is wrong, I would appreciate your assistance.

Yaron

I am having the same issue with the following template:

Template("{{ (state_attr('climate.ff6b18_channel1', 'current_temperature')) >= (state_attr('climate.ff6b18_channel1', 'temperature')) }}")

TypeError: ‘>=’ not supported between instances of ‘NoneType’ and ‘NoneType’
It looks like it is working well. But your description of the percentage failing rings a bell to me that not always the automation where the template is used was working as expected.