Switch devices on and off based on two seperate temperatures

So here is the formula/scene/automation I need to construct:

If Temp A>Temp B then Device A On and Device B Off or If Temp A<Temp B then Device A Off and Device B On

How do I achieve this in HA?

The use case is an HVAC system that has two inputs, one outdoors and one from the loft space. Most of the year I always want the unit to pull in the warmest air. I have a Shelly 2PM plus to activate the valve actuators and an addon with two DS18B20’s to measure the temperatures. I can switch them manually but whats the point when I have HA. I probably will also want to add a temperature ceiling for when summer arrives i.e. if loft temperature >25 Deg C then take outdoor air.

Any suggestions to take my HA automations to the next level would be greatly appreciated

Mark

Something like this:

trigger:
  - platform: state
    entity_id: sensor.temp_a
    to: 
  - platform: state
    entity_id: sensor.temp_b
    to: 
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.temp_a
            above: sensor.temp_b
        sequence:
          - device A on action here
          - device B off action here
      - conditions:
          - condition: numeric_state
            entity_id: sensor.temp_b
            above: sensor.temp_a
        sequence:
          - device A off action here
          - device B on action here

Note that the automation will still trigger if temp A = temp B, but nothing will happen.

1 Like

Thank you very much for this Tom. I will give it a go. This is my first time getting into scripting in HA so will find a few tutorials to get me started.

Mark.

Hi Tom. I got this working. Thanks for your help, much appreciated.

Mark

1 Like