Pls help w/ service template for climate (heater)

Hi everybody,

below is my automation for toggling an SPZB0001 zigbee thermostat depending on the window state (determined by a Xiaomi Aqara Door Sensor). Unfortunately, it does not work. I am not quote sure what I am doing wrong, so would somebody please guide me in the right direction?

I have read the docs, that why I don’t understand how this could be wrong… It should set the hvac_mode depending on the window state…?

Thank you in advance for your ideas :slight_smile:


automation:
  - id: "heizung_az_aus"
    alias: "[Heizung] AZ Aus"
    trigger:
      - platform: state
        entity_id: binary_sensor.arbeitszimmer_fenster_contact
    action:
      - service: climate.set_hvac_mode
        entity_id: climate.arbeitszimmer_heizung_climate
        service_template:
          hvac_mode: >
            {% if states("binary_sensor.arbeitszimmer_fenster_contact") == "on" %}
              "off"
            {% elif states("binary_sensor.arbeitszimmer_fenster_contact") == "off" %}
              "on"
            {% endif %}

I have also tried this

automation:
  - id: "heizung_az_aus"
    alias: "[Heizung] AZ Aus"
    trigger:
      - platform: state
        entity_id: binary_sensor.arbeitszimmer_fenster_contact
    action:
      - service: climate.set_hvac_mode
        data_template:
          entity_id: climate.arbeitszimmer_heizung_climate
          hvac_mode: >
            {% if states("binary_sensor.arbeitszimmer_fenster_contact") == "on" %}
              "off"
            {% elif states("binary_sensor.arbeitszimmer_fenster_contact") == "off" %}
              "on"
            {% endif %}


Try this:

    action:
      - service: climate.set_hvac_mode
        data_template:
          entity_id: climate.arbeitszimmer_heizung_climate
          hvac_mode: >
            {% if is_state('binary_sensor.arbeitszimmer_fenster_contact', 'off')  %}
              on
            {% else %}
              off
            {% endif %}

This has the advantage of catching the ‘unavailable’ state as well (it will turn the mode off).

Just for your information, the service_template is to determine the service that should be used like “switch.turn_on” or “switch.turn_off”. You need the data_template as in your second example.

Thank you! I have tried the code @tom_l pasted… when I opened the window, the radiator turned OFF (actually visible on the radiator as well as on the Home Assistant UI); however, when I shut the window (and when I opened it again), I only got

2019-11-22 15:21:34 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.heizung_az_aus. Invalid data for call_service at pos 1: value is not allowed for dictionary value @ data['hvac_mode']

I don’t use the climate integration but just had a bit of a read of the docs. hvac_mode valid states appear to be ‘heat’ and ‘cool’ not 'on and ‘off’.

I think you want the climate.turn_on , climate.turn_off services. So back to your service template:

    action:
      - service_template: >
          {% if is_state('binary_sensor.arbeitszimmer_fenster_contact', 'off') %}
            climate.turn_on
          {% else %}
            climate.turn_off
          {% endif %}
        entity_id: climate.arbeitszimmer_heizung_climate

However, as I said, I don’t use this integration so could be wrong.

1 Like

Thank you! That did it.

At first I only read the first part about the states, so I changed “on” to “heat”; this already worked (as far as I can tell). Is there a benefit to using climate.turn_on and climate.turn_off instead of changing the hvac mode?

:man_shrugging: I really don’t know. I don’t use it. But from what I can gather hvac_mode is now just for changing the cooling or heating mode not switching on or off. The integration has had quite a few breaking changes recently to make it work better with voice assistants, worth a read: https://developers.home-assistant.io/blog/2019/07/03/climate-cleanup.html

I had huge issues with this so I changed my method and NEVER turn the heating off, just set it to some ridiculously low value. If it hits that, the heating should be on to stop the pipes freezing.
If I’ve lost the roof or something, I’m not beyond just turning the boiler off.

You guys could also try shedy …it’s a really good climate control system for appdaemon