Need help to set a switch depending on HVAV mode

Hi,

I am struggling at the moment with the following Code…
I have installed the climate_template.
First is setting the temperature. I have to consider an offset between -3 and +3 ontop on a basis temperature. this is working
Depending on the HVAC mode, I want to enable the heater (In my case you have to enable the heater and I want to do that depending on the mode. “auto” = heater disabled, “heat” = heater enabled).
With my code, always the switch will be activated. I guess because of the else conditions. Seems that the comparison is not working, but don’t know what is wrong there.
Any hints?

Thanks Steffen

- platform: climate_template
  name: Proxon Template Heizung Schlafzimmer
  unique_id: proxon_template_heizung_schlafzimmer
  modes:
    - "auto"  
    - "heat"
  max_temp: 23
  min_temp: 17
  current_temperature_template: "{{ states('sensor.proxon_ist_temperatur_schlafzimmer') }}"
  set_temperature: 
    - service: modbus.write_register
      data_template:
        hub: proxon
        unit: 41
        address: 216
        value: > 
          {% if ((state_attr('climate.proxon_template_heizung_schlafzimmer', 'temperature') | int) - (states('sensor.proxon_mitteltemperatur_schlafzimmer') | int)) == -3 %}
          65533
          {% elif ((state_attr('climate.proxon_template_heizung_schlafzimmer', 'temperature') | int) - (states('sensor.proxon_mitteltemperatur_schlafzimmer') | int)) == -2 %}
          65534
          {% elif ((state_attr('climate.proxon_template_heizung_schlafzimmer', 'temperature') | int) - (states('sensor.proxon_mitteltemperatur_schlafzimmer') | int)) == -1 %}
          65535
          {% else %}
          {{ ((state_attr('climate.proxon_template_heizung_schlafzimmer', 'temperature') | int) - (states('sensor.proxon_mitteltemperatur_schlafzimmer') | int)) }}
          {% endif %}
  set_hvac_mode:
    - service: >
        {% if state_attr('climate.proxon_template_heizung_schlafzimmer', 'hvac_mode') == 'auto' %}
        switch.turn_off
        {% elif state_attr('climate.proxon_template_heizung_schlafzimmer', 'hvac_mode') == 'heat' %}
        switch.turn_on
        {% else %}
        switch.turn_on
        {% endif %}
      entity_id: switch.heizelement_schlafzimmer

Soved! Code needs to be

set_hvac_mode:
    - service: >
        {% if is_state('climate.proxon_template_heizung_schlafzimmer', 'auto') %}
        switch.turn_off
        {% elif is_state('climate.proxon_template_heizung_schlafzimmer', 'heat') %}
        switch.turn_on
        {% else %}
        switch.turn_off
        {% endif %}
      entity_id: switch.heizelement_schlafzimmer