I have written a template sensor and that the moment it looks like that:
platform: template
sensors:
# Template created to display either a green or black bin whichever is next
bin:
value_template: >-
{% if this %}
State1
{% else %}
State2
{% endif %}
friendly_name_template: >-
{% if this %}
Name1
{% else%}
Name2
{% endif %}
icon_template: >-
{% if this %}
icon1
{% else %}
icon2
{% endif %}
The if statement is the same for each template. Is there a way to “simplify” the code so that the if statement is only used once and the template are surrounded?
I have tried several way of formatting it but the check config always come back saying it is not correct