Bath Fan Switch and Humidity

Here is a rule that does two things:

  • When switch is turned on, FAN run for 30min
  • When switch is tuned on again, 30 additional minutes is added to time (each time)
  • When humidity is above 60%, FAN runs

I'm new to Hubitat and RM, feedback is happily accepted...

You realize that the rule is going to be triggered every time that a measurement from the humidity sensor is received and the value is >= 65, correct? Numeric triggers are not thresholds, they are statewise. So, I don't see how this rule is going to work when you are going to be triggering it every time a sensor reading is received.

Yes, that is correct. Every time the sensor sends data over 65RH (about every 3min) it will start the rule again. The first 3 lines of the rule have the effect of canceling the previous running rule (cancel/stop/cancel lines) so the rule just stars over and it goes back into the wait line for the sensor to be under 65RH.

Could be a more elegant way to write the rule, and if you have a suggestion I'm happy to hear it.

So, I'm not sure I understand what the point is then. When your rule re-fires, it's going to reset all the counters again.

I'm confused....are you posting this because it works correctly as an example for others to use or because it does not and you need help getting it to work?

It works great, so I was posting for others to consume and/or adjust to their liking.

I think what you are seeing is that the humidity is meant to override the manual settings. So, if you have the fan on for 2hrs and then humidity goes over 65RH it will reset the time and turn the fan off when humidity is less than 65RH.

I hadn't thought of that UC because it's not something I do, but maybe v2 of the script could be more complex and handle scenarios like that. I'd just have to use the manual delay separately from the humidity. If I do a more complex script that handles this, I'll post it.

So, you want the fan to always be on if the humidity is above 65 but turn off after a timeout if it is below 65%?

There are humidity fan apps that handle this situation. Did you try any of them? From what I understand, apps are always better than rules, they take less resources and/or run faster.

I use this one, it works great.

If that is truly all you are trying to do, the rule is a LOT simpler.

Trigger:  Humidity Changes

Actions:
IF Humidity is <=65 and PB is true THEN
     Set PB to False
     Delay actions for X mins (cancelable)
     Turn off fan
ELSE IF (Humidity is >= 65 and PB is False THEN
     Set PB to True
     Turn on Fan
END-IF

Your requirements at the top are in contradiction:

Which is the overriding control? The timeout or the humidity? If the Humidity is over 60 and the timeout ends, will the fan stay on or off? What if the humidity goes below 60 before the timeout? Will the fan stay on or turn off?

Also, you can't turn a switch on twice. That's not how switches work. The switch will turn on once then it has to be turned off again before being turned on again.

The switch I am using (GE enbrighten Smart Switch) will send Hubitat a "button 1 pressed" for ON and "button 2 pressed" for OFF (regardless of the current state of the switch). That's what I am using for my triggers (not ON/OFF). That's why my rule works so well - I can press ON 4 times in a row and the fan will stay on for 2hrs (4*30min).

Yes, I mentioned in my previous reply that humidity will override the manual timer. This isn't an issue for me, and could easily be solved with changing the rule a bit (see above).

Thanks @neonturbo! I haven't ventured into the app part of Hubitat. I'll definitely give them a look and see how they work.

I'm sorry, I'm just not following...Lets say that the humidity goes up to 70. The rule is triggered and the first part turns the fan on and sets delay to -29. Now the second part first and sets delay to 1. THen you get to the repeat, that will keep the fan running for one minute. Then you get to the wait. Delay is already 0, so its just going to wait for the humidity to drop to turn the fan off.

Now, lets say while the fan is running, you press button 1. The first part of the rule will fire again, setting delay back to -29, then the next part also fires, setting the delay to 1 and then it repeats once and again delay is 0. So, we're back to just waiting for humidity to be below 65. So, I don't understand why you think the fan will stay on for an hour in that case. As soon as the humidity is below 65 then the fan will turn off.

If you want to overrride with a timeout when humidity is below 65, then just wrap the whole thing in that condition and have the humidity and the manual fan handled separately. It would make your rule a hell of a lot less complicated and wouldn't have to use repeats and waits.

@Ryan780, thanks for your comments but we are saying the same thing, just in different ways. I'm not focused on that edge case because it's mostly irrelevant to how I've used the switch for the several weeks. Here are three things it does really well:

  • if I turn the FAN on manually it will stay on for 30min and will turn off.
  • if I turn the FAN on manually and then (within 30 min) turn it on 3 more times, it will stay on for 2hrs and then turn off
  • if there is humidity, it will turn the fan on automatically and off after humidity is done

Humidity always overrides the manual fan control, and that's ok for my cases. But, certainly it would be possible to enhance the script to handle that scenario (although, as @neonturbo pointed out, might be better to do an app at that point).

There are much, MUCH easier ways to accomplish the exact same thing that do not involve such complicated and convoluted rules and do not involve variables and waits.

Also, if your humidity is low, why would you ever want to run your bathroom fan for 4 hours? Exhaust fans are very energy inefficient. Plus, you are pulling warm/cool air out of your house.

@Ryan780 I'd be very happy to learn from you on how to accomplish the above 3 scenarios in the Rules Machine without using a variable or a wait. Please share.

I already said, handle them separately. Simply use two rules, one for manual and one for humidity. Since you aren't using them interchangeably, you don't need them in the same rule.