Translate

Sunday 6 April 2014

Room Management System – Part 3 of Switching some lights while on vacation


Today we will be taking care of a simple way to activate or deactivate time settings in the variable declaration part. And add photocell checking to our switch commands so we don't need to reprogram the timers every time the season changes. We just leave the time frame set for the days with the least day light time and run the switching command through a photocell reading so in summer the lights don't switch on before it is getting dark. Now it has to be dark and within the time frame to switch the lights.

Lets start with activating and deactivating single time settings. Again we start at the declaration part of our sketch and find the following lines where we add:

//////////////////////holiday timer settings//////////////////////

////////////Room 1 (Bed 1) ///////////

//>>>>>>>>>>addition starts here<<<<<<<<<<<<<<<<<<<<<<<<<
byte room1MActive = 1;                       //Set to 1 if you want to process
                                                             //Timer will be ignored when set to 0
//>>>>>>>>>>addition ends here<<<<<<<<<<<<<<<<<<<<<<<<<<<

unsigned int room1OnM[2] = {5, 35};  //Time to switch on the lights 5
unsigned int room1OffM[2] = {6, 5};    //Time to switch off the lights 6

//>>>>>>>>>>addition starts here<<<<<<<<<<<<<<<<<<<<<<<<<<
byte room1O1Active = 1;                      //Set to 1 if you want to process
                                                             //Timer will be ignored when set to 0
//>>>>>>>>>>addition ends here<<<<<<<<<<<<<<<<<<<<<<<<<<<

unsigned int room1On1[2] = {19, 35};  //Time to switch on the lights
unsigned int room1Off1[2] = {20, 15};  //Time to switch off the lights

//>>>>>>>>>>addition starts here<<<<<<<<<<<<<<<<<<<<<<<<<<<
byte room102Active = 1;                       //Set to 1 if you want to process
                                                              //Timer will be ignored when set to 0
//>>>>>>>>>>addition ends here<<<<<<<<<<<<<<<<<<<<<<<<<<<<
unsigned int room1On2[2] = {21, 5};     //Time to switch on the lights
unsigned int room1Off2[2] = {21, 15};   //Time to switch off the lights

////////////Room 2 (Bed 2) ///////////
unsigned int room2OnM[2] = {6, 30};    //Time to switch on the lights
unsigned int room2OffM[2] = {6, 50};    //Time to switch off the lights

We declare a variable for each timer setting like “room1MActive” for the morning switching time, “room1O1Active” for the first evening switching time of room 1, “ room1O2Active” for the second evening switching time of room 1 and set it to 1 if we want the time to be processed and to 0 if we want it to be ignored. This we do for every timer setting in each room and than we move down to the main loop again and find “////processing the input////” and “//////holiday switching/////”. There we add:

//////////////////processing the input/////////////////////
//////////////Holiday lighting/////////////////////////
if(switchState[20] == 1) {          //check if the holiday switch
                                                 //is activated
tmElements_t tm;                       //initializing RTC
if(RTC.read(tm)) {                     //Reading the clock
currentHour = tm.Hour;             //passing the time into a var
currentMinute = tm.Minute;       //passing the time into a var
}

///////Room 1 (Bed 1) /////////////
if(room1MActive == 1 && currentHour >= room1OnM[0] &&
currentHour <= (room1OffM[0] + 1)){               //checking if we came passed
                                                                          //the hour where the lights
                                                                          //to be switched on
                                                                          //checking the times
room1Lights = checkOnTime(room1OnM[0], room1OnM[1],
room1OffM[0], room1OffM[1]);
}
if(room1O1Active == 1 && currentHour >= room1On1[0] &&
currentHour <= (room1Off1[0] +1)){                  //checking if we came passed
                                                                           //the hour where the lights
                                                                           //to be switched on
                                                                           //checking the times
room1Lights = checkOnTime(room1On1[0], room1On1[1],
room1Off1[0], room1Off1[1]);
}
if(room102Active == 1 && currentHour >= room1On2[0] &&
currentHour <= (room1Off2[0] + 1)){                //checking if we came passed
                                                                          //the hour where the lights
                                                                          //to be switched on
                                                                          //checking the times
room1Lights = checkOnTime(room1On2[0], room1On2[1],
room1Off2[0], room1Off2[1]);
}
if(room1Lights == 1){                                        //if with in the on time
lightOutput[0] =1;                                              //switch on the lights
}
else {
lightOutput[0] = 0;                                           //other keep them off
}
////////Room 2 (Bed 2)//////////////

Here we add to the if-statements where we check if we are within the time frame to activate the timer.
if(currentHour >= room1OnM[0] &&
currentHour <= (room1OffM[0] + 1)){                      //checking if we came passed
                                                                                 //the hour where the lights
                                                                                 //to be switched on

Right in the beginning of the if-statement we add “room1MActive == 1 &&”. Now the statement is also checking if the “active” variable is set to 1 and the complete statement looks like this:

if(room1MActive == 1 && currentHour >= room1OnM[0] &&
currentHour <= (room1OffM[0] + 1)){                           //checking if we came passed

We do the same thing with every timer all the way down to room 9.

I know, quite a bit a typing, but it makes the unit a little more flexible. If you want to use the same unit in a different house or flat where you don't have windows in the bathroom or in the kitchen for example, than there is no point in switching on the lights when nobody can see it. Instead of going through the whole sketch and start commenting things out or deleting parts, you just need to change the “active status” in the declaration part from 1 to 0 and you are done.

On this part I was planing to implement the photocell reading to limit the time where the lights are switched to times when they are needed to be on. Getting the readings of a photocell right on a desk with artificial light is quite easy but running the experiment in the garden with light levels constantly changing is a bit of a challenge I found. Got to say, I've learned quite a bit experimenting the last couple of days. Share all my experiments, findings and thoughts, I decided to do all this in the next post.

No comments:

Post a Comment