Rules engine with bathroom fan sensor

I’m trying to do something. I have the Aeontech AerQ sensor in my bathroom.
Rule 1
I set up a rule so that when humidity hit 50% or greater it would trigger the fan which is a homewerks Alexa fan. Basically, I’m triggering an Alexa routine that starts the fan.

Rule 2
Then I created another rule that when humidity is 40 or less it would shut off the fan (alexa routine).

Ok, my issue. Rule 2 is triggering several times during the day. And there are no showers going on. Is there a way to have this rule go live only after Rule 1 has been triggered and the rule 2 settings have been triggered. I think because it’s sitting at 40 or moving slightly up and then slightly down, it’s triggering Rule 2.

I know this is possible. Thanks for your help.

I would do this by setting a Boolean variable from rule 1 as true and having a condition in the flow of rule 2 that the variable from rule 1 is true.

Thanks for your response. What is a Boolean variable?

Boolean is a true or false variable.

A Boolean is a true/false variable.

Variables for Rules and Dashboards!

You would create the variable and in the rule 1, add set variable true.

In rule 2, I’m guessing your trigger is humidity is less than 40. Add an if statement that says if variable is true then turn off fan, set variable false.

5 Likes

Thanks for the additional instructions. Sometimes it takes me a while to learn new concepts, but once I grasp them, my creativity and imagination shine.

2 Likes

I found a message the fan turned off at 5 am. Lol. Ill get some screen shots and see where i went wrong.

1 Like

What was the humidity of the bathroom at 5 AM?

Here is a quick view of rule one and two

Youtube

It was 37% at 5:48 am. It continued to off several times until I disabled it.

Can you post screenshots of the rules? I looked at the link but it was hard to read.

1 Like


1 Like

There’s also a Rule screenshot feature that can help you take a full screenshot of the rule.

2 Likes

I dont see anything setting $bathroomFan to false. You’ll need to add set $bathroomFan false after the fan is turned off in the first screenshot, otherwise it will continue to turn off when the humidty is triggered.

Another thing to keep in mind is that the “changes and is below XX” trigger will trigger every time the value is reported and it’s below 40… not just when it changes to below 40 (or above it in the 50 rule).

As Nemo, Jake, Terri and others alluded to, one approach would be to use a variable to flag if the high-humidity action was taken so you can condition the low-humidity action on that. You just have to make sure to set it back to false again after you take your action in the conditional low-humidity rule as Terri mentioned. :slight_smile:


Another approach some people like to take is to create a separate rule just for setting true/false variables that indicate if the humidity is high or low, so you can use those as triggers and conditions in other rules. (The beauty of this is what it enables with ‘state stays’ which I’ll cover below)

Triggers:
Humidity changes and is greater than 0 (basically anything)

Flow:
If $context.event.value <= 40
THEN Set $isHumidityLow = true
ELSE Set $isHumidityLow = false

If $context.event.value >= 50
THEN Set $isHumidityHigh = true
ELSE Set $isHumidityHigh = false

The beauty of this is you can then use a ‘state stays’ trigger on the variables and it will only fire when that variable first gets changed to that value and stays that value for a period of time. The variable getting set to true over and over again won’t retrigger the rule with a ‘state stays’ trigger on a variable.

Triggers:
$isHumidityLow stays true for 2 minutes

Flow:
Turn the fan off

2 Likes

Ok, i think I got the fist part done. And now I create two more rules and incorporate humidity into them? Thank you for your patience and and explanation.

1 Like

Yes, that looks like it would work for the second approach I mentioned. For the other rules, make sure to use State Stays trigger for the variables so it will only run the rule flow the first time is stays true (rather than each time the variable updates from the first rule).

1 Like

Ok, here is high humidity, turn fan off. In the flow I am having a virtual doorbell pressed (=st3-high-bathroom-humidity) this triggers an Alexa routine to turn the fan off. The second flow is to announce a message from my echo show 15. Can I combine them into one flow as follows:

post
https://api.voicemonkey.io/trigger?access_token={{$VoiceMonkeyAT}}&secret_token={{$VoiceMonkeyST}}&monkey=st3-high-bathroom-humidity&voice=Amy

JSON
{
“monkey”: “alexa-bathroom-monkey”,
“announcement”: “The humidity is getting high in here. I’m going to turn on the fan for a little while. I will turn it off when the humidity drops to normal levels. Enjoy your shower.”
}

Awesome! I got it to work! Wohhooo. I’m so excited. Mooohahhahah. Im going to bed now, thank you everyone!!!

2 Likes