Using templates to set temperature for Thermostat

Hi,

I am trying to automate the thermostats in my house and would like to easily set temperature schedule for a week.

I found a very good custom component called Programmable_thermostat for this use, and it works like a charm for my electrical heaters which are connected to a power plug and room sensor.

For these I create a Programmable thermostat in configuration.yaml, and use the file_restore component as input with a set temperature every hour throughout the week.

However I also have a couple of HeatIt floor thermostats and a Mitsubishi Heat pump. These are already set up as climate entities, so I not possible to use the Programmable Thermostat component. Instead I wanted to use the file_restore as input to set temperature throughout the day with an automation that is triggered every 5 minutes. The file_restore component has an array with temperatures, and state gives the one for the current hour. However I am not able to get this value and use it for automation. I am not so experience with templates and home assistant programming, so may be an obvious fix…

My automation code:

automation:
  - alias: Sette temperatur på gulvvarme kjøkken
    trigger:
    - platform: time_pattern
      minutes: "/5"
    action:
    - service: climate.set_temperature
      entity_id: climate.kjokken_gulvvarme_heating
      data_template:
        temperature: {{ states.sensor.set_temperature_gang_1_etg.state }}

I have tried the template in the template editor, and it gives me the temperature, but does not work to set temperature. I have also tried to add “| float” to fix type.

I get this error when trying to start HA with the script:
ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] invalid key: “OrderedDict([(‘states.sensor.set_temperature_gang_1_etg.state’, None)])”
in “/config/automations.yaml”, line 130, column 0

Any suggestions to get a “programmable thermostat” using HeatIt floor heating?

You have to quote single line templates:

      data_template:
        temperature: "{{ states.sensor.set_temperature_gang_1_etg.state }}"

Also you would be better off with this format that does not error if the state is unknown:

      data_template:
        temperature: "{{ states('sensor.set_temperature_gang_1_etg') }}"
2 Likes

Also take a look at Schedy, might be of use for you:

My heating is always on, but if the doors are open or the house unoccupied the target is pretty low. (ie it’s the same as ‘off’)
I use a template to set an input number value and when that changes it updates the climate control.
This way I can manually overide at any time.
I also have an input binary to act as a ‘boost button’ - sets value to evening setting for 1 hour (unless another change happens)

## resets temperature following any pattern change
  sc_heat_reset_value:
    alias: Heating Reset Value
    sequence:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.in_heat_temp_control_val
        value: >
          {% if false and not is_state('binary_sensor.bs_door_open', 'on') %}
            {{ '6' | float }}
          {% elif not is_state('binary_sensor.bs_occupied', 'on') %}
            {{ states('input_number.in_heat_temp_away_val') | float }}
          {% elif  is_state('binary_sensor.bs_heat_night_active', 'on') %}
            {{ states('input_number.in_heat_temp_night_val') | float }}
          {% elif is_state('binary_sensor.bs_heat_day_active', 'on') %}
            {{ states('input_number.in_heat_temp_day_val') | float }}
          {% else %}
            {{ states('input_number.in_heat_temp_evening_val') | float }}
          {% endif %}
#### end of template

@tom_l , you note my template paranoia here to ensure “nothing” gets mistakely put into my template.
Just coz I’m paranoid, doesn’t mean that they aren’t out to get me ! :crazy_face:

My door sensors aren’t all set up yet so the above just has a placeholder
Edit: just to be clear the above is a script so as to use the code from mutiple triggers

1 Like

Why?

  {% if false and not is_state('binary_sensor.bs_door_open', 'on') %}
            {{ '6' | float }}

Why not?:

  {% if not is_state('binary_sensor.bs_door_open', 'on') %}
            6

Your template can evaluate to

false and true = false
false and false = false

In both cases it will never return true and is pointless to include.

Also what is the point of converting a string to a number when you can just supply a number?

Ha ha ha, read the second to last line of my post :rofl:

I’m assigning it to an input_number, I’ll try assigning a string (containing a number) I guess I assumed I couldn’t.

Thanks for reply! Unfortunately still does not work… Seems I need to better understand the template function. E.g. what is different with value_template and data_template etc.

But the option with Schedy should work instead!

Thanks! That sounds like a good alternative. Will try that, and liked that window open off is already implemented!

Ideally it would be possible to implement a user interface to set weekly schedules for a thermostat… I.e. similar to commercial equipment such as EQ3 Max! or similar. But have not found anything for HA yet…