Differential temperature

hi, I have two temperature sensors, I need to switch a pump (relay) on when sensor 1 is 10 degrees above sensor 2 and then switch off when the difference comes down to only 5 degrees above.
can anyone explain how I can do this?
Im a novice at this so plain and simple please.
thanks

There are a number of ways to approach this, but all of them are going to include Templating.

You could use Numeric state triggers, but I would recommend using Template triggers.

so ive got the trigger working but the switch doesn’t work “on” or “off” what’s wrong with this code? it shows no errorsalias: Update TankSwitch
description: “”
trigger:

  • platform: state
    entity_id:
    • sensor.sonoff_1001e23ad2_temperature
    • sensor.sonoff_100114a710_temperature
      condition:
      action:
  • if:
    • condition: template
      value_template: >-
      (states(‘sensor.sonoff_1001e23ad2_temperature’) | float -
      states(‘sensor.sonoff_100114a710_temperature’) | float) >= 10)
      then:
    • type: turn_on
      device_id: 69041622535e34621d9284d28b74abe7
      entity_id: 20d22e4f2a5885d8f85412306160eb93
      domain: switch
    • service: logger.log
      data:
      message: Switch Turned On!
  • if:
    • condition: template
      value_template: >-
      (states(‘sensor.sonoff_1001e23ad2_temperature’) | float -
      states(‘sensor.sonoff_100114a710_temperature’) | float) <= 5)
      then:
    • type: turn_off
      device_id: 69041622535e34621d9284d28b74abe7
      entity_id: 20d22e4f2a5885d8f85412306160eb93
      domain: switch
    • service: logger.log
      data:
      message: Switch Turned Off!
      mode: single

Please follow Community guideline #11 and format your cobe blocks properly… the forum software does weird things and it can be difficult to determine the source of the error.

With that in mind, it looks like your templates are missing their curly braces {{ }}.

I would probably just use template triggers instead of triggering on every state change:

alias: Update TankSwitch
description: ""
trigger:
  - id: 'on'
    platform: template
    value_template: |
      {{ states('sensor.sonoff_1001e23ad2_temperature') | float -
      states('sensor.sonoff_100114a710_temperature') | float >= 10 }}
  - id: 'off'
    platform: template
    value_template: |
      {{ states('sensor.sonoff_1001e23ad2_temperature') | float -
      states('sensor.sonoff_100114a710_temperature') | float <= 5 }}
condition: []
action:
  - service: switch.turn_{{ trigger.id }}
    target:
      device_id: 69041622535e34621d9284d28b74abe7
  - service: logger.log
    data:
      message: Switch Turned {{ trigger.id|title }}!