The configuration check give the message : Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘%’) for dictionary value @ data[‘sensors’][‘days_num1’][‘value_template’]. Got “{{% if is_state(‘input_select.days1’, ‘Semaine’)%} ‘2’ {% elif is_state(‘input_select.days1’, ‘Week-end’) %} ‘1’ {% else %} ‘0’ {% endif %}}”. (See ?, line ?).
What do I wrong ? I do not find the solution on the forum
Thanks in advance for your king help
Patou
Remove the outer curly braces from your template . Also you don’t need quotes around ‘2’, ‘1’, ‘0’ unless you want your value to actually be ‘2’. I suspect you really want 2. Finally you need to use the </> selector not the blockquote you used to have the text formatted properly in the question above.
You can also use inline-if style which is slightly more compact:
- platform: template
sensors:
days_num1:
friendly_name: Jours 1
value_template: >
{{ 2 if is_state('input_select.days1', 'Semaine') else 1 if is_state('input_select.days1', 'Week-end') else 0 }}
Basically it reads like: 2 if Semaine else 1 if Week-end else 0
The > symbol means the template starts on the next line. In that case, the template should not be delimited with any quotes. If you omit the > symbol then the tempalte must begin in the same line and must be delimited with quotes, like this:
value_template: "{{ 2 if is_state('input_select.days1', 'Semaine') else 1 if is_state('input_select.days1', 'Week-end') else 0 }}"
Your second template uses the inline if/then/else but then nests them to produce more options.
I am going to have to study that as it’s VERY compact.
Though it ‘may’ be a tad more difficult to ‘read’ (human wise) and thus maintain.
Still … “HFUHRUHURR”