Hello,
I have a script that receives input via fields. Based on those fields’ input, I would like to set a variable. I am editing the script externally but when I load it I receive an error message (see below).
My script:
raffstore_set_position:
alias: Raffstore_set_position
sequence:
- variables:
# I know the error is coming from that comparison below.
# If I change the fields name to hard coded values, the script runs fine
tilt: >-
{% if {{ state_attr( entity_id , 'current_position')|int < position|int}} %}
100
{% elif {{ state_attr( entity_id , 'current_position')|int > position|int}} %}
0
{% else %}
{% endif %}
- event: set_Raffstore_Positionen
event_data:
key: '{{ entity_id }}_Tilt'
value: '{{ tilt }}'
- action: cover.set_cover_position
data:
position: '{{ position }}'
target:
entity_id: '{{ entity_id }}'
fields:
entity_id:
description: The cover entity
example: cover.X
position:
description: position to go to
example: 80
mode: parallel
description: Set position of Raffstore
icon: mdi:blinds-horizontal
Here is the error from the Logs:
Logger: homeassistant.components.script
Source: components/script/config.py:147
integration: Script (documentation, issues)
First occurred: 2:59:42 PM (20 occurrences)
Last logged: 4:52:53 PM
Script with alias 'Raffstore_set_position' could not be validated and has been disabled: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['sequence'][0]['variables']['tilt']. Got "{% if {{ state_attr( entity_id , 'current_position') }} < 80 %}\n 100\n{% elif {{ state_attr( entity_id , 'current_position') }} > 80 %}\n 0\n{% endif %}\n"
Script with alias 'Raffstore_set_position' could not be validated and has been disabled: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['sequence'][0]['variables']['tilt']. Got "{% if {{ state_attr( entity_id , 'current_position') }} < 80 %}\n 100\n{% elif {{ state_attr( entity_id , 'current_position') }} > 80 %}\n 0\n{% endif %}"
Script with alias 'Raffstore_set_position' could not be validated and has been disabled: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['sequence'][0]['variables']['tilt']. Got "{% if state_attr( 'cover.raffstore_hst_links' , 'current_position') < {{position}} %}\n 100\n{% elif state_attr( 'cover.raffstore_hst_links' , 'current_position') > {{position}} %}\n 0\n{% endif %}\n"
Script with alias 'Raffstore_set_position' could not be validated and has been disabled: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['sequence'][0]['variables']['tilt']. Got "{% if state_attr( 'cover.raffstore_hst_links' , 'current_position') < {{position|int}} %}\n 100\n{% elif state_attr( 'cover.raffstore_hst_links' , 'current_position') > {{position|int}} %}\n 0\n{% endif %}"
Script with alias 'Raffstore_set_position' could not be validated and has been disabled: invalid template (TemplateSyntaxError: expected token ':', got '}') for dictionary value @ data['sequence'][0]['variables']['tilt']. Got "{% if {{ state_attr( entity_id , 'current_position')|int < position|int}} %}\n 100\n{% elif {{ state_attr( entity_id , 'current_position')|int > position|int}} %}\n 0\n{% else %} {% endif %}"
Thanks for your support!
Tim