Set Climate Temperature from Template Sensor

I’m having some trouble with a script - I’m hoping the answer is obvious and all my Googling is just missing it somehow.

I’ve set up automations to change the climate set temperature when Hassio detects I’m at home or away. I’d like to use different temperatures depending on the outside temperature (ie: if it’s summer or winter will change if I’m heating with a furnace or cooling with AC).

Here’s the code I’ve tried, but it doesn’t work. I’ve set up template sensors to have the correct temperature set points for various times of the day/week, so I can reference them in the script, but the reference doesn’t seem to work. Any ideas?

Example Template Sensor:

  - platform: template
    sensors:
      temperature_weekend:
        friendly_name: "Weekend Temperature Setpoint"
        value_template: >-
          {% if is_state('binary_sensor.summer', 'off') %}
            21
          {% else %}
            22
          {% endif %}

Example Script:

    - service: climate.set_temperature
      data:
        entity_id: climate.thermostat
        temperature: "{% states('sensor.temperature_weekend') %}"

The syntax in your script isn’t right, all you need to do is:

- service: climate.set_temperature
  data:
    entity_id: climate.thermostat
    temperature: "{{ states.sensor.temperature_weekend.state }}"

That should fix your problem.

Thanks! That code gives me the below error message though - any ideas?

Invalid service data for climate.set_temperature: expected float for dictionary value @ data['temperature']. Got '{{ states.sensor.temperature_weekend.state }}'

Use data_template: instead of data:

1 Like

That got it, thanks!!

What’s the difference between data: and data_template?

data indicates that you are providing the values directly to be used in the action. data_template indicates that there is template that needs to be evaluated to obtain the values to be used in the action.

Ahh yes sorry, didn’t notice the data bit. data_template is the correct one.

Just for my understanding, the full code is:

- service: climate.set_temperature
  data_template:
    entity_id: climate.thermostat
    temperature: "{{ states.sensor.temperature_weekend.state }}"
1 Like