How to create a rule/timer so that IF LIGHT has been on X seconds turn EXTRACTOR FAN on for X seconds once lights has been turned OFF


#1

Hi Webcore team,

I have a light in my bathroom and want to use it as a trigger to turn on the extractor fan …

If someone uses the bathroom for 2 mins I want the extractor to just run for 2 mins after the light turns off. (wee?)

If someone uses the bathroom for 5 mins I want the extractor to just run for 5 mins after the light turns off. (number 2!?)

If someone uses the bathroom for 20 mins I want the extractor to just run for 20 mins after the light turns off. (shower?)

Any ideas how to do this ?

Thanks,
Christopher


#2

Just a quick thought here. I don’t have fans controlled by webcore so I did not test this. Others may have better suggestions/modifications.

IF Bathroom_Light changes to ON
followed within 2 minutes by
Bathroom_Light changes to OFF
THEN
    Turn ON Bathroom_Fan
    Wait 2 minutes
    Turn OFF Bathroom_Fan

IF Bathroom_Light changes to ON
followed within 5 minutes by
Bathroom_Light changes to OFF
THEN
    Turn ON Bathroom_Fan
    Wait 5 minutes
    Turn OFF Bathroom_Fan

IF Bathroom_Light changes to ON
followed within 20 minutes by
Bathroom_Light changes to OFF
THEN
    Turn ON Bathroom_Fan
    Wait 20 minutes
    Turn OFF Bathroom_Fan

The logic gets more complex if the fan is running (say for 20 minutes) and someone comes into the bathroom and turns the light on…


#3

My suggestion is not better or simpler than @Pantheon’s just a different approach…

I haven’t use recording “time” in any of my pistons but if you just search the forum i’m sure you’ll figure it out…
When the light turns ON
Record the starting time… (Let’s say 11:10am)
When the light turned OFF
Again record the time… (Let’s say 11:15am)
Save the difference into a variable
@bathroomtime = 5min

Run the fan with @bathroomtime variable..
Turn ON Fan 
Do Wait @bathroomtime 
Turn OFF Fan

But in my experience with smarthomes it’s always better just to keep it simple.
If I were you, I would just go for a fixed time for fan running.
IF the light turns OFF
Run the fan
WAIT 8 minutes
Turn off the fan

IF the light turns ON
Cancel pending tasks

in this case 8 minute will start again if anyone comes in before 8minute is up…


#4

@ike2018, LOL. That is the logic that I first wrote for my response and then I changed my mind! Like minds…


#5

LOL:)
As I said I haven’t try that one before so I’m not sure about the syntax of it…:slight_smile:
Would you mind sharing how that could be done? (Recording time is simple but I don’t know how to calculate the minutes between the begining and the end)


#6

You are right, the logic gets quite complicated if say the fan is set to spin for 8 minutes and then someone comes in for 1 minute … does the fan then spin for 8+1 minute, 1 minute or what.

Thanks Pantheon for the logic, but how would the three IF statements distinguish between each other as if the light turns off within 2 minutes all of them are true - so I think there would need to be a “under 2”, “2 to 5” and “5-20 or above” in there.

At the moment the fan runs for a standard 5 minutes after the light goes off which means a quick wee at night and the fan is spinning for ages, whereas when 3 people have a shower (one after each other - not at the same time!!!) the 5 minutes is not enough to fully extract the steam.

Hence the timer … in fact, if there are three people who go for a wee one after another (2 mins each) then I would like the timer to add it all together and run for 6 minutes.

So, basically … lights on = start timer and start fan
lights off = run the fan for the duration of the timer - timer starts to countdown
if light turns on again add more time time to the timer

I am sure that this is logically possible with variables …


#7

Yes, @Snuker, you are correct. My IF’s will run in tandem. I should have waited for my coffee to kick in and stayed with my original plan like @ike2018’s suggestion with time variables. Give me a little bit and I will re-code this…


#8

Thanks … as I say I want to have a way that a long shower is de-misted without someone popping in for a wee resetting the extractor to ‘1 min’ … without the simplicity of just having the fan whirrrrrr for 10 mins regardless like a ‘dumb’ standard extractor :slight_smile:


#9

Ok, I have had a difficult time working with this piston. Here is what I have. I am just getting into the meat of webCoRE so the logic is perplexing. I would appreciate some outside input here. I have NOT been able to test this so criticism/suggestions/edits are welcome. One of the trouble spots is found in the desire to NOT turn off the fan early when a longer time is needed (like after a shower) when someone else uses the bathroom for a short period of time. I have included two photos. The “RED” one so that the device names are present and the GREEN one to load for testing.


#10

I suppose one could use a global variable to avoid the early fan shut off. I’ll give that some thought.