def __init__(self, sunrise_time, sunset_time, time_on, time_off):
     App.__init__(self, "Fake Activity")
     self.sunrise_time = sunrise_time
     self.sunset_time = sunset_time
     self.time_on = time_on
     self.time_off = time_off
     self.counter = time_off
    def update(self, sys):
        if self.sunrise_time <= sys.rounded_time <= self.sunset_time:
            App.app_print(
                "[Light Manager] [Indoor Lights] Lights on requested")
            act_list = []
            weight_list = []

            all_devs = sys.all_devs_of_type("Lights_")
            for dev in all_devs:
                act_list.append({"device": dev, "target": "on"})
                weight_list.append([
                    sys.devices[dev].get_resource_usage("on", None)["power"],
                    8, 10
                ])

            return act_list, weight_list, [], [], [], []
        else:
            App.app_print(
                "[Light Manager] [Indoor Lights] Lights off requested")

            act_list = []
            weight_list = []

            all_devs = sys.all_devs_of_type("Lights_")
            for dev in all_devs:
                act_list.append({"device": dev, "target": "off"})
                weight_list.append([0, 8, 0])

            return act_list, weight_list, [], [], [], []
 def update(self, sys):
     sens_vals = sys.all_sensors_of_type("Smoke Detector")
     for s in sens_vals:
         if sys.sensors[s].value:
             # requested_actions, weight_sets, mandatory_actions,
             # contradicting_action_pairs, dependent_action_pairs, alternative_actions
             App.app_print("[Fire Safety] [Doors] Doors opened requested")
             acts, weights, mandatory, _ = sys.all_action("Door_", "opened", [0, 0, 10], 0)
             return acts, weights, mandatory, [], [], []
     return [], [], [], [], [], []
    def off(sys):
        App.app_print("[Fake Activity] [Indoor Lights] Lights off requested")

        actions = []
        weights = []

        all_devs = sys.all_devs_of_type("Lights_")
        for dev in all_devs:
            actions.append({"device": dev, "target": "off"})
            weights.append([0, 0, 3])

        return actions, weights, [], [], [], []
 def update(self, sys):
     if sys.sensors["Power Rate"].get_value() <= self.charge_cutoff_rate:
         App.app_print(
             "[Battery Backup Management] [Battery Backup] Charging requested")
         # charge
         return [{"device": "Battery Backup", "target": "charging"}], [[sys.devices["Battery Backup"].get_resource_usage("charging", {})["charging_rate"], 300, 1]], [], [], [], []
     elif sys.sensors["Power Rate"].get_value() >= self.discharge_cutoff_rate:
         pwr_cons = sys.sensors["Power Meter"].get_value()
         sys.devices["Battery Backup"].variables["consumption"] = pwr_cons
         App.app_print(
             "[Battery Backup Management] [Battery Backup] Supplying requested")
         # discharge
         return [{"device": "Battery Backup", "target": "supplying"}], [[-pwr_cons, 300, 1]], [0], [], [], []
     return [], [], [], [], [], []
    def on(sys):
        App.app_print("[Fake Activity] [Indoor Lights] Lights on requested")

        actions = []
        weights = []

        all_devs = sys.all_devs_of_type("Lights_")
        for dev in all_devs:
            actions.append({"device": dev, "target": "on"})
            weights.append([
                sys.devices[dev].get_resource_usage("on", None)["power"], 0, 5
            ])

        return actions, weights, [], [], [], []
    def update(self, sys):
        if self.current_state == "on_pending" and sys.rounded_time >= self.on_time:
            # Request lights on or motion sensing
            self.current_state = "off_pending"
            # requested_actions, weight_sets, mandatory_actions,
            # contradicting_action_pairs, dependent_action_pairs, alternative_actions

            req_actions = []
            weights = []
            alt_actions = []

            App.app_print(
                "[Intruder Prevention] [Outdoor Lights] Lights on requested")
            App.app_print(
                "[Intruder Prevention] [Outdoor Lights] Motion sensor requested"
            )
            for i in range(5):  # 5 brightness levels
                req_actions.append({
                    "device": "Outdoor Lights",
                    "target": "on_%d" % (i)
                })
                weights.append([
                    sys.devices["Outdoor Lights"].get_resource_usage(
                        "on", {"level": i})["power"], 0, 4 + i
                ])

                req_actions.append({
                    "device": "Outdoor Lights",
                    "target": "motionsensor_%d" % (i)
                })
                weights.append([
                    sys.devices["Outdoor Lights"].get_resource_usage(
                        "motionsensor", {"level": i})["power"], 0, 1 + i
                ])

                alt_actions.append(i * 2 + 0)
                alt_actions.append(i * 2 + 1)

            return req_actions, weights, [], [], [], [alt_actions]
        elif self.current_state == "off_pending" and sys.rounded_time >= self.off_time:
            # Request lights off
            self.current_state = "on_pending"
            App.app_print(
                "[Intruder Prevention] [Outdoor Lights] Lights off requested")
            # requested_actions, weight_sets, mandatory_actions,
            # contradicting_action_pairs, dependent_action_pairs, alternative_actions
            return [{
                "device": "Outdoor Lights",
                "target": "off"
            }], [[0, 0, 9]], [], [], [], []
        return [], [], [], [], [], []
