Compare two humidity Sensors and have a fan come on if they are too far apart

What I’m trying to do. Bathroom Humidity is 4+ degrees more than Bedroom Humidity, turn on the bathroom exhaust fan, after the Bathroom Humidity is less than 4 degrees more than the Bedroom Humidity, turn off the Exhaust fan.

What am I doing wrong?

This is what I have so far:

trigger:
  - platform: time_pattern
    minutes: "1"
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: sensor.master_bath_humidity_centralite_3310_g_humidity
        above: sensor.bedroom_ac_current_humidity
        value_template: "{{ state.state|float(0) + 4 }}"
    then:
      - type: turn_on
        device_id: 19627a92f844fcb19495ee21522b2e91
        entity_id: switch.master_bath_exhaust_fan
        domain: switch
      - wait_for_trigger:
          - platform: numeric_state
            entity_id: sensor.master_bath_humidity_centralite_3310_g_humidity
            above: sensor.bedroom_ac_current_humidity
            value_template: "{{ state.state | float(0) + 3 }}"
      - type: turn_off
        device_id: 19627a92f844fcb19495ee21522b2e91
        entity_id: switch.master_bath_exhaust_fan
        domain: switch
    else: []
mode: single

This Time Pattern Trigger:

  - platform: time_pattern
    minutes: "1"

means it triggers once every hour at one minute past the hour. (00:01, 01:01, 02:01, 03:01, etc).

This Time Pattern Trigger:

  - platform: time_pattern
    minutes: "/1"

means it triggers every minute. I believe that’s what you want.

1 Like

I’ll change that. thank you. It did come on, though it didn’t seem to apply the comparison correctly. And it wouldn’t go off.

Honestly, I wouldn’t use a Time Pattern Trigger for this application. I would use Template Triggers or create a Template Binary Sensor to detect when bathroom humidity exceeds bedroom humidity (by 4%) and then use it in a State Trigger. In either case, the automation will trigger only when necessary as opposed to a Time Pattern Trigger which will trigger even when bathroom humidity is low.

Here’s what I suggest you do.

Create a Template Binary Sensor:

template:
  - binary_sensor:
      - name: High Bathroom Humidity
        state: >
          {{ states('sensor.master_bath_humidity_centralite_3310_g_humidity') | float(0) - 
             states('sensor.bedroom_ac_current_humidity') | float(0) >= 4 }}

It turns on when bathroom humidity exceeds bedroom humidity by 4 (otherwise it’s off).

Create an automation that monitors the Template Binary Sensor:

alias: example
trigger:
  - platform: state
    entity_id: binary_sensor.high_bathroom_humidity
condition: "{{ trigger.to_state.state in ['on', 'off'] }}"
action:
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: switch.master_bath_exhaust_fan
mode: single
2 Likes

Thanks. I’ll give that a shot!