Temperature Difference - turn on switch

HI, Im trying to confiure my pool solar heating system.

I need to turn on switch.poolpump when sensor.gw1100c_outdoor_temperature is 2 degrees C warmer than sensor.pool_water_temperature and then turn off again when the temperature drops.

Any thoughts?

Pump on

trigger:
  - platform: template
    value_template: "{{ states('sensor.gw1100c_outdoor_temperature')|float(0) + 2 > states('sensor.pool_water_temperature')|float(0) }}"
condition:
  - condition: template
    value_template: "{{ has_value('sensor.gw1100c_outdoor_temperature') and has_value('sensor.pool_water_temperature') }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.poolpump

Pump off

trigger:
  - platform: template
    value_template: "{{ states('sensor.gw1100c_outdoor_temperature')|float(0) + 2 < states('sensor.pool_water_temperature')|float(0) }}"
    for:
      minutes: 5
condition:
  - condition: template
    value_template: "{{ has_value('sensor.gw1100c_outdoor_temperature') and has_value('sensor.pool_water_temperature') }}"
action:
  - service: switch.turn_off
    target:
      entity_id: switch.poolpump

The for time prevents the pump cycling too often. Adjust it as you see fit. It could also be moved to the first automation so the pump turns off straight away but the temperature difference must be +2 degrees for a time before the pump turns on. There are pros and cons for both methods, use what you think is best.

Thanks Tom

Very quick response. I’ll apply and see how it goes. Next hot day is Wednesday. Cheers