Skip to content

Home Automation

Jurgen edited this page Dec 13, 2016 · 6 revisions
# Pseudo Logic

time_of_day = home.datetime.timeofday; 
// LIGHT     = home.datetime.Within(SUNRISE, SUNSET)
// DARK      = !LIGHT
// BREAKFAST =  7:00 -  9:30
// MORNING   =  6:00 - 12:00
// NOON      = 12:00 - 13:00
// LUNCH     = 11:45 - 12:45
// AFTERNOON = 13:00 - 18:00
// DINNER    = 18:00 - 20:00
// NIGHT     = 20:00 -  6:00
// SLEEPING  = 22:00 -  6:00
// EVENING   = (DARK.start - 0:30) - SLEEPING.start

family = presence state of family members
mumdad = presence state of mum and dad

IF (family == ABSENT) {
   // Do nothing for now

} else IF (family == LEAVING) {
   home.Lights.TurnAllOffIn(30_seconds);
   home.Switches.TurnAllOffIn(30_seconds);
} else IF (family == ARRIVING) {
   home.Lights.TurnOnIn(10_seconds, "Kitchen");
   home.Lights.TurnOnIn(10_seconds, "Living Room");
   home.Switches.TurnOnIn(10_seconds, "Christmas Tree");
} else IF (family == PRESENT) {
   IF (time_of_day == LUNCH) {
      home.Lights.TurnOnIn(10_seconds, "Kitchen");
   }
} else IF (time_of_day == EVENING) {
   IF (mumdad == PRESENT) {
      IF (home.Lights.IsOff("Kitchen") && home.Lights.IsOff("Living Room") && home.Lights.IsOff("Bed Room")) {
         home.Lights.TurnOffIn(10_seconds, "Christmas Tree");
         home.Lights.TurnOnIn(10_seconds, "Bedroom");
      }
   }
} else IF (time_of_day == MORNING) {
   IF (mumdad == ARRIVING) {
      IF (home.Lights.IsOff("Kitchen") && home.Lights.IsOff("Living Room")) {
         home.Lights.TurnOnIn(10_seconds, "Christmas Tree");
         home.Lights.TurnOnIn(10_seconds, "Kitchen");
         home.Lights.TurnOnIn(10_seconds, "Living Room");
      }
   } else IF (time_of_day != BREAKFAST) {
         home.Lights.TurnOffIn(10_seconds, "Kitchen");
         home.Lights.TurnOffIn(10_seconds, "Living Room");
   }
}
Clone this wiki locally