Modbus switch on/off value based on winter/summer mode

Hi all,
in my climate system i have a modbus switch that enable me to power on/off a thermostat.
The issue is that the on and off value are based on winter summer condition.
I tried with this code but it’s fault:

switch:
  - platform: modbus
    registers:
    - name: "Termostato_Cucina Switch"
      slave: 11
      register: 12
      command_on: >-
          {% if is_state('sensor.cucina_ei', '0') %}
            3
          {% else %}
            7
          {% endif %}      
      command_off: >-
          {% if is_state('sensor.cucina_ei', '0') %}
            1
          {% else %}
            5
          {% endif %}

hints?
thanks