Template as condition state

Hi all,
I know this one isn’t working, since it evaluates always to false, but doesn’t give me any error… Is there a way to write this, or have I to use the entire logic in a template? It goes to an automation condition

  - condition: state
    entity_id: switch.vmc
    state: {{ iif(states('sensor.cessione_energia_istantanea') | float(0) > 50, 'off', 'on') }}


- condition: template
  value_template: "{{ states('sensor.cessione_energia_istantanea') | float(0) > 50 }}"

Well, that’s not the same… Basically, I want to check the state of the switch.vmc that should be off or on depending by the value of the other sensor…

the state of switch.vmc will be on or off. It’s not going to change state based on the value of the other sensor. Are you saying you want to check the state of switch.vmc and look at the value of the other sensor?


is the state of switch.vmc on and sensor.cessione_energia_istantanea > 50?

Nope, I want to check, so the automation has to continue, if the sensor switch.vmc is off when the sensor.cessione_energia_istantanea > 50 or if the switch.vmc is on when the sensor.cessione_energia_istantanea <= 50.

- condition: template
  value_template: >
    {% set energy = states('sensor.cessione_energia_istantanea') | float(0) %}
    {% set vmc = states('switch.vmc') %}
    {{ (vmc == 'off' and energy > 50) or (vmc =='on' and energy <= 50) }}

ok, so it’s not possible to use a “formula” to define the value of the state on a state condition, you have to use a condition template alltogether… Thanks :slight_smile: