Naive Bathroom Fan Humidity Control (correct format this time)

This blueprint is a naive first pass at controlling fans by the change in humidity in a room over time.

Feel free to tweak and edit to your hearts content of course! There’s no way this covers all but a naive scenario, though so far it’s been good enough for me.

Pay close attention to the comments in the YAML, in particular you need to set up a “derivative” sensor for this to work.

# Bathroom Fan Humidity Control
# 1) Set up a derivative sensor built up from your humidity data.
# You can do this by manually editing your configuration.yaml file with a new "derivative" sensor.
# Here is an example, based off of a "sensor.master_bathroom_humidity" sensor that's already set up, and
# I'm taking a derivative of the change in humidity over the last 5 minutes.
# sensor:
#   - platform: derivative
#     source: sensor.master_bathroom_humidity
#     name: Master Bathroom Humidity Delta
#     round: 1
#     unit_time: min
#     time_window: "00:05:00"
# ---
# 2) Add this blueprint to your blueprints.
# 3) Choose your new derivative sensor for the "Humidity Derivative Sensor" input.
# 4) Choose reasonable values given your environment for how much the humidity has to change over a 5 minute period
#    (or whatever you set your derivative sensor to) before you start the fan
# 5) Choose a value for how long the fan should run based on how long you've observed your fan taking to clear out the
#    room of moisture after a shower.
# 6) Choose the switch for your fan.
# 7) Enjoy and tweak, as this first pass is probably not going to be sufficient: but hopefully it serves as a good
#    starting point for something more sophisticated.
  name: Bathroom Fan Humidity Control
  description: A first pass at controlling bathroom fans by checking the change in humidity and being able to enter your own guesses for certain thresholds.
  domain: automation
      name: Humidity Derivative Sensor 
      description: IMPORTANT set up a derivative sensor for your humidity in configuration.yaml and restart before using this!
      name: Percent change to start fan
      description: Over the given period of time, how much % should the humidity have risen to trigger this fan.
      default: 10
          min: 1
          max: 100
          unit_of_measurement: percent
      name: Fan Switch
            domain: switch
      name: Duration of time to run
      description: once humidity threshold has been reached, run the fan for this long.  Restart the timer if the threshold gets reached again.
      default: '00:45:00'

  - platform: numeric_state
    entity_id: !input humidity_derivative_sensor
    above: !input humidity_change_percent_to_start
    below: '100'
    for: '00:00:01'

  - service: switch.turn_on
    target: !input fan_switch_target
  - delay: !input time_to_run
  - service: switch.turn_off
    target: !input fan_switch_target

mode: restart
max_exceeded: silent

This works great and its easy to set up, do you thing we coude work out a way for the fan to go off when it get to a certain humidity?
great work.

1 Like

Sweet, I’m glad it works! Definitely that would be feasible, though I don’t have much time to look into it these days (I just had a baby, yikes!). But I’m 100% certain it’s possible to do, I remember initially that I was going to do that but there were some complexities around it: for instance, what if it’s raining and thus the overall humidity of the house is high? I think there’s something you’d have to do around “relative” humidity compared to the rest of the house for it to work well, but that’s when I decided to just do the dumb/simple thing and give it a reasonably long timer.

But if someone has time, there’s absolutely room for improvement here!

1 Like

Congratulations !

1 Like

congrats on the baby!!!make sure to get them into coding early :smiley:

I figured that would be the reason for the timer, it just makes sense.
I do have humidity sensors all over my house so theoretically I could do something that checks relative humidity but that would become a a complicated web to maintain.

1 Like

Thank you both! <3

Yeah, it’s an interesting problem. I’m curious about how old school “relative humidity” in-wall panels do it. When I moved into this place I replaced one of those (that had been installed in the late 80’s) with a smart switch that I wanted to control with home assistant. Ended up settling on this simple solution, but those dumb in-wall panels were actually intuitively doing what would take a bit of effort and multiple sensors to do with the home assistant approach, and I’m not quite sure how. I’m going to have to look that up sometime. I can’t imagine it had any microcontroller or memory to store historical humidity data, and I don’t see a way that it could have more than just a sensor on the panel itself which means it won’t know the humidity in the rest of the house. Maybe whatever it was doing would provide a hint for how we could do this more elegantly as well.

(the one I replaced was one of these, but from the 80’s

Thank you very much for starting this; I am looking for a bllueprint/automation to set this up.
I just switched to HA from Domoticz and had an automation built roughly this way:
If humidity went up more then 10 within 10 minutes (from a shower for instance) it would save the initial humidity to a variable and fire up the fan at high setting. It would switch off after either a predefined time (say an hour), or if the humidity went down to the initial setting. Is this something you plan to build?


It’s a good idea if there’s support for stored variables! I can’t recall now, it’s been so long since I made this little thing that I don’t remember what sort of tools were available. With the kiddo, I won’t have the time to investigate it further in the near future unfortunately - so if one of you folks wants to take up the mantle and run with it that’s great!

not working for me =(
strange value in derivative sensor
Bathroom Humidity Delta -9 385,2 %/min

You may want to edit the title. It may not be saying what you think it’s saying…

On the title, that’s intentional to warn people - I have a lack of experience both in making HA blueprints, and it took an unsophisticated approach of just turning on for a fixed length of time instead of trying to do anything fancy around detecting relative humidity etc.

There’s a lot of room for someone to make a better blueprint that actually does something like that if anyone found the cost/benefit ratio of it to be worthwhile!

IRT the derivative sensor not working, unfortunately I don’t know why that’s happening. That sounds like more of a problem with either your physical sensor, the integration with your physical sensor, or HA’s derivative sensor. Unfortunately I don’t know how to fix any of those. All I know is that the blueprint is working for me locally with the sensor that I happen to own.


Yeah, I’m having the same issue here. I’ve been trying to figure this out - in the meantime, curious if you were able to find a solution? I’m tapping humidity data coming from this sensor.

Ciao Edgar, progetto splendido, lo uso in 2 bagni,
Un’info vorrei accendere e spegnere la cappa d’aspirazione ma non tramite uno switch ma con uno script, è possibile?

I cant get this to work, have made the sensor and everything, been trying using “Aqara temperature, humidity and pressure sensor”, “TuYa TS0201” and " SONOFF SNZB-02" but cant get it to turn on fan, it works only if i “Run action”,. no automation. Anyone else have this proiblem?