Help with Template trigger for heating turn on

Hi

I have a need to turn on heating after the temp has been below a set temp for an hour.

I have created a template to monitor if the temp sensor is below a given value in an input helper.

This displays true / false in dev tools so i think i have it correct.
I have created the following automation but it doesn’t work

alias: heat test
description: "Turn on Heating if current temp is below input_helper for over 10 mins"
trigger:
  - platform: template
    value_template: >-
      "{{ state_attr ('climate.bedroom_thermostat', 'current_temperature') |
      float < states('input_number.heat_number') | int}}" 
    for: "00:10:00"
condition:
  - condition: time
    after: "21:50:00"
    before: "23:00:00"
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
action:
  - type: turn_on
    device_id: 3d8765c23e6eb5dc8feb558261cbac04
    entity_id: switch.sonoff_10008bf75a_2
    domain: switch
mode: single

any help will be great thanks

Paul

Add brackets?

"{{ (state_attr ('climate.bedroom_thermostat', 'current_temperature') | float)
< (states('input_number.heat_number') | int) }}" 

Remove the outer double-quotes from the template. They’re not required because you are using a line-continuation character >- to indicate the template begins on the next line.

  - platform: template
    value_template: >-
      {{ state_attr ('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}

File editor didnt like that at all. I think the quotes are needed

They’re not needed. In fact, by placing them there, they will be included in the template’s result.

They’re only needed if the template is placed on the same line as the option.

  - platform: template
    value_template: "{{ state_attr('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}"

You also have the alternative of using a Numeric State Trigger.

  trigger:
    - platform: numeric_state
      entity_id: climate.bedroom_thermostat
      attribute: current_temperature
      below: input_number.heat_number
      for:
        minutes: 10

It triggers the moment the value of current_temperature decreases below the threshold value of input_number.heat_number and stays below it for at least 10 minutes. In other words, it triggers 10 minutes after current_temperature falls below the input_number’s value.

I see what your saying on develpoer tools this is the case

as in “true” or true" the docs also say that the for: requires true

but if I take them out i get an error in file editor

missed comma between flow collection entries (2883:87)

 2880 |  ... put_helper for over 10 mins
 2881 |  ... 
 2882 |  ... 
 2883 |  ... ostat', 'current_temperature') | float < states('input_numb ...
------------------------------------------^
 2884 |  ... 
 2885 |  ... 

either (yours or mine) results in true with dev tools

Which file editor are you using?

Good question… the one that comes with home assistant

That’s the File Editor Add-on.

The screenshot you posted shows you have the template on the same line as the value_template option but you do not have the template wrapped in double-quotes. That’s incorrect.

Correct

  - platform: template
    value_template: "{{ state_attr('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}"
  - platform: template
    value_template: >
      {{ state_attr('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}

Incorrect

  - platform: template
    value_template: {{ state_attr('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}
  - platform: template
    value_template: >
      "{{ state_attr('climate.bedroom_thermostat', 'current_temperature') | float(0) < states('input_number.heat_number') | int(0) }}"

So I’m here but still no joy

alias: heat test
description: Turn on Heating if currnt temp is below input_helper for over 10 mins
trigger:
  - platform: template
    value_template: >
      {{ state_attr('climate.bedroom_thermostat', 'current_temperature') |
      float(0) < states('input_number.heat_number') | int(0) }}
    for: "00:01:00"
condition:
  - condition: time
    after: "23:52:00"
    before: "23:59:00"
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
action:
  - type: turn_on
    device_id: 3d8765c23e6eb5dc8feb558261cbac04
    entity_id: switch.sonoff_10008bf75a_2
    domain: switch
mode: single

How are you testing the automation?

I’ve set the times to relevant i.e now and if the temp is below the helper for 1 min it should turn on the lights in my living room.

I am thinking I don’t need to restart HA

I am also hoping that this automation doesn’t require the state to change as the temp is already below the input helper

Then it won’t trigger if the temperature is already below the input_number’s value.

It will trigger only when the template changes from false to true. That means only at the moment the value of current_temperature decreases below the value of the input_number.

So the answer is i need to push the temp up first to meet the desired temp then monitor it? or is there a way to make it check at the beginning of the time frame?

The template must change from false to true in order to trigger. For it to report false, the value of current_temperature must be higher than the value of the input_number. Do whatever it takes to make that happen, perhaps by just lowering the value of the input_number. Then make the template report true. The easiest way would be to increase the value of the input_number.

At the moment when the template changes from reporting false to reporting true that’s when the Template Trigger will trigger the automation (be sure the time when you perform the test is within the time range you specified in the Time Condition). For testing purposes, you may want to simply remove, or disable, the Time Condition.

1 Like

yes i think it is straight in my head. I can get it to turn my lights on with a different style of automation.

So in my head i start three automations one that forces the heating on if below a temp then the one we have been working on and another to turn it off. this way one will force the temp change and the other two will manage it during the given time period.

Thank you so much I kind of had it and just needed steering to a different way of thinking.