Value Template from HA Website

I’m trying to get the boiler relay to fire when the set point is higher than the current temp. I downloaded this from the HA website but it isnt working. Any ideas?

alias: TRV Boiler Control Test
description: ""
trigger:
  - platform: numeric_state
    entity_id: climate.trv_bathroom_2
    value_template: >-
      "{{ state.attributes.current_temperature - state.attributes.temperature_set_point }}"
    above: 3
condition: []
action:
  - type: turn_on
    device_id: ceb20e35b91d7ea09b6ceebdb438dd3c
    entity_id: dd38ac3e17233cae5451c7d9b1ad83ec
    domain: switch
mode: single

temperature_set_point isn’t a standard attribute for climate entities… the normal attribute is just temperature. Double check your entity in the States tool to make sure you’re using the correct attribute name. Also, you cannot use both a multi-line indicator like >- and quotes "… get rid of the quotes around the template.

Thanks. You are correct… the set_point was incorrect. I check in states. I’ve fixed that but it still isnt working.

It wont let me get rid of the quotes. I just get this message - Message malformed: template value should be a string for dictionary value @ data[‘value_template’]

Any other ideas?

Cheers

This is how it looks after I check states

alias: TRV Boiler Control Test
description: ""
trigger:
  - platform: numeric_state
    entity_id: climate.bathroom
    value_template: "{{ state.attributes.current_temperature - state.attributes.temperature }}"
    above: 3
condition: []
action:
  - type: turn_on
    device_id: ceb20e35b91d7ea09b6ceebdb438dd3c
    entity_id: dd38ac3e17233cae5451c7d9b1ad83ec
    domain: switch
mode: single

You probably really want a template trigger, as mentioned on Discord:

alias: TRV Boiler Control Test
description: ""
trigger:
  - platform: template
    value_template: "{{ state_attr('climate.bathroom','current_temperature') - state_attr('climate.bathroom','temperature') > 3 }}"
condition: []
action:
  - type: turn_on
    device_id: ceb20e35b91d7ea09b6ceebdb438dd3c
    entity_id: dd38ac3e17233cae5451c7d9b1ad83ec
    domain: switch
mode: single

