That is not quite true. I am using this code from topic one. The device id exists and in the Value line i am slipped. But i have change this. I created the automation using the editior.
Thanks a lot for this Code this helps me very well. I check this and give feedback.
Hello @tom_l I tested this code but it doesn’t work. The light does not turn on or change color.
Where is my mistake, can you help me? I can not find my mistake
- id: '9999999999'
alias: PV-Anlage
description: ""
trigger:
- platform: state
entity_id: sensor.sma_power_template
to:
action:
- service: light.turn_on
target:
entity_id: light.schreibtischlampe
data:
color_name: >
{% set power == states('sensor.sma_power_template')|float(10101010) %}
{% if power == 10101010 %}
fuchsia {# error colour #}
{% elif power <= 500 %}
lightyellow
{% elif 500 < power <= 2500 %}
red
{% elif 2500 < power <= 3500 %}
yellow
{% elif 3500 < power <= 7500 %}
darkgreen
{% else %}
blue
{% endif %}
The Logs are empty. After Restart the System i have this in the Logs:
Logger: homeassistant.components.automation
Source: components/automation/config.py:207
Integration: Automatisierung (documentation, issues)
First occurred: 12:30:45 (1 occurrences)
Last logged: 12:30:45
Automation with alias 'PV-Anlage' could not be validated and has been disabled: template value should be a string for dictionary value @ data['action'][0]['data']. Got OrderedDict([('color_name', "{% set power == states('sensor.sma_power_template')|float(10101010) %} {% if power == 10101010 %}\n fuchsia {# error colour #}\n{% elif power <= 500 %}\n lightyellow\n{% elif 500 < power <= 2500 %}\n red\n{% elif 2500 < power <= 3500 %}\n yellow\n{% elif 3500 < power <= 7500 %}\n darkgreen\n{% else %}\n blue\n{% endif %}")]
**Second Entry**
Logger: homeassistant.helpers.event
Source: helpers/template.py:460
First occurred: 12:31:12 (1 occurrences)
Last logged: 12:31:12
Error while processing template: Template("{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1771, in forgiving_float_filter
return float(value)
ValueError: could not convert string to float: 'unavailable'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1774, in forgiving_float_filter
raise_no_default("float", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1472, in raise_no_default
raise ValueError(
ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' 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 576, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' but no default was specified
**Third Entry**
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:364
First occurred: 12:31:12 (1 occurrences)
Last logged: 12:31:12
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}' but no default was specified') while processing template 'Template("{{ iif(states('sensor.sma_power_total'), (states('sensor.sma_power_total') | float/1000) | round(0)) }}")' for attribute '_attr_native_value' in entity 'sensor.sma_power_total_template'
Thank you very much for your patience. I don’t get it right yet.