Hello,
I’m having this template problem.
I have another sensor with the same template and the HA does not report an error, but this one is reporting 2 errors and 1 warning.
How do I resolve it? it has the correct value in its state.
Logger: homeassistant.helpers.event
Source: helpers/template.py:400
First occurred: 23:05:11 (1 occurrences)
Last logged: 23:05:11
Error while processing template: Template("{{ ( (float(states.sensor.energy_shelly_em_casa_monthly_total.state) * 0.1547) + float(states.sensor.monthly_energy_cicle_days_shelly_em_casa.state) * 0.2143 ) | round(2) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, 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 1, in top-level template code
TypeError: can't multiply sequence by non-int of type 'float'
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 514, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: can't multiply sequence by non-int of type 'float'
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:73
Integration: Template (documentation, issues)
First occurred: 23:05:11 (1 occurrences)
Last logged: 23:05:11
TemplateError('TypeError: can't multiply sequence by non-int of type 'float'') while processing template 'Template("{{ ( (float(states.sensor.energy_shelly_em_casa_monthly_total.state) * 0.1547) + float(states.sensor.monthly_energy_cicle_days_shelly_em_casa.state) * 0.2143 ) | round(2) }}")' for attribute '_attr_native_value' in entity 'sensor.custo_energia_mes_casa'
Logger: homeassistant.helpers.template
Source: helpers/template.py:1254
First occurred: 23:05:11 (2 occurrences)
Last logged: 23:05:11
Template warning: 'float' got invalid input 'unknown' when rendering template '{{ ( (float(states.sensor.energy_shelly_em_casa_monthly_total.state) * 0.1547) + float(states.sensor.monthly_energy_cicle_days_shelly_em_casa.state) * 0.2143 ) | round(2) }}' but no default was specified. Currently 'float' will return 'unknown', however this template will fail to render in Home Assistant core 2022.1
my template:
sensor:
- platform: template
sensors:
custo_energia_mes_casa:
friendly_name: "Fatura Energia Mensal"
icon_template: "mdi:currency-eur"
value_template: >-
{{ ( (float(states.sensor.energy_shelly_em_casa_monthly_total.state) * 0.1547) + float(states.sensor.monthly_energy_cicle_days_shelly_em_casa.state) * 0.2143 ) | round(2) }}
unit_of_measurement: "€"
Obrigado