Switch template want to change climate.hvac_mode

I have this switch to change the mode of a virtual thermostat (dual thermostat) using a inpput_boolean… but it does not work:

switch:
  - platform: template
    switches:
      hvac_mode_auto:
        friendly_name: "hvac_mode_auto"
        value_template: "{{is_state('input_boolean.frio_calor', 'on')}}"
        turn_on:
          service: climate.set_hvac_mode
          target:
            entity_id: climate.study
          data:
            hvac_mode: heat
        turn_off:
          service: climate.set_hvac_mode
          target:
            entity_id: climate.study
          data:
            hvac_mode: cool

when y change switch to on, status of switch change to on, butn hvac_mode not change…
what am I doing wrong?

how are you turning this switch on? Are you going to switch.hvac_mode_auto and turning that on/off? or are going to input_biolean.frio_calor and flipping that?

Im guessing you are flipping the frio_calor?

if that is right, you shouldn’t be doing this… You should go to automations and create an automation that triggers off the input Boolean and sets the mode depending on the state of the input Boolean.

I agree with armedad but you have two options here:
Option 1- Do what armeded suggests & remove the template switch entirely, and instead create an automation

or, what I feel is the better option:

Option 2- Delete your input_boolean.frio_calor helper, and change your value_template to this:

value_template: "{{ is_state('climate.study', 'heat') }}"

And then you can toggle the switch.hvac_mode_auto instead of toggling your (now deleted) input_boolean helper

1 Like

there is also the question of why do this at all. if it is to expose an easy push button control for the UI, that can be done by directly adding the climate entity and having the tap action set the mode. The benefit of doing this is that you can also display other info more easily, like the target temp, maybe fan status etc.

Yes good point. This is the better question.

I do it this way because it is a site that has 8 other thermostats, and I thought with an input_boolean to change them all at once.
That input_boolean also controls which pump should be used depending on whether heat or cool is demanded.

I was thinking of using that input to change the whole system with a single button.
Currently we do it with automations, but I tried to remove automations and use templates to make this task easier.

ah, if you are looking for single switch that sets a bunch and potentially have differing behaviors on them even then input_boolean is a reasonable way to go.

move your code to an automation.

1 Like