Esempio n. 8
0
 def __init__(self, sleep_time, wake_time):
     App.__init__(self, "Sleep Cycle Manager")
     self.sleep_time = sleep_time
     self.wake_time = wake_time
     self.transition_time = 5
Esempio n. 9
0
    def update(self, sys):
        if self.current_state == "wake_pending" and sys.rounded_time >= self.wake_time:
            # Transition to wake mode
            self.current_state = "wake_processing"
            self.transition_counter = 0

        elif self.current_state == "wake_processing":
            # Set system to sleep pending
            self.transition_counter += 1
            # Slowly raise blinds
            if self.transition_counter == 50:
                self.current_state = "sleep_pending"

            App.app_print("[Sleep Cycle Manager] [Blinds] Blinds raised requested")

            actions = []
            weights = []

            all_devs = sys.all_devs_of_type("Blinds_")
            for dev in all_devs:
                actions.append(
                    {"device": dev, "target": "raised_%d" % (self.transition_counter / 10)})
                weights.append([0, self.transition_counter / 10, 0])

            all_devs = sys.all_devs_of_type("Lights_")
            for dev in all_devs:
                actions.append({"device": dev, "target": "on"})
                weights.append([sys.devices[dev].get_resource_usage("on", None)[
                               "power"], self.transition_counter / 10, 0])

            all_devs = sys.all_devs_of_type("Windows_")
            for dev in all_devs:
                actions.append({"device": dev, "target": "open"})
                weights.append([0, self.transition_counter / 10, 0])

            return actions, weights, [], [], [], []

        elif self.current_state == "sleep_pending" and sys.rounded_time >= self.sleep_time:
            # Transition to sleep mode
            self.current_state = "sleep_processing"
            self.transition_counter = 0

        elif self.current_state == "sleep_processing":
            # Set system to wake pending
            self.transition_counter += 1
            # Slowly lower blinds
            if self.transition_counter == 50:
                self.current_state = "sleep_pending"

            App.app_print("[Sleep Cycle Manager] [Blinds] Blinds lowered requested")
            actions = [{"device": "Blinds", "target": "lowered_%d" % (self.transition_counter / 10)},
                       {"device": "Indoor Lights", "target": "off"},
                       {"device": "Windows", "target": "closed"}]
            weights = [[0, self.transition_counter / 10, 2],
                       [0, self.transition_counter / 10, 2],
                       [0, self.transition_counter / 10, 2]]

            actions = []
            weights = []

            all_devs = sys.all_devs_of_type("Blinds_")
            for dev in all_devs:
                actions.append(
                    {"device": dev, "target": "lowered_%d" % (self.transition_counter / 10)})
                weights.append([0, self.transition_counter / 10, 0])
                
            all_devs = sys.all_devs_of_type("Lights_")
            for dev in all_devs:
                actions.append({"device": dev, "target": "off"})
                weights.append([0, self.transition_counter / 10, 0])
                
            all_devs = sys.all_devs_of_type("Windows_")
            for dev in all_devs:
                actions.append({"device": dev, "target": "closed"})
                weights.append([0, self.transition_counter / 10, 0])

            return actions, weights, [], [], [], []

        return [], [], [], [], [], []
 def __init__(self, charge_cutoff_rate, discharge_cutoff_rate):
     self.charge_cutoff_rate = charge_cutoff_rate
     self.discharge_cutoff_rate = discharge_cutoff_rate
     App.__init__(self, "Battery Backup Management")
 def __init__(self):
     App.__init__(self, "HVAC Power Control")
 def __init__(self, on_time, off_time):
     App.__init__(self, "Intruder Prevention")
     self.on_time = on_time
     self.off_time = off_time
 def __init__(self, sunrise_time, sunset_time):
     App.__init__(self, "Light Manager")
     self.sunrise_time = sunrise_time
     self.sunset_time = sunset_time
