Binary sensor template to compare two temperatures

Hi all,

Sorry, I know that in principle exactly the same question has been asked before (many times I guess) and I tried to use the existing answers but still my solution does not work.

I have got a thermometer (called: ‘sensor.office_temperature’) and a TRV (called: ‘climate.hahm_000a1d89a65220_1’).

Within a binary sensor template I am trying to compare the current temperature with the set temperature on the TRV. If the current temperature is lower than the set, I want to use this later on as a trigger to turn on the central heating. I am planning to do this for 5 rooms, combine those binary sensors in to a group so that whenever the group changes (from true to false, or off to on) the central heating gets turned on.

However, with the template code below it does not seem to work.

Both value are picked up and displayed currently but the value of the template never changes when I set the TRV temperature lower or higher than the current temperature.

I am sure it is a very small and stupid mistake but have not managed to figure it out.

binary_sensor:
  - platform: template
{% set current = state_attr('climate.hahm_000a1d89a65220_1', 'temperature')%}
{{ current}}
{{ states ('sensor.office_temperature')}}
      sensors:
      office_temp_too_low:
        
        friendly_name: Office Temperature too Low
        value_template: "{{ states('sensor.office_temperature') | float < states('climate.hahm_000a1d89a65220_1.temperature') | float }}"



This is the output it get:

binary_sensor:

  • platform: template

17.0
18.9
sensors:
office_temp_too_low:

  friendly_name: Office Temperature too Low
   value_template: "False"

Thanks for your help.
Merc

binary_sensor:
  - platform: template
      sensors:
        office_temp_too_low:
          friendly_name: Office Temperature too Low
          value_template: "{{ states('sensor.office_temperature') | float(0) < state_attr('climate.hahm_000a1d89a65220_1', 'temperature') }}"

Or in modern style:

template:
  - binary_sensor:
      - name: Office Temperature too Low
        state: "{{ states('sensor.office_temperature') | float(0) < state_attr('climate.hahm_000a1d89a65220_1', 'temperature') }}"

Hi @123 ,
thank you very much for your help.
So I forgot the ‘_attr’ part.
I had tried it with ‘climate.hahm_000a1d89a65220_1.temperature’ but that did not work.

Definitely good to know for the future.

It works now, one step closer to the heating automation.

Cheers,
Merc

1 Like