Jump to content

Programming how to make a timer?


ThisIsTheWay

Recommended Posts

Posted (edited)

We have two switches in our bathroom.  One for lights one for exhaust fan. When the light is turned on, the fan turns on.  I would like to keep track of how long the light is on so that when the light is turned off, the fan stays on for the same amount of time the lights were on with a minimum of a 5 min on time.

Here is my code so far.  Curious if there was a better cleaner way to do this.

 

fan on via human - [ID 006B][Parent 006C]

If
        '2 / M.Bath / TopHatsMain' is switched On
     Or '2 / M.Bath / TopHatsMain' is switched Fast On
     Or '2 / M.Bath / TopHatsSink' is switched On
     Or '2 / M.Bath / TopHatsSink' is switched Fast On
     Or '2 / M.Bath / TopHatShower' is switched On
     Or '2 / M.Bath / TopHatShower' is switched Fast On
 
Then
        Set '2 / M.Bath / Fan' On
        Stop program 'fan timer run'
        Run Program 'fan 5min primer' (If)
        Run Program 'fan timer add' (Then Path)
 
Else
   - No Actions - (To add one, press 'Action')
 

 

fan off via human - [ID 006E][Parent 006C]

If
        '2 / M.Bath / TopHatsMain' is switched Off
     Or '2 / M.Bath / TopHatsMain' is switched Fast Off
     Or '2 / M.Bath / TopHatsSink' is switched Off
     Or '2 / M.Bath / TopHatsSink' is switched Fast Off
     Or '2 / M.Bath / TopHatShower' is switched Off
     Or '2 / M.Bath / TopHatShower' is switched Fast Off
 
Then
        Stop program 'fan timer add'
        Run Program 'fan timer run' (If)
 
Else
   - No Actions - (To add one, press 'Action')

 

 

fan 5min primer - [ID 0070][Parent 006C]

If
        $M.Bath_Exhaust_Fan_Timer < 5
 
Then
        $M.Bath_Exhaust_Fan_Timer  = 5
 
Else
   - No Actions - (To add one, press 'Action')
 

 

fan timer add - [ID 006D][Parent 006C]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        Wait  1 minute 
        $M.Bath_Exhaust_Fan_Timer += 1
        Run Program 'fan timer add' (Then Path)
 
Else
   - No Actions - (To add one, press 'Action')
 

 

fan timer run - [ID 006F][Parent 006C]

If
        $M.Bath_Exhaust_Fan_Timer > 0
 
Then
        $M.Bath_Exhaust_Fan_Timer -= 1
        Wait  1 minute 
        Run Program 'fan timer run' (If)
 
Else
        Set '2 / M.Bath / Fan' Off
 

 

Edited by uffy
Posted (edited)
1 hour ago, uffy said:

We have two switches in our bathroom.  One for lights one for exhaust fan. When the light is turned on, the fan turns on.  I would like to keep track of how long the light is on so that when the light is turned off, the fan stays on for the same amount of time the lights were on.

My thinking here is.  If someone takes a 15 minute shower then fan will stay on for 15 min after they turn the lights off.  If they spent 2 min in the bathroom, the fan will stay on for 2 min after the lights are shut off.

Is there a timer function that can keep track of time. or do I need make an integer and use waits in a then statement to increase variable value?

You'll need to create variables to create a timer function.

I think you're making this much more complicated than it has to be as well as mostly likely going overboard with the fan or not enough. 

It's your fan's cfm rating and room size that should determine how long the fan stays on vs the light itself being on.

The fan is on and moving air while your in there. Depending on how much air it moves, should determine the length of time it stays on afterwards. 

What I'm saying is that being in the bathroom for 5 minutes or 55 minutes is irrelevant once you exit. It's moving air while you're in there. Whatever is left once you leave will continue to be moved. Due to the room size, if your fan needs 10 minutes, running it an extra 45 minutes is a waste. Same thing with being in there for 5 minutes. Running it for an extra 5 when it needs 10 leaves you short. This is a simplistic view of things but I'm using to help you understand what I'm getting at. 

 

Edited by lilyoyo1
Posted
4 minutes ago, lilyoyo1 said:

You'll need to create variables to create a timer function.

I think you're making this much more complicated than it has to be as well as mostly likely going overboard with the fan or not enough. 

It's your fan's cfm rating and room size that should determine how long the fan stays on vs the light itself being on.

The fan is on and moving air while your in there. Depending on how much air it moves, should determine the length of time it stays on. 

What I'm saying is that being in the bathroom for 5 minutes or 55 minutes is irrelevant once you exit. It's moving air while you're in there. Whatever is left once you leave will continue to be moved. Due to the room size, if your fan needs 10 minutes, running it an extra 45 minutes is a waste. Same thing with being in their for 5 minutes. Running it for an extra 5 when it needs 10 leaves you short. This is a simplistic view of things but I'm using to help you understand what I'm getting at. 

 

I think you make a really good point.  I should probably just run it for a set time after the lights turn off an be done with it....or just cap the program at 10 minutes of runtime...

Either way, it was fun to write the program.

Posted

My setup consists of using humidity setting of 48% for winter and 45% for summer.  I use the aeotec multisensor for humidity.  I also have a maximum timer that starts after the light is shut off just so the fan doesn't shut off for some unknown reason.

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...