Can I do this with a template?

Hi
I have several automations that control the heating, I have tado trv’s but the temp sensors are pretty poor so I use the temperature from xiaomi bluetooth temp sensors.
Anyway in the example below the heating comes on at 23c and goes off at 23.3c which keeps the room at a pretty constant temperature but this is not adjustable from the dashboard which is not wife friendly.
I have created a number helper as a temp selector, goes from 15 to 25 with 0.1 increments.
I’m guessing I can replace the IF conditions of 23 and 23.3 with a template that takes it’s value from the number helper and number helper +0.3
I have never used templates so help would be much appreciated

alias: 06.HK & BLE LRoom 6am-10pm
description: ""
trigger:
  - platform: time_pattern
    minutes: /3
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: state
    entity_id: group.people
    state: home
  - condition: state
    state: "on"
    entity_id: binary_sensor.heating06_22
  - condition: state
    entity_id: input_boolean.all_heating_automations_off
    state: "off"
action:
  - if:
      - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        below: 23
    then:
      - service: climate.set_temperature
        data:
          hvac_mode: heat
          temperature: 25
        target:
          entity_id:
            - climate.tado_smart_radiator_thermostat_va3659997952
            - climate.tado_smart_radiator_thermostat_va3233555200
  - if:
      - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        above: 23.3
    then:
      - service: climate.turn_off
        data: {}
        target:
          entity_id:
            - climate.tado_smart_radiator_thermostat_va3659997952
            - climate.tado_smart_radiator_thermostat_va3233555200
mode: single

I am by no means an expert but possibly something like this:

alias: 06.HK & BLE LRoom 6am-10pm
description: ""
trigger:
  - platform: time_pattern
    minutes: /3
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: state
    entity_id: group.people
    state: home
  - condition: state
    state: "on"
    entity_id: binary_sensor.heating06_22
  - condition: state
    entity_id: input_boolean.all_heating_automations_off
    state: "off"
action:
  - if:
      - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        below: "{{ states('input_number.your_input_number') }}"
    then:
      - service: climate.set_temperature
        data:
          hvac_mode: heat
          temperature: 25
        target:
          entity_id:
            - climate.tado_smart_radiator_thermostat_va3659997952
            - climate.tado_smart_radiator_thermostat_va3233555200
  - if:
      - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        above: {{ states('input_number.your_input_number') | float(0) + 0.3 }}
    then:
      - service: climate.turn_off
        data: {}
        target:
          entity_id:
            - climate.tado_smart_radiator_thermostat_va3659997952
            - climate.tado_smart_radiator_thermostat_va3233555200
mode: single

you can use templates in the numeric_state comparison (I’m pretty sure) but you should probably explicitly convert it to a number. I’m not sure if the system will auto convert the state string to number or if it will give an error because the numeric_state expects a number.

action:
  - if:
      - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        below: "{{ states('input_number.your_input_number') | float }}"
    then:
.
.
.

Thanks guys, I’ll try that

I don’t believe that’s possible. It’s not described in the documentation for Numeric State Condition..

However, above and below will accept a direct reference to an Input Number.

        below: input_number.your_input_number
1 Like

Oh, yeah. that’s what I was thinking of.

thanks for the correction.

I believe you may be right, I’ve been trying with the templates and keep getting errors.
However using the number helper directly how would I get the +0.3??
thanks

the funny thing is I tested it with a template in my config before I posted to (try to) make sure I was remembering right and my config checker never complained at all. with either the string state or explicitly converted to a number.

Which is why I thought it might have been an undocumented feature.

i tried it in the template editor and it showed the correct result but when I put it in my automation it threw up an error when I tried to save the automation.

i guess that’s the difference. I don’t use the automation UI editor.

The config checker used to be very useful but lately not so much anymore. :slightly_frowning_face:

You can’t. My point was simply that below doesn’t accept a template, only a constant or an entity with a numeric value (like a sensor or input_number).

For your application, I suggest you consider using a Template Condition.

Here’s an example employing a Template Condition in shorthand notation.

action:
  - if: "{{ states('sensor.lroom_t_and_h_custom_temperature') | float(0) < states('input_number.your_input_number') | float0) + 0.3 }}"
    then:

Algebra…

x > y + 0.3
x - (y + 0.3) > 0 or x - y > 0.3 … take your pick

    - condition: numeric_state
        entity_id: sensor.lroom_t_and_h_custom_temperature
        above: 0
        value_template: >
          {{ state.state | float(0) - (states('input_number.your_input_number') | float(0) + 0.3) }}