Automation with template in variables with climate domain headache

I have an automation to switch my heating {{heater}} (ZWave TRV in the climate domain) on and off and replace it with an electric heater {{heater_electric}}. The automation is quite complicated and split among multiple automations, but the relevant part is

trigger through bool on/off switch → variables through templates → climate.trv off/on service call, plug off/on service call

This works fine on the off, but nearly the same code fails to turn the TRV back on (the eletric plug part always works fine). I am at a complete loss as to why, but I am guessing it’s some typo, lack of quotes etc.

Here is the working OFF automation part:

variables:
    heater: >
      {% if is_state('input_boolean.heating_season','on') %} 
      {% set heater = 'climate.trv_bath' %} 
      {% else %} 
      {% set heater = 'switch.plug_bath_grzejnik'%}
      {% endif -%} 
      {{heater}}
    heater_electric: switch.plug_bath_grzejnik
    in_temp: "{{ (states('sensor.xiaomi_bath_temperature') | float) }}"
    temp_boost: "{{4 | float}}"
  trigger:
    - platform: state
      entity_id: input_boolean.bath_cozify_status
      to: "on"
action:
    choose:
...
        sequence:
...
          - choose:
              conditions:
                - alias: if electric override is on, turn TRV off and turn on electric
                  condition: state
                  entity_id: input_boolean.heating_electric_radiator_override
                  state: "on"
              sequence:
                - service: climate.set_hvac_mode
                  target:
                    entity_id: "{{heater}}"
                  data:
                    hvac_mode: "off"
                - service: switch.turn_on
                  target:
                    entity_id: "{{heater_electric}}".

and here is the reverse ON automation which doesn’t fully work. I paste a bit more of it, but there are some other branches which get executed when my heating is off completely and are irrelevant here.

- alias: "Bath: Heat off on cozify to off"
  id: auto_bath_cozify_on_status_off
  description: Turn off bath heat when cozify_status flipped to off
  variables:
    heater: >
      {% if is_state('input_boolean.heating_season','on') %} 
      {% set heater = 'climate.trv_bath' %} 
      {% else %} 
      {% set heater = 'switch.plug_bath_grzejnik'%}
      {% endif -%} 
      {{ heater }}
    heater_electric: "switch.plug_bath_grzejnik"
    in_temp: "{{ (states('sensor.xiaomi_bath_temperature') | float) }}"
    temp_boost: "{{ 4 | float }}"
  trigger:
    - platform: state
      entity_id: input_boolean.bath_cozify_status
      to: "off"
  action:
    - choose:
        - alias: Switch electric off and turn TRV back if override on
          conditions:
            - condition: state
              entity_id: input_boolean.heating_season
              state: "on"
            - condition: state
              entity_id: input_boolean.heating_electric_radiator_override
              state: "on"
          sequence:
            - service: switch.turn_off
              target:
                entity_id: "{{heater_electric}}"
            - service: climate.set_hvac_mode
              target:
                entity_id: "{{heater}}"
              data:
                hvac_mode: "heat"

The last call here gets executed, but doesn’t do anything. In the automation debugger:

Executed: 27 October 2021, 09:02:15
Result:
params:
  domain: climate
  service: set_hvac_mode
  service_data:
    hvac_mode: heat
    entity_id:
      - climate.trv_bath
  target:
    entity_id:
      - climate.trv_bath
running_script: false
limit: 10

If I do the call manually in the service developer tool, it works fine. Maybe it’s a question of how the variable {{heater}} is formatted, but it shouldn’t work in the OFF automation either in this case.

Just for completeness, here is the climate.trv_bath state:

hvac_modes:
  - 'off'
  - heat
min_temp: 7
max_temp: 35
preset_modes:
  - none
  - Energy heat
  - Full power
current_temperature: 25
temperature: null
preset_mode: none
friendly_name: TRV Shower
supported_features: 17