The problem
After the home assistant started, I saw this error in the logs.
What version of Home Assistant Core has the issue?
core-2024.5.0
it also happened with older versions.
What type of installation are you running?
Home Assistant OS
Link to integration documentation on our website
Diagnostics information
Complete log:
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:197
integration: Template ([documentation](https://www.home-assistant.io/integrations/template), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+template%22))
First occurred: 4:08:21 PM (9 occurrences)
Last logged: 4:08:21 PM
TemplateError('TypeError: argument of type 'NoneType' is not iterable') while processing template 'Template<template=({%- set ns = namespace(contactsensors=[]) -%} {%- set ns.contactsensors = states.binary_sensor | selectattr('entity_id', 'in', state_attr('binary_sensor.contact_sensors_roller_shade', 'entity_id')) | selectattr('state', 'eq', 'on') | map(attribute='name') | list -%} {{ ns.contactsensors | count }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.security_roller_shade_open_count'
TemplateError('TypeError: argument of type 'NoneType' is not iterable') while processing template 'Template<template=({%- set ns = namespace(contactsensors=[]) -%} {%- set ns.contactsensors = states.binary_sensor | selectattr('entity_id', 'in', state_attr('binary_sensor.contact_sensors_roller_shade', 'entity_id')) | selectattr('state', 'eq', 'on') | map(attribute='name') | list -%} {{ ns.contactsensors | join(', ') }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.security_roller_shade_open_info'
Those sensors are template sensors, and the code for them is:
## sensor.security_roller_shade_open_count
- name: "security: roller-shade open - count"
unique_id: a50f776c-4d99-495e-89f4-29a252844e04
icon: mdi:door-open
state: >
{%- set ns = namespace(contactsensors=[]) -%}
{%- if states is not none and states.binary_sensor is not none -%}
{%- set ns.contactsensors = states.binary_sensor
| selectattr('entity_id', 'in', state_attr('binary_sensor.contact_sensors_roller_shade', 'entity_id'))
| selectattr('state', 'eq', 'on')
| map(attribute='name') | list -%}
{{ ns.contactsensors | count }}
{%- endif %}
## sensor.security_roller_shade_open_info
- name: "security: roller-shade open - info"
unique_id: a50f776c-4d99-495e-89f4-29a252844e05
icon: mdi:door-open
state: >
{%- set ns = namespace(contactsensors=[]) -%}
{%- if states is not none and states.binary_sensor is not none -%}
{%- set ns.contactsensors = states.binary_sensor
| selectattr('entity_id', 'in', state_attr('binary_sensor.contact_sensors_roller_shade', 'entity_id'))
| selectattr('state', 'eq', 'on')
| map(attribute='name') | list -%}
{{ ns.contactsensors | join(', ') }}
{%- endif %}
while trying to solve this problem, I added the line with
{%- if states is not none and states.binary_sensor is not none -%}
but it did not have any effect.