[Help] How to simplify my code. output multi key in template

    aircon_auto:
      friendly_name: Aircon
      icon_template: mdi:fan
      value_template: "{{ states('climate.hitachi_ac') != 'off' }}"
      turn_on:
        - service: climate.set_temperature
          entity_id: climate.hitachi_ac
          data_template:
            temperature: >
              {% if states('sensor.pudong_temperature') | float < 15 %}
                30
              {% elif states('sensor.pudong_temperature') | float > 25 %}
                27
              {% else %}
                25
              {% endif %}
            hvac_mode: >
              {% if states('sensor.pudong_temperature') | float < 15 %}
                heat
              {% elif states('sensor.pudong_temperature') | float > 25 %}
                cool
              {% else %}
                fan_only
              {% endif %}
      turn_off:
        - service: climate.turn_off
          entity_id: climate.hitachi_ac

Heating while cold and cooling while warm, but 2 attr need to be set.

The code looks ugly, I’ve tried output json in data, but not work.
If split the code to script, that waste more code and more thing in “all script”, not so good.
( BTW, is that some way to hide script or switch in “all_*”? )

So, is that any way I missed? Please help.