[OBSOLETE] Smart Bathroom Fan

Smart Bathroom Fan

Bathroom fan automation can be tricky. If your house is anything like mine, it’s not exactly air tight. Seasonal changes in humidity can make it difficult to set specific relative humidity percentages at which to turn your bathroom exhaust fan on or off.

This SmartApp attempts to put some intelligence into the process by sampling the humidity in the room every five minutes and maintaining a rolling 24-hour average humidity. Your thresholds are then specified based on this average.


This SmartApp does the following:

  • Turns on the fan when the humidity is more than X percent greater than the 24-hour average.
  • Turns off the fan when the humidity falls to within Y percent of the 24-hour average OR after an optional (but recommended) specified maximum amount of time.

GitHub Integration

For easier updating, add the GitHub repository in your IDE account:

  • Owner: bkeifer
  • Name: smartthings
  • Branch: master


This SmartApp is provided with no warranty, either expressed or implied and by installing it you agree that I am not accountable for its actions. It will probably break. It might eat your homework. It will almost certainly pee on the living room rug when company is over.

In short, don’t blame me. I told you so.


This is genius…

1 Like

This is indeed nice work…

For our own home, I have decided, for the time being, NOT to have ST control my critical home items that depend on the stability of ST’s backend cloud and erratic scheduler… This is unfortunate, as I had high expectations of 99.9% dependability for items like my home alarm, HVAC, humidity/fan controls, door locks, heater outlets, etc…

So what I have done is use local devices when I can. For example, the DewStop FS-100 Condensation Control Sentry Fan Switch that perform flawlessly because all the logic is in the firmware. I do miss not being able to monitor the device or setup a customized schedule using motion sensors, etc…

I have made a decision not to bet on the availability and dependability of SmartThings (with their current backend issues), especially when a bathroom fan could potentially continue to run for hours or days waiting for a missed ST event or schedule…while one is on vacation for an extended point of time.


I wholeheartedly agree, but I’ve already considered that in the design!

If you use the auto-off after X minutes feature in this SmartApp, it does indeed use a scheduled event to turn the fan off. That said, there’s also a safeguard built in which is much more reliable.

When this SmartApp turns the fan on, it saves a timestamp in its state map. Each time the humidity sensor checks in, it also checks that timestamp against your auto-off time to see if the fan has been running longer than it should. This provides a failsafe for when the hamster powering ST scheduler falls off the wheel.


Ha… love the hamster reference…that is an excellent design… as we all now, the scheduler has been less than dependable.

Now all you have to worry about is when ST send’s a daytime firmware update and bricks the hub… Quick knock on wood three times!

Did you move this I cant seem to find this on your GitHub.

1 Like

Here’s the direct link:

Thank you, I had to enable OAuth is this expected? not had to enable so far on other smart apps.

It’s used for some watchdog functions that can help keep it scheduled in case of platform issues, but they require some non-trivial external infrastructure to use.

If you don’t want to enable OAuth, you can remove the mappings {} block (lines 33-36 in the github code as of 97c9f3a) as well as logURLs(), checkStamp(), and reschedule() (lines 181-213 in the same revision as above).

Its fine having it, just was not expecting it as there was no text to say this was needed until I found the error in the live logs. Your first post could also use an update as its no longer possible to add the details like you have in your first post.

I like it so far, the Daily AVG seems to be working well.



I’m not sure I follow. Could you elaborate?

When it works, it works well. Be aware that the ST platform is currently randomly deleting state for SmartApps. If it does this to your instance of this app, results may be unpredictable.

The current ide doesn’t allow for git hub integration? The code should have links now that tell the ide the location so you can tiger updates to be pulled down using the update section. I’m fail recent to this st arena and most of the post state like u have some thing I think they removed in favour for the updating system. At least that’s how I read the ide setup details currently out there. Even the ide docs seem out of date with still listing the git hub integration you refer to.

With regards to the avg logic I noticed that once the fan is triggered in my case 5% increase the avg continues to update rising slightly each time. This seems to slight skew the avg while say the shower is on. Is it possible that once triggered the avg is locked or not changed so that once the room returns to the amt set in my case 2% of avg and the fan stopped the avg won’t have risen by 2% in the mean time giving me a actual 4% increase? Now I could reduce the 2% to 0% to account for the rise but that rise depends on how long it stays above the avg. If several ppl shower after each other the avg may increase even further skewing it even further. Anyway just a thought. I don’t know code so can’t suggest how that could be performed.

