Solar heating trigger

Hi,

In my DIY solar heating system for our swimming pool i have two temp sensors. One at the top end of the heating pipes and the other in de pool.

The idea is that when the temp at the top of the pipes is higher then the temp in de pool, the pump that pumps the water threw the pipes, has to turn on.
In that case i maximize the temp i every situation.

When it cools down and/or the temp is higher in de pool the pump automatically turns off.

Would it be possible to set an automation for this?

I appreciate your help.

Kind regards,
Raymon

trigger:
  - platform: template
    value_template: "{{ states('sensor.heating_pipe_temperature')|float(0) > states('sensor.pool_temperature')|float(0) }}"
    for:
      minutes: 5 # to prevent fast flip-flopping of pump switch
    id: 'on'
  - platform: template
    value_template: "{{ states('sensor.heating_pipe_temperature')|float(0) < states('sensor.pool_temperature')|float(0) }}"
    id: 'off'
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.pool_heating_pump