Help with climate data_template

Can you try to change this

entity_id: ‘{{ trigger.entity_id }}’

to this

entity_id: ‘{{ trigger.to_state.entity_id }}’

Sorry, still same error…

Do all of these service calls work without an error?

entity_id: climate.mi_acpartner_playroom_2
temperature: 26
hvac_mode: cool
entity_id: climate.mi_acpartner_playroom_2
temperature: 26
hvac_mode: heat
entity_id: climate.mi_acpartner_bedroom
temperature: 26
hvac_mode: cool
entity_id: climate.mi_acpartner_bedroom
temperature: 26
hvac_mode: heat

No errors… weird…

No errors means they work and no errors?

I recall a similar problem while helping someone else. I performed the test using an older version of Home Assistant that employs operation_mode instead of the newer hvac_mode.

When I used the Services page to call set_temperature, I could specify both the desired temperature and the operation_mode. However, when I tried to do the same thing with an automation, Config Check complained that operation_mode is an “extra key”.

That’s not the same error as you have but still highlights a discrepancy between using the Services page and an automation.

I have not yet repeated the test using a newer version of Home Assistant.

Works good with no errors.

Is this what you are experiencing?

  • Works good with no errors when you use the Services page.
  • Fails with errors when used in an automation.

Yes. If i force to set “hvac_mode” to heat (no if else,…), the automation works great.

Does the automation also work if you force it to “cool” without if …else…?
I ask this because I remeber having read something about not being able to set to “cool” if a temperature is provided.

Still works fine if i force it to ‘cool’ in automation.

I can pass the “Config Check” with no errors. @123

Have you tried manually testing auto mode? Does your thermostat show ‘auto’ under hvac_modes?

image

Did some test here.
If the thermostat in off state, I just can’t turn it on by climate.set_temperature service, tried heat/auto/cool, no feedback at all and no errors in log.
Then I called climate.turn_on to turn on it first, the climate.set_temperature service works good.

That makes sense. Glad you figured it out! Now that I think about it I think I had the same problem when I did my climate automations a while back. You should probably mark your comment as the solution so anyone else coming across the thread sees it right away.

But my issue is still there.
The automation triggered when I turn on thermostat manually, but still get error when run the hvac_mode change.

Log shows " Invalid data for call_service at pos 1: value is not allowed for dictionary value @ data[‘hvac_mode’]"

Oops. Sorry I misunderstood. Have you tried separating out the hvac mode and temperature calls?

    - service: climate.set_hvac_mode
      data_template:
        entity_id: {{ trigger.entity_id }}
        hvac_mode: >
          {% if ((now().month >= 11) or (now().month <= 3)) and (trigger.to_state.state != 'heat') %}
             heat
          {% elif ((now().month >= 6) and (now().month <= 10)) and (trigger.to_state.state != 'cool') %}
             cool
          {% else %}
             auto
          {% endif %}

    - service: climate.set_temperature
      data_template:
        entity_id: {{ trigger.entity_id }}
        temperature: 24

I’d be interested to hear the answer. In the linked post I wrote:

Strictly speaking, the error message is correct. A completely different service is used to set the operation mode ( climate.set_operation_mode ) so if this option appears with climate.set_temperature it’s superfluous (i.e. ‘extra key’) and reported to be an error.

To reiterate, the error I received is not the same one as in this topic but there are similarities in what both topics are attempting (use the set_temperature service to set temperature and hvac_mode). It seems it works fine here unless a template is used for hvac_mode. That’s very strange.

I tried only set “climate.set_hvac_mode” but still same error… It looks like hvac_mode hates “if else” in my scenario…:joy:

It suggests there’s a problem with the template.

Try this template. It is equivalent to just setting hvac_mode to heat (but does it with a template).

  action:
  - service: climate.set_temperature
    data_template:
      entity_id: '{{ trigger.entity_id }}'
      temperature: 26
      hvac_mode: "{{ 'heat' if true else 'auto' }}"

If it fails to work than there’s something unusual going on.

Please post the configuration of your climate entity.