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
# SETUP:
# 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.
blueprint:
  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
  source_url: https://github.com
  input:
    humidity_derivative_sensor:
      name: Humidity Derivative Sensor 
      description: IMPORTANT set up a derivative sensor for your humidity in configuration.yaml and restart before using this!
      selector:
        entity:
    humidity_change_percent_to_start:
      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
      selector:
        number:
          min: 1
          max: 100
          unit_of_measurement: percent
    fan_switch_target:
      name: Fan Switch
      selector:
        target:
          entity:
            domain: switch
    time_to_run:
      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'
      selector:
        time:

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

action:
  - 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
5 Likes

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 https://www.amazon.com/Honeywell-H46C1166-Dehumidistat/dp/B003CVT5ZK/ref=asc_df_B003CVT5ZK/