I love this app, thanks @btk! I have been playing with the right numbers. I really had no idea what the best practice was so I started with start at +5% and stop at +2%. It became immediately apparent to me that this was underkill as my base humidity was 37% and when I started the shower it went up to 80%. :slight_smile: I left it just to have a true first iteration. The fan definitely came on, and went off after the 60 minutes I set, but then it came on a few more times incorrectly.

I have now set it to start at +25% and stop at +5%. If anybody has gone through any experiments, would love to hear what works best for people.

Finally I will say that I don’t know how I used to get by without my Everyspring st814-2’s for temp/humidity. I basically have one in every room of my house and I can’t say enough positive about them. I went through about 5 other options trying to drive my HVAC system and was always let down. These things are gold and have been rock solid for over 2 years in some cases. If you are trying to rely on temp or humidity readings, they are must have.

here you go think I worked out how to make it not update while the fan is on so that the avg doesn’t get pulled up while the room is humid

def updateAmbientHumidity() {

def q = state.ambientHumidity as Queue

if (state.fanOn == null)
while (q.size () > 288) { q.poll()}

state.ambientHumidity = q

Float rollingAverage = state.ambientHumidity.sum() / state.ambientHumidity.size()
Float triggerPoint = rollingAverage + humidityHigh
log("Rolling average: ${rollingAverage.round(1)}% - Currently ${sensor.currentHumidity}% - Trigger at ${triggerPoint.round(1)}%.")


Great app thank you! I installed it a couple of days ago and it works great!

I have a bathroom in the basement without window and after taking a shower humidity goes up. I use 5% to turn on and 3% to turn off. After the fan gets the humidity out initially it will climb back up as the shower floor and towels dry up. Not sure how/if this impacts the 24 hr average calculation. The fan then starts running again as defined in the app. It does work great!

I have a feature request (if I am allowed to… :blush: ): option to turn in fan by comparing humidity to external sensor (I have a nest thermostat installed in the hallway that is a good reference).

Again, app works great! Thank you! Here is my initialstate log. The pink line is humidity in the bathroom and the blue line is humidity measured by the nest in the hallway.

I installed this app and I am having a little trouble. I am using a Zooz 4 in 1 multisensor. That is installed properly and I can see all of the readings, including the humidity reading history. When I program the app, I entered 5 in the turn on above above average humidity field and 2 in the turn off below average humidity field. I then entered 25 in the turn off after regardless of humidity. Then I press Done, and I get the green bar across the top that says Smart Bathroom Fan is installed and automating.Trouble, is the fan never comes on. I look at the activity of the devices and there are no commands in history looking to turn the fan on. Only other weird item I see is that when I go back into the app after pressing Done to re-check settings, the turn off after X regardless of humidity is blank even though I entered 25. Tried several different numbers in that field several times, and every time I go back in that field is blank. What am I missing? Is there something else I need to do or install to get this to work?

I couldn’t get it to install. I was getting errors in the line that reads the humidity. I messed with it for a bit but gave up. I ended up writing a couple pistons in core. I have 2 humidity sensors in the house so I compare my bath sensor to my living room sensor and if it is 5% higher, it will turn on the fan. I’ve had a few quirks but overall I have been happy because I can limit the fan coming on for humidity only if the door is closed, etc. I can limit total run time. My wife can still turn on the fan if she uses harsh chemicals while cleaning.


I have just seen this and have read through the complete post.
I’ve installed it just to have a look.
I’m not sure if I’ve missed something or I need it installed for 24hrs to get the average, but how do I see what the average seting is?
Is there anyway to see this or do I just let it run and do its thing.
EDIT: Looking at the logs, I can see the average and trigger point.

I just installed this application but when I attempt setup the smart app I get am error saving the page.

I am using an AeoTec Multi-sensor 6 which SmartThings sees as a humidity sensor and a virtual switch which controls one of my switches on a dual-switch pack.

Are there settings you can’t use? I tried 10 for the fan on and 3 for the fan off with a 30 minute timer regardless.