How to combine two automations into one - Turn on/off fan, when RH is different between two sensors

I have these two automation that I want to combine or maybe there is a completely different way of implementing this, any pointers or guidance would be great.

I have seen a few posts regarding combining two automations, but I haven’t been able to figure out how to adapt them to what I need.

alias: Air Circulation Fan On
description: >-
  If Workshop 3 RH is greater than Workshop 2 RH by 0.5% or more, turn on Air
  Circulation Fan
trigger:
  - platform: template
    value_template: >-
      {% set workshop2_rh = states('sensor.h5100_5e5f_humidity')|float %} {% set
      workshop3_rh = states('sensor.h5100_3536_humidity')|float %} {% set
      difference = workshop3_rh - workshop2_rh %} {{ difference >= 0.5 }}
    for:
      minutes: 5
condition:
  - condition: state
    entity_id: switch.tbp_switch_4570
    state: "off"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tbp_switch_4570
mode: single

alias: Air Circulation Fan Off
description: >-
  If Workshop 3 RH is less than or equal to Workshop 2 RH by 0.5% or more, turn
  off Air Circulation Fan
trigger:
  - platform: template
    value_template: >-
      {% set workshop2_rh = states('sensor.h5100_5e5f_humidity')|float %} {% set
      workshop3_rh = states('sensor.h5100_3536_humidity')|float %} {% set
      difference = workshop3_rh - workshop2_rh %} {{ difference <= 0.5 }}
    for:
      minutes: 5
condition:
  - condition: state
    entity_id: switch.tbp_switch_4570
    state: "on"
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.tbp_switch_4570
mode: single

Give the triggers an ID and use a choose action with two options and use condition: TriggeredBy = trigger_ID

This is what I have ended up with and it’s all working. Thanks for the help @aceindy

alias: Air Circulation Fan Control
description: Control Air Circulation Fan based on Workshop 3 and Workshop 2 RH
trigger:
  - id: circulation_fan_on
    platform: template
    value_template: >-
      {% set workshop2_rh = states('sensor.h5100_5e5f_humidity')|float %} {% set
      workshop3_rh = states('sensor.h5100_3536_humidity')|float %} {{
      workshop3_rh >= (workshop2_rh + 0.5) }}
    for:
      minutes: 5
  - id: circulation_fan_off
    platform: template
    value_template: >-
      {% set workshop2_rh = states('sensor.h5100_5e5f_humidity')|float %} {% set
      workshop3_rh = states('sensor.h5100_3536_humidity')|float %} {{
      workshop3_rh <= (workshop2_rh - 0.5) }}
    for:
      minutes: 5
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: circulation_fan_on
        sequence:
          - condition: state
            entity_id: switch.tbp_switch_4570
            state: "off"
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.tbp_switch_4570
      - conditions:
          - condition: trigger
            id: circulation_fan_off
        sequence:
          - condition: state
            entity_id: switch.tbp_switch_4570
            state: "on"
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.tbp_switch_4570
mode: single

1 Like