Setting thermostat_target_temperature with template

I have an Ecobee thermostat, and for the most part integrating it has been a breeze, but I recently switched it from “cool” to “heat_cool”, ie heating and cooling to keep things in a range, and it broke one of my sensors for displaying the current target temperature. I figured a template for this wouldn’t be too bad, since I know the possible state_attr values, but I’m struggling. The template tool is showing the result is a string, not an integer, and it’s just coming back blank.

I’m sure there’s probably a better way to go about this, but I’m still learning, so this is what I’ve been able to come up with so far. Can someone tell me what I’m doing wrong?

sensor:
  - platform: template
    sensors:
      thermostat_target_temperature:
        friendly_name: "Thermostat Target Temperature"
        unit_of_measurement: "F"
        value_template: >-
          {% if state_attr('climate.thermostat', 'hvac_modes' == 'heat' ) %}
            {{ state_attr('climate.thermostat', 'temperature') | float }}
          {% elif state_attr('climate.thermostat', 'hvac_modes' == "cool" ) %}
            {{ state_attr('climate.thermostat', 'temperature') | float }}
          {% elif state_attr('climate.thermostat', 'hvac_modes' == "heat_cool" ) %}
            {{ state_attr('climate.thermostat', 'target_temp_high') | float }}
          {% else %} 0
          {% endif %}
        device_class: temperature