Thanks Tinkerer, I’m really struggling to get my head around the value_template. I’ve put your code into an automation and it still doesnt trigger. I’m chaning the ‘temperature’ setpoint all over the place and it doesnt trigger. I’ve tried ‘temperature’ and ‘temperature_set_point’ (even though I know its ‘temperature’

Any ideas?

I’m eternally greatful for any help as this is really annoying me

I agree with @Tinkerer, just use a Template trigger.

The Numeric state trigger has somewhat complicated logic. For example, it will only fire on changes to the state of the entity listed under entity_id, not the other entity in the template. In analogous Template trigger changes to either entity can cause the trigger to fire.

@Didgeridrew thanks. The ‘current_temperature’ is refreshing every few minutes so I cant see why it isnt triggering.

All I need to do is fire a boiler relay if the the ‘current_temperature’ is lower than ‘temperature’ (set point).

Can you think of any other ways to make it happen?

You need to show us what trigger you are actually using… between Discord and here, there have been a few options floated.

The trigger you presented is for when the current_temperature is 3 degrees, or more, higher than the set point.

@Didgeridrew OK thanks for explaining that… I found the automation on the HA website when I was trying to figure it out. It isnt going to work if the current temp is 3 degrees or more higher than the setpoint. I’ve changed it to 1 degree lower than the setpoint and it still isnt working.

All I want to do is fire the boiler relay when the set point is higher than the actual temperature? 1 degree higher will be fine. Then turn the boiler relay off when the actual temperature is 1 degree over the setpoint?

As always, any help is greatly appreciated. I’m new to this and managed to crack everything by myself so far. Its just this one which is destroying me.

Cheers guys I got it working with your help.

To fire boiler -

  - platform: template
    value_template: >-
      {{ state_attr('climate.bathroom','current_temperature') -
      state_attr('climate.bathroom','temperature') < 0.5 }}

To turn boiler off -

  - platform: template
    value_template: >-
      {{ state_attr('climate.bathroom','current_temperature') -
      state_attr('climate.bathroom','temperature') > 0.5 }}

Hi Guys, I’m still trying to get my head around triggering a value_template. I’m trying one to boost hot water as follows -

trigger:
  - platform: template
      {{ state('sensor.hot_water_control_air_temperature') < 50 }}

The entity is ‘sensor.hot_water_control_air_temperautre’ and the state is the measured temperature. Basically, if the hot water is below 50 then the hot water relay fires

Any ideas?

As always, thanks for any advice.

Edit - this is the error I get at the moment. It doesnt seem to like the sensor

Message malformed: Invalid platform 'template {{ state(‘sensor’ specified

Three issues.

First, you have left out the value_template: key form the sensor configuration. This is the source of the error.

Second, your template is not surrounded in quotes or demarcated by a multiline quote indicator.

Third, you have not converted your state to an actual number. States are always strings. Attributes can be other data types. Any time you want to perform mathematical operations or numeric comparisons on a state, you must first convert it using either int() or float().

trigger:
  - platform: template
    value_template:  "{{ state('sensor.hot_water_control_air_temperature')|float(0) < 50 }}"
  1. Triggers don’t fire when they’re already true
  2. Triggers have to go from false to true to fire

Isn’t even valid

For the two triggers in your post the triggers have to go from false to true before they fire.

Thanks. I get the theory, I just dont understand the actual coding of value templates and I cant find anything online to learn from except you very helpful people… what does ‘float’ do? I’ve tried the following and it still doesnt trigger -

trigger:
  - platform: template
    value_template:  "{{ state('sensor.hot_water_control_air_temperature')|float(0) < 50 }}"

Home Assistant Templating : This is the the most comprehensive and up-to-date source for HA-specific functions.

Jinja Docs: These docs are not geared toward new/casual users, but they contain a lot of important information.

Jinja for Ninjas: This is a well organized tutorial and group of examples. It’s been a while since this was updated, so there are better/easier ways to do some of the things shown, but it’s still a good resource.

There are many helpful videos covering templates available on YouTube.
SlackerLabs
Everything Smart Home
Smart Home Makers

The float filter/function converts strings or integers into floating point numbers (aka “floats”). Data Type Basics

Define “tried”… what is your testing process? What is the state of the sensor before and during testing?

thanks @Didgeridrew I’ll look those up…

Basically, I’ve got a toggle on overview which allows the automation to run. When toggling it doesnt trigger. I’ve got an automation which refreshes the hot water sensor value every 5 minutes so I wait until the value is refreshed but still doesnt trigger. If I click ‘run’ in automations then it does fire the relays etc. It just getting it to trigger autmatically which I cant get working

Turning an automation on (aka enabling the automation) is not the same as triggering.

It doesn’t matter how often you “refresh” the sensor, a Template trigger will only fire when the evaluation of the template changes from “false” to “true”. You can temporarily manipulate the value of states or attributes in the Developer Tools > States tool by selecting the desired entity, editing the state in the “Set State” section then clicking the “Set State” button. Remember, if the current state is already less than 50, you need to set the value above fifty, then set it back below fifty (or wait until it updates normally).

Using the “Run” button or calling the automation.trigger only runs the actions, the triggers and conditions are skipped.

Thanks @Didgeridrew, the developer tool is indeed very helpful. My code is as follows -

alias: Hot Water Boost
description: ""
trigger:
  - platform: template
    value_template: "{{ states ('sensor.hot_water_control_air_temperature') | float(0) < 58 }}"
condition: []
action:
  - type: turn_on
    device_id: 885ff857910a22568ba3adb75828ffa1
    entity_id: 626a094c850ae449d70a92c13a526ebd
    domain: switch
mode: single

The developer tool says this -

alias: Hot Water Boost
description: ""
trigger:
  - platform: template
    value_template: "True"
condition: []
action:
  - type: turn_on
    device_id: 885ff857910a22568ba3adb75828ffa1
    entity_id: 626a094c850ae449d70a92c13a526ebd
    domain: switch
mode: single

However its not triggering :exploding_head:

I really am stumped? Any further advice?

Thanks for your help to date