Automation: Triggered when there is a difference between two humidity sensors

i have two Bluetooth Temperature Humidity 2, I want to create an automation that starts the fan when the outdoor humidity is 20% lower than the indoor humidity, and the outdoor humidity is below 60%, and the time is between 8:00 and 18:00.
Outdoor meter information

  • type: is_humidity
    condition: device
    device_id: 187c277635856fd59832d6ab61baab2d
    entity_id: d76460cb16f6c78acf762b4fb71e138c
    domain: sensor
    Indoor meter information
  • type: is_humidity
    condition: device
    device_id: 64aca92447ebed87d67380f8a94d773a
    entity_id: 38af55c6c3b6c0cdbbc1ba8b9e018549
    domain: sensor
    Fan switch
  • type: turn_off
    device_id: 8539f6499966c4d39ea05b86c2e1d2a5
    entity_id: 1c194f5d40d

thankyou!

Hello matt19891231,
Welcome to the home assistant forums!

I’m sure that can be done. Also having someone or something writing it for you means the second it misbehaves, you will be struggling back to find someone to fix it for you.

The best way to learn is to just try. Run thru the docs on getting started with the automation editor. If you get stuck, come back with what you have done.

and
The Home Assistant Cookbook - Index.

1 Like

What are the real entity IDs for your two sensors and the switch? I don’t work with devices.

Add three triggers: any change to either sensor and 08:00;.

Add a time condition for the time window, a numeric state condition for the outdoor humidity test, and a template condition to check the difference.

outdoor:室外,indoor:室内,fan switch:排气扇。
I saw this link yesterday, but I’m still not sure how to get specific values. I hope everyone can provide an example so that I can take a lessons from it. It’s better to write it in YAML, I know nothing about it.Thank you again for your help.

It’s not “better” to write in YAML in general, but it is far easier to share code in this forum in YAML.

Here’s an example. I think that 室外 is the “friendly name” for your outdoor sensor, and it must have an ASCII entity id. I’ve used sensor.outdoor (and similar for the others) below — you will have to find out the real entity IDs.

I have assumed that you meant "when the outdoor humidity is 20% (or more) lower than the indoor humidity.

The 08:00 trigger is to ensure that the fan starts promptly if all the other conditions are already met at that time, rather than waiting for the next sensor reading.

triggers:
  - trigger: state
    entity_id:
      - sensor.outdoor
      - sensor.indoor
  - trigger: time
    at: "08:00"
conditions:
  - condition: time
    after: "07:59"
    before: "18:00"
  - condition: numeric_state
    entity_id: sensor.outdoor
    below: 60
  - condition: template
    value_template: "{{ states('sensor.indoor')|int(0) - states('sensor.outdoor')|int(0) >= 20 }}"
actions:
  - action: switch.turn_on
    target:
      entity_id: switch.fan

thank you! i will try right now


Is the arrow pointing to the entity ID?

Yes, although that is a temperature sensor.

I roughly understand now. Let’s wait until tomorrow to see if it will trigger automatically. I need to lower the humidity value a bit to trigger it.thank you!

Use the </> button for code, or use three backticks:

```
CODE GOES HERE
```

triggers:
  - trigger: state
    entity_id:
      - sensor.miaomiaoce_t2_3408_relative_humidity
      - sensor.miaomiaoce_t2_8a5b_relative_humidity
conditions:
  - condition: time
    after: "07:59"
    before: "18:00"
  - condition: numeric_state
    entity_id: sensor.miaomiaoce_t2_3408_relative_humidity
    below: 60
  - condition: template
    value_template: >-
      {{ states('sensor.miaomiaoce_t2_8a5b_relative_humidity')|int(0) -
      states('sensor.miaomiaoce_t2_3408_relative_humidity')|int(0) >= 10 }}
actions:
  - action: switch.turn_on
    target:
      entity_id: switch.chuangmi_212a01_3789_switch
    data: {}

like this?is that any wrong?

微信截图_20250129172411

it works! it’s fantasy

Excellent. You have not included the 08:00 trigger, but that doesn’t really matter if your humidity sensors are sending frequent updates.

It will also send multiple “turn-on” requests to the switch, but that shouldn’t matter. If you wanted to stop that, you could add an additional condition to check the switch is off before trying to turn it on:

  - condition: state
    entity_id: switch.chuangmi_212a01_3789_switch
    state: 'off'

OK, i will try it