Automation help - compare two temperature values to trigger Automation

I have put my solar heating system temperature monitoring into HA and I have created an Automation that triggers if the temperature in the pool is greater than or equal to the water coming in from the roof for 30 mins. (no point in pumping in same temp or cooler water)

The only thing is this will be always triggering as the temperature values change, will that cause problems with resources of HA if this is always running? Is there a better way to handle this sort of automation?

alias: Pool Heater - Temperature Comparison
description: >-
  Checks temps of pool and solar return and turns off if Pool is over return
  temperature, after 1 hour will rerun heater.
trigger:
  - platform: state
    entity_id:
      - sensor.shelly_pool_temperature
      - sensor.shelly_roof_return_temperature
condition:
  - condition: time
    before: "18:00:00"
    after: "10:00:00"
  - condition: template
    value_template: >-
      {{ states('sensor.shelly_pool_temperature') | float >
      states('sensor.shelly_roof_return_temperature') | float }}
action:
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - if:
      - condition: template
        value_template: >-
          {{ states('sensor.shelly_pool_temperature') | float >
          states('sensor.shelly_roof_return_temperature') | float }}
    then:
      - service: switch.turn_off
        data: {}
        target:
          entity_id: switch.spareplug
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - if:
      - condition: time
        before: "18:00:00"
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
        after: "00:00:00"
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.spareplug
mode: single

Have you considered using a Template Trigger that at incorporates everything you currently have in your automation’s condition?

No, how would I do that?

Trigger only when the time is within the desired range and pool temperature exceeds return temperature (for at least 15 minutes).

trigger:
  - platform: template
    value_template: >
      {{ (states('sensor.shelly_pool_temperature') | float(0) >
        states('sensor.shelly_roof_return_temperature') | float(0)) and
        10 <= now().hour < 18 }}
    for:
      minutes: 15

Reference: Template Trigger

1 Like

Brillant, that makes sense! Ill give it a try!