Trigger automation based on relative value

Good afternoon,

I have an automation that turns on a fan when humidity reaches 69%, and shuts off when it goes down to 60%.

There is also a trigger to turn off fan if the humidity falls below 50%. This second off trigger is there in case I turn on the fan manually, but the humidity is already below 69%.

This works in the summer when humidity is high, but not so much in winter when humidity can fall way below.

I would like to change the trigger to be a relative based on other sensor.

Something like:

  • If fan OFF & inside humidity is above [outside humidity] x 1.2 then
    • trigger automation to turn fan ON.
  • If fan ON & inside humidity is below [outside humidity] x 1.1 then
    • trigger automation to turn fan OFF.

example 0:
outside humidity 45%
inside humidity 60%
fan off
trigger automation to turn fan ON as 60% is above 45% x 1.2, or 54%.

example 1:
outside humidity 45%
inside humidity 53%
fan on
trigger automation to turn fan OFF as 53% is below 45% x 1.1, or 49%.

My current automation is as follows:

alias: "Base: bath: Fan: ON/OFF on humidity"
description: Turn on fan if too humid, off if okay in basement bath.
mode: single
triggers:
  - entity_id: sensor.weathersensor5_humidity
    above: 69
    trigger: numeric_state
  - entity_id:
      - sensor.weathersensor5_humidity
    below: 60
    trigger: numeric_state
  - entity_id:
      - sensor.weathersensor5_humidity
    below: 40
    trigger: numeric_state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.weathersensor5_humidity
            above: 69
        sequence:
          - type: turn_on
            device_id: ee952
            entity_id: f7369
            domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.weathersensor5_humidity
            below: 60
        sequence:
          - type: turn_off
            device_id: ee952
            entity_id: f7369
            domain: switch

I have attempted something like:
above: "{{ state_attr('sensor.lumi_lumi_weather_humidity_2', 'humidity') * 1.2 }}"

in above, where the sensor is the external humidity sensor, but no such luck.

Thank you and Merry Christmas and Happy New Year!

Rather than putting it all in the automation, have you tried creating a template binary sensor to handle the relative values? Then the trigger would be a simple on/off.