it definitely does not like my template file!
2022-07-05 20:30:12 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: list object has no element 1 when rendering '{{ states.input_select.insteon_devices.state.split('(')[1].split(')')[0] }}'
2022-07-05 20:30:12 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ states.input_select.insteon_devices.state.split('(')[1].split(')')[0] }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 409, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1842, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "
File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 326, in getattr
value = getattr(obj, attribute)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1868, in _fail_with_undefined_error
raise ex
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1859, in _fail_with_undefined_error
return super()._fail_with_undefined_error(*args, **kwargs)
jinja2.exceptions.UndefinedError: list object has no element 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 525, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 411, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: list object has no element 1
2022-07-05 20:30:12 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: list object has no element 1') while processing template 'Template("{{ states.input_select.insteon_devices.state.split('(')[1].split(')')[0] }}")' for attribute '_attr_native_value' in entity 'sensor.selected_insteon_device'
2022-07-05 20:30:12 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ states('input_number.target_insteon_group')|int }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 409, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1842, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1634, in forgiving_int_filter
raise_no_default("int", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1331, in raise_no_default
raise ValueError(
ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ states('input_number.target_insteon_group')|int }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 525, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 411, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ states('input_number.target_insteon_group')|int }}' but no default was specified
2022-07-05 20:30:12 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{{ states('input_number.target_insteon_group')|int }}' but no default was specified') while processing template 'Template("{{ states('input_number.target_insteon_group')|int }}")' for attribute '_attr_native_value' in entity 'sensor.targeted_insteon_group'
this is my template file:
##
## These are template sensors.
##
## Given an insteon Scene Number, return a list of entities
## This requires two pieces of information, the target address as well as the group number for multi-button, multi-outlet devices.
## In the code for the sensor, first a list is created using the Insteon Address and the actual button (or outlet) number
## Then this list is parsed against the entities themsleves to get the entities in the given Insteon Scene
##
## sensor.insteon_scene_entities
##
- name: insteon_scene_entities
state: "{{ 'OK' }}"
attributes:
scene_entities: "
{% set glist = state_attr('sensor.insteon_groups','groups') %}
{% set devices = namespace(switch=[]) %}
{% for value in glist %}
{% if (value.group | int == states('input_select.insteon_modem_groups') | int) %}
{% set devices.switch = devices.switch + [(value.device_address[0:2] + '.' + value.device_address[2:-2] + '.' + value.device_address[-2:] + '_' + value.button | string) | upper] %}
{% endif %}
{% endfor %}
{% set gp = namespace(groups=[]) %}
{% for ent in integration_entities('insteon') %}
{% if state_attr(ent,'insteon_address') + '_' + state_attr(ent,'insteon_group') | string in devices.switch %}
{% set gp.groups = gp.groups + [ent] %}
{% endif %}
{% endfor %}
{{ gp.groups | unique | sort }}"
##
## This sensor for scene names and numbers is created by hand based on my installation. There is no local storage in the ALDB or hub where the group names from the Insteon app are stored.
## Using the app or just based on experiements, you can create a map like below for scene names and scene number.
## This just helps you use some friendly names but can be used in automations/scripts for turning on an Insteon scene by using a friendly name.
##
## sensor.insteon_group_names
##
- name: insteon_group_names
state: "
{% for gpname in states.sensor.insteon_group_names.attributes %}
{% if state_attr('sensor.insteon_group_names',gpname) == states('input_select.insteon_modem_groups') %}
{{ gpname | replace('_', ' ') }}
{% endif %}
{% endfor %}"
attributes:
Unknown_Group_34: 34
Unknown_Group_36: 36
Unknown_Group_105: 105
Unknown_Group_254: 254
and when i try to change the select item i get this:
2022-07-05 20:39:30 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities input_number.target_insteon_group or it is/they are currently not available
2022-07-05 20:39:30 WARNING (MainThread) [homeassistant.helpers.entity_component] Forced update failed. Entity sensor.insteon_group_names not found.
2022-07-05 20:39:32 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'None' has no attribute 'attributes' when rendering '{% set scene_number = (state_attr('input_select.insteon_modem_groups','options')[repeat.index - 1]) %} {% set glist = states.sensor.insteon_group_names.attributes %} {% set gstring = namespace(grname=[]) %} {% set gstring.grname = 'Insteon Group ' + scene_number %} {% for gname in glist %} {% if state_attr('sensor.insteon_group_names',gname) == scene_number %} {% set gstring.grname = gstring.grname + ' (' + (gname | replace('_',' ')) + ')' %} {% endif %} {% endfor %} {{ gstring.grname }}'
i’ll try to find out how to nuke these groups from any devices and then try this all again. In both Indigo & Insteon-MQTT we could remove links but it doesn’t appear we can from the native integration.