Help with Automation: Compare two Temperatures

Hello,

I want to automate ventilation. I would like to compare two temperature values. If the temperature in the garden is lower than in the cellar, something should happen.
But this dont work for me…

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  initial_state: 'on'
  trigger:
    platform: template
    value_template: "{{ ( states.sensor.taupunkt_garten.state  ) < ( states.sensor.taupunkt_keller.state ) }}"
  action:
   - service: switch.turn_on
      entity_id:
        - switch.lufter_keller

You are comparing values inside a trigger:. The best way is to trigger the automation every minute, for example, and compare values inside a condition:

ok, i understand.

but how i compare this two temperatures?

1 Like

You are doing it right but on the wrong place.

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  initial_state: 'on'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 01
  condition:
    platform: template
    value_template: "{{ ( states.sensor.taupunkt_garten.state  ) < ( states.sensor.taupunkt_keller.state ) }}"
  action:
   - service: switch.turn_on
     entity_id: switch.lufter_keller

Try that and give some feedback.

Thank you very much, but this dont work for me.

Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->condition->0->platform. (See /home/pi/.homeassistant/configuration.yaml, line 75). Please check the docs at https://home-assistant.io/components/automation/
11:38 config.py (ERROR)

Any Idea?

This is my config…
- id: lueftersteuerung_keller_taupunktabhängig
alias: Lüftersteuerung Keller Taupunktabhängig
initial_state: ‘on’
trigger:
platform: time
minutes: ‘/1’
seconds: 00
condition:
platform: template
value_template: “{{ ( states.sensor.taupunkt_garten.state ) < ( states.sensor.taupunkt_keller.state ) }}”
action:
- service: switch.turn_on
entity_id: switch.lufter_keller

Maybe it’s better to create binary sensor like this:

binary_sensor:
  - platform: template
    sensors:
      temp_diff:
        friendly_name: Temperature difference
        value_template: "{{(states.sensor.taupunkt_garten.state) | float < (states.sensor.taupunkt_keller.state) | float }}"

And than in your automation add this:

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.temp.diff
      to: 'on'
  action:
   - service: switch.turn_on
     entity_id: switch.lufter_keller

This way you don’t have to wait for 1 minute to trigger automation.

1 Like

It´s not working because you forgot to put the “-” before "platform. It should be “- platform”.

When posting code use preformated text </>.

If you want the trigger to be quicker, reduce the time:

trigger:
    - platform: time
      seconds: '/5'

Hi there. I want to do a similar thing by comparing the temperature in my pools solar panel to the temp in the pool. I only want the binary sensor to be ‘on’ though if the solar panel is at least one degree above the pool temperature. How can I achieve that?

You can try this with binary sensor template:
{{((states.solar.sensor.state | float ) -
(states.pool.sensor.state | float)) > 1}}

Thank you! Is it possible to return the difference as a value?

Sure. Just use regular sensor. And lose > 1.

Thank you, that worked. Appreciate your help.

{{(states.sensor.solar_temperature.state | float ) - (states.sensor.pool_temperature.state | float)}}

3 Likes

change ‘platform’ to ‘condition’

Thanks. Didn’t realise I could have that template embedded into an automation without creating a binary sensor first.

Oh yeah, value templates are way better than the normal conditions in my opinion. Easier to read, less chances to screw up!

Hi Newbie here,
I’ve been following this thread with interest, but can I check the example above should platfrom not be “condition” as per the code below:

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  initial_state: 'on'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 01
  condition:
    - condition: template
      value_template: "{{ ( states.sensor.taupunkt_garten.state  ) < ( states.sensor.taupunkt_keller.state ) }}"
  action:
   - service: switch.turn_on
     entity_id: switch.lufter_keller

Hi.
I am totally new to home assistant and I am not programmer.
Can anybody help me to solve folowing.
I have two temperature sensors outside one on the west side and one on the east side so the temperature is different because the sun . I want to create template to compare this two sensors and the template value will be the lower temperature from both of them.

I suggest opening a new topic instead of resurrecting a 3 year old topic.