No, he changed it for testing. His error is related to startup issues with the update to 2021.5 where silent errors produced by things being ‘undefined’ in templates are no longer ignored. This results in the template sensor failing the onboarding process and a listener is never created. You basically have to safely access things from here on out, even at startup when things aren’t initialized.
See his error:
It’s referencing Device which is a key inside root. I.E. root is set to none. That only happens at startup (Typically).
With the new Energy focus in HA 2021.8 I am wondering what the criterias is for our Steca inverters to be able to be selectable as a Solar input?
I know that it is Power (Watt) that is measured, and Energy (wh) that is wanted as input - but no matter how I tweak any sensor I can not figure out how to get anything working.
Do i need to go to a ModBus solution for this to work?
Every day my home assistant stops responding some where in the night. It started after using the REST integration as Rene (see threat)
The error i get is:
2021-09-22 03:16:42 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: dict object has no element 2') while processing template 'Template("{% set root = state_attr('sensor.solar_frontier', 'root') %} {% if root.Device.Measurements.Measurement[2]["@Value"] is defined %}
{{ root.Device.Measurements.Measurement[2]["@Value"] | round(0)}}
{% else %}
0
{% endif %}")' for attribute '_attr_native_value' in entity 'sensor.solar_live_output'
Below is the config i am using
# Configuration.yaml entry
sensor:
- platform: rest #Solar Frontier Inverter
resource: http://x.x.x.x/measurements.xml
json_attributes:
- root
- Measurements
name: Solar_Frontier
scan_interval: 60
timeout: 20
value_template: 'OK'
- platform: template
sensors:
solar_live_output:
value_template: >
{% set root = state_attr('sensor.solar_frontier', 'root') %}
{% if root.Device.Measurements.Measurement[2]["@Value"] is defined %}
{{ root.Device.Measurements.Measurement[2]["@Value"] | round(0) }}
{% else %}
0
{% endif %}
device_class: power
unit_of_measurement: 'W'
friendly_name: Solar Frontier Live power
The inverter has all value’s at daytime but at night some value disappear from measurements.xml (complete lines disappear at night)
Most of the error messages have disappeared. There is only one error left every day. Is there a way to resolve this condition to?
2021-09-28 19:15:41 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('UndefinedError: No first item, sequence was empty.') while processing template 'Template("{% set root = state_attr('sensor.solar_frontier', 'root') %} {% if root.Device.Measurements.Measurement is defined and root.Device.Measurements.Measurement | length > 0 %}
{{ (root.Device.Measurements.Measurement | selectattr('@Type', 'eq', 'AC_Power') | list | first)['@Value'] | default }}
{% else %}
0
{% endif %}")' for attribute '_attr_native_value' in entity 'sensor.solar_live_output'
And now the complete error hoping someone can help me solve it
Logger: homeassistant.helpers.event
Source: helpers/template.py:399
First occurred: 2:00:46 AM (2 occurrences)
Last logged: 2:00:46 AM
Error while processing template: Template("{% set root = state_attr('sensor.solar_frontier', 'root') %} {% if root.Device.Measurements.Measurement is defined and root.Device.Measurements.Measurement | length > 0 %} {{ (root.Device.Measurements.Measurement | selectattr('@Type', 'eq', 'AC_Power') | list | first)['@Value'] | default }} {% else %} 0 {% endif %}")
Error while processing template: Template("{% set root = state_attr('sensor.solar_frontier', 'root') %} {% if root.Device.Measurements.Measurement is defined and root.Device.Measurements.Measurement | length > 0 %} {{ (root.Device.Measurements.Measurement | selectattr('@Type', 'eq', 'Temp') | list | first)['@Value'] | default }} {% else %} 0 {% endif %}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 397, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1604, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 2, in top-level template code
File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 303, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: No first item, sequence was empty.
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 513, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 399, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: No first item, sequence was empty.
I think the problem is that sometimes @Type = AC_Power is not available. But i dont know how to change the command to first check is it is there or not.