Help in yaml syntax

Good morning,

I’m sorry but I’m a noob in coding and so, obviously, I have a big problem in yaml syntax.
I’m trying to create a sensor in configuration.yaml with if-then but I don’t find the way for right code; this is my last version and Home Assistant tells that is wrong :

template:

  - sensor:
    - name: "Vel VMC cucina nonna def"
      unique_id: b7bbe7fe-a39f-4e7e-ae0f-015a12a4d5dd
      state: >
        {% if is_state('binary_sensor.clima_cucina_nonna_a4s_input1', 'on') %}
          0
        {% else %}
          {% if is_state('binary_sensor.clima_cucina_nonna_a4s_input2', 'on') %}
            0
          {% else %}
            {{ states('sensor.vel_vmc_cucina_nonna) | int }}
          {% endif %}
        {% endif}

Can someone help me in this my stupid lack ?

Thanks in advance for your reply

try

template:

  - sensor:
    - name: "Vel VMC cucina nonna def"
      unique_id: b7bbe7fe-a39f-4e7e-ae0f-015a12a4d5dd
      state: >
        {% if is_state('binary_sensor.clima_cucina_nonna_a4s_input1', 'on') %}
          0
          {% elif is_state('binary_sensor.clima_cucina_nonna_a4s_input2', 'on') %}
            0
          {% else %}
          {{ states('sensor.vel_vmc_cucina_nonna') | int }}
        {% endif %}
1 Like

That’s 2 things…

Ok,

in post 3 gave my the right solution for my syntax (after watching it I understand that I’m a inattentive noob).

The syntax from

in post 2 instead is more clean and efficient than mine, I will use it for the next sensors I must create.

Thank You very much (to all of them) and have a nice day !!!

1 Like