Jump to content

Programming how to make a timer?


ThisIsTheWay

Recommended Posts

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
 

 

Link to comment
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. 

 

Link to comment
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.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...