How to compare sensor status in automation

Hello,

I’m setting up a complex automation to handle the best charging approach for my house…I would like to perform a status check between sensor to check if a “selected” value in a sensor in a certain time is aligned with offical sensor… below the code i wrote but seems not working because the result is always negative. what is wrong?

- if:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.ignora_consumi
        state: "on"
      - condition: or
        conditions:
          - condition: state
            entity_id: input_select.fascia_selezionata
            state: Tutte
          - condition: state
            entity_id: sensor.pun_fascia_corrente
            state: "{{states('input_select.fascia_selezionata')}}"
  then:
    - service: switch.turn_on
      data: {}
      target:
        entity_id: switch.presa_di_ricarica_auto
  else:
    []

This is not valid:

The state key does not support templates.

Use a template condition.

          - condition: template
            value_template: "{{ states('sensor.pun_fascia_corrente') == states('input_select.fascia_selezionata') }}"