If else in automation

Hello, I want to do this automation, but it gives an error and in the template editor the actions are not executed and I write them blank, as if it were a text.
I wonder if you can use the if and else options in an automation? so as not to have to do an automation to activate and another to deactivate. Thank you

{% if ((states.sensor.temperatura_acs.state | float) > ((states.input_number.temp_acs_minima.state | float))) %}
action:
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.freeds_pwm_aut_man
- switch.freeds_pwm_on_off
{% else %}
action:
- service: switch.turn_on
data: {}
target:
entity_id:
- switch.freeds_pwm_aut_man
- switch.freeds_pwm_on_off
{% endif %}

1 Like

You’re confusing templates and automations. Automations use yaml. Your automation for that would look more like this. Of course you’ll need a trigger to actually fire it…

alias: New Automation
description: ""
mode: single
trigger: []
condition: []
action:
  - if:
      - condition: template
        value_template: >-
          {{ ((states.sensor.temperatura_acs.state | float) >
          ((states.input_number.temp_acs_minima.state | float))) }}
    then:
      - service: switch.turn_off
        data: {}
        target:
          entity_id: switch.back_office_fan
    else:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.back_office_fan
2 Likes