Esempio n. 14
0
    def update(self, sys):
        room_name = sys.sensors["User Locator"].get_value()
        # Turn A/C off if the resident is not home.
        if room_name.startswith("outside_"):
            App.app_print("[HVAC Location Control] [HVAC] Off requested")

            act_list, weight_list, _, _ = sys.all_action(
                "HVAC", "off", [0, 0, 0], 0)
            return act_list, weight_list, [], [], [], []

        # Compute distance vs target temperature time to determine target heating/cooling rate
        hvac_props_h = \
            [sys.devices["HVAC_%s" % (room_name)].get_resource_usage("heating", {"rate": x + 1}) for x in range(4)]
        hvac_props_c = \
            [sys.devices["HVAC_%s" % (room_name)].get_resource_usage("cooling", {"rate": x + 1}) for x in range(4)]

        actions = []
        weights = []
        alt_actions = []

        target_temp = sys.target_temperature_present

        cur_temp = sys.sensors["Thermometer_%s" % room_name].get_value()

        if cur_temp > target_temp:
            # Cooling
            hvac_tot = [
                -1 * (cur_temp - target_temp) /
                hvac_props_c[x]["temperature_delta"] for x in range(4)
            ]

            App.app_print("[HVAC Location Control] [HVAC] Cooling requested")
            # Adjust penalties based on time difference till target temperature
            for i in range(4):
                actions.append({
                    "device": "HVAC_%s" % (room_name),
                    "target": "cooling_%d" % (i + 1)
                })
                weights.append([
                    hvac_props_c[i]["power"], 5 - abs(hvac_tot[i] / 30 * 3), 0
                ])
                alt_actions.append(i)
            return actions, weights, [], [], [], [alt_actions]

        elif cur_temp < target_temp:
            # Heating
            hvac_tot = [
                (target_temp - cur_temp) / hvac_props_h[x]["temperature_delta"]
                for x in range(4)
            ]

            App.app_print("[HVAC Location Control] [HVAC] Heating requested")
            # Adjust penalties based on time difference till target temperature
            for i in range(4):
                actions.append({
                    "device": "HVAC_%s" % (room_name),
                    "target": "heating_%d" % (i + 1)
                })
                weights.append([
                    hvac_props_h[i]["power"], 5 - abs(hvac_tot[i] / 30 * 3), 0
                ])
                alt_actions.append(i)
            return actions, weights, [], [], [], [alt_actions]

        return [], [], [], [], [], []
Esempio n. 15
0
 def __init__(self):
     App.__init__(self, "HVAC Location Control")
Esempio n. 16
0
 def __init__(self):
     App.__init__(self, "Fire Safety")