RichardU
(Richard)
September 23, 2020, 8:35pm
1
Why would this give me a configuration error?
action:
service: input_select.select_option
data_template:
entity_id: input_select.family_lamps
option: >
{% if is_state("input_select.family_lamps", "Turn-on") %}
"Motion-always"
{% elif if is_state("input_select.family_lamps", "Motion-always") %}
"Turn-on"
{% endif %}
Error Message:
Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'is_state') for dictionary value @ data['action'][0]['data_template']. Got None. (See /config/configuration.yaml, line 127)
Cheers, Richard
tjntomas
(Tomas Jansson)
September 23, 2020, 8:47pm
2
Remove the extra if
, after elif
:
` {% elif is_state("input_select.family_lamps", "Motion-always") %}`
RichardU
(Richard)
September 23, 2020, 11:23pm
4
Hmmm. that took care of the configuration error, but I’m not getting the expected results
This works:
action:
service: input_select.select_option
data_template:
entity_id: input_select.family_lamps
option: "Motion-always"
But this doesn’t, even when input_select.family_lamps does equal “Turn-on”
action:
service: input_select.select_option
data_template:
entity_id: input_select.family_lamps
option: >
{% if is_state("input_select.family_lamps", "Turn-on") %}
"Motion-always"
{% endif %}
rccoleman
(Rob Coleman)
September 23, 2020, 11:40pm
5
It could be extra whitespace around the string. Maybe try this:
action:
service: input_select.select_option
data_template:
entity_id: input_select.family_lamps
option: >-
{%- if is_state("input_select.family_lamps", "Turn-on") -%}
"Motion-always"
{%- endif -%}
RichardU
(Richard)
September 24, 2020, 3:33am
6
Thanks, I think it was maybe too many leading spaces on the template. This now works
action:
service: input_select.select_option
data_template:
entity_id: input_select.family_lamps
option: >-
{% if is_state('input_select.family_lamps', 'Turn-on') %}
Motion-always
{% elif not is_state('input_select.family_lamps', 'Turn-on') %}
Turn-on
{% endif %}