Ejemplo n.º 1
0
    def __init__(self):
        self.bw_client = Client()
        self.bw_client.setEntityFromEnviron()
        self.bw_client.overrideAutoChainTo(True)
        self.hod_client = HodClient("xbos/hod", self.bw_client)
        self.priority = {
            "fan": 1,
            "kettle": 2,
            "student_office_tstat": 3,
            "microwave": 4,
            "sra_office_tstat": 5,
            "space_heater": 5,
            "fridge": 6,
            "evse": 7,
            "michaels_office_tstat": 8
        }

        meter_q = """
            SELECT ?uri FROM rfs WHERE {
            ?m rdf:type brick:Building_Electric_Meter .
  	         ?m bf:uri ?uri .
             };
        """
        self.building_meter = Meter(
            self.bw_client,
            self.hod_client.do_query(meter_q)['Rows'][0]['?uri'])
        self.tstats = {
            "student_office_tstat":
            Thermostat(
                self.bw_client,
                "rfs/devices/s.pelican/Student_Office/i.xbos.thermostat"),
            "sra_office_tstat":
            Thermostat(self.bw_client,
                       "rfs/devices/s.pelican/SRA_Office/i.xbos.thermostat"),
            "michaels_office_tstat":
            Thermostat(
                self.bw_client,
                "rfs/devices/s.pelican/Michaels_Office/i.xbos.thermostat")
        }

        self.plugloads = {
            "fan":
            Plug(self.bw_client, "rfs/devices/fan/s.tplink.v0/0/i.xbos.plug"),
            "fridge":
            Plug(self.bw_client,
                 "rfs/devices/refrigerator/s.tplink.v0/0/i.xbos.plug"),
            "space_heater":
            Plug(self.bw_client,
                 "rfs/devices/heater/s.tplink.v0/0/i.xbos.plug"),
            "kettle":
            Plug(self.bw_client,
                 "rfs/devices/boiler/s.tplink.v0/0/i.xbos.plug"),
            "microwave":
            Plug(self.bw_client,
                 "rfs/devices/microwave/s.tplink.v0/0/i.xbos.plug")
        }
        self.evse = EVSE(self.bw_client,
                         "rfs/devices/s.aerovironment/ParkingLot/i.xbos.evse")
        self.evse.set_current_limit(_MAX_EVSE_CURRENT)
Ejemplo n.º 2
0
def get_thermostats(client, hod, building):
    """Gets the thermostats for given building.
    :param client: xbos client object
    :param hod: hod client object
    :param building: (string) building name
    :return {zone: tstat object}"""

    query = """SELECT ?uri ?zone FROM %s WHERE {
        ?tstat rdf:type/rdfs:subClassOf* brick:Thermostat .
        ?tstat bf:uri ?uri .
        ?tstat bf:controls/bf:feeds ?zone .
        };"""

    # Start of FIX for missing Brick query
    query = """SELECT ?zone ?uri FROM  %s WHERE {
              ?tstat rdf:type brick:Thermostat .
              ?tstat bf:controls ?RTU .
              ?RTU rdf:type brick:RTU .
              ?RTU bf:feeds ?zone. 
              ?zone rdf:type brick:HVAC_Zone .
              ?tstat bf:uri ?uri.
              };"""
    # End of FIX - delete when Brick is fixed
    building_query = query % building

    tstat_query_data = hod.do_query(building_query)['Rows']
    tstats = {tstat["?zone"]: Thermostat(client, tstat["?uri"]) for tstat in tstat_query_data}
    return tstats
Ejemplo n.º 3
0
Archivo: server.py Proyecto: kuzha/XBOS
def get_all_thermostats(client, hod, building):
    """Gets the thermostats for given building.
    :param client: xbos client object
    :param hod: hod client object
    :param building: (string) building name
    :return {zone: tstat object}"""

    query = """SELECT ?uri ?zone FROM %s WHERE {
        ?tstat rdf:type/rdfs:subClassOf* brick:Thermostat .
        ?tstat bf:uri ?uri .
        ?tstat bf:controls/bf:feeds ?zone .
        };"""

    building_query = query % building

    tstat_query_data = hod.do_query(building_query)['Rows']
    tstats = {}
    for tstat in tstat_query_data:
        k = tstat["?zone"].lower()
        if building in BRICK_XSG_MISMATCH:
            if k in BRICK_XSG_MISMATCH[building]:
                k = BRICK_XSG_MISMATCH[building][k]
        try:
            tstats[k] = Thermostat(client, tstat["?uri"])
        except Exception:
            tb = traceback.format_exc()
            logging.error("failed to get thermostat for bldg:%s, zone:%s\n%s",
                          building, k, tb)

    return tstats
Ejemplo n.º 4
0
 def getTstats(self):
     hod_client = HodClient("xbos/hod", self.client)
     thermostat_query_data = hod_client.do_query(self.thermostat_query %
                                                 self.building)["Rows"]
     return {
         tstat["?zone"]: Thermostat(client, tstat["?uri"])
         for tstat in thermostat_query_data
     }
Ejemplo n.º 5
0
    client = get_client(agent='172.17.0.1:28589', entity="thanos.ent")
else:
    client = get_client()
hc = HodClientHTTP("http://ciee.cal-sdb.org")

q = """SELECT ?uri ?zone WHERE {
	?tstat rdf:type/rdfs:subClassOf* brick:Thermostat .
	?tstat bf:uri ?uri .
	?tstat bf:controls/bf:feeds ?zone .
};
"""

zones = {}
for tstat in hc.do_query(q):
    print tstat
    zones[tstat["?zone"]] = Thermostat(client, tstat["?uri"])

normal_zones = [cfg['zone']]

filename = "thermostat_changes.txt"  # file in which the thermostat changes are recorded


def workday():
    p = {
        "override": True,
        "heating_setpoint": 70.,
        "cooling_setpoint": 76.,
        "mode": 3
    }
    print "workday", datetime.datetime.now()
    #for z in normal_zones:
Ejemplo n.º 6
0
    # set new heating setpoint
    print "Setting new fan_mode to:", new_fanmode
    tstat.set_fan_mode(new_fanmode)

    # wait for update
    time.sleep(15)

    # check if it changed
    if tstat.fan_mode == old_fanmode:
        print "BAD FAN MODE", tstat.fan_mode

    # reset to old value
    print "Setting fan mode back to:", old_fanmode
    tstat.set_fan_mode(old_fanmode)

    print "===Fan test passes.==="


if __name__ == '__main__':
    URIs = ["scratch.ns/demo/s.imt550c/410soda/i.xbos.thermostat"]
    c = get_client()

    for uri in URIs:
        tstat = Thermostat(c, uri)

        heating(tstat)
        cooling(tstat)
        override(tstat)
        mode(tstat)
        fan(tstat)
Ejemplo n.º 7
0
?equipment rdf:type/rdfs:subClassOf* brick:Thermostat .
?equipment bf:uri ?uri .
}"""

results = hod.do_query(lighting_query)
lights = []
if results["Count"] > 0:
    for row in results["Rows"]:
        l = Light(c, row["?uri"])
        lights.append(l)

results = hod.do_query(tstat_query)
tstats = []
if results["Count"] > 0:
    for row in results["Rows"]:
        t = Thermostat(c, row["?uri"])
        tstats.append(t)


#### Light Strategy: dim to 25%
def light_strategy(self):
    self.old_brightness = self.brightness
    new_brightness = 25
    self.write({state: self.state, 'brightness': new_brightness})


def light_reset(self):
    self.write({state: self.state, 'brightness': self.old_brightness})


#### Thermostat Strategy: widen deadband by 8 degrees
Ejemplo n.º 8
0
        };""" % cfg["Building"]

    # Start of FIX for missing Brick query
    thermostat_query = """SELECT ?zone ?uri FROM  %s WHERE {
              ?tstat rdf:type brick:Thermostat .
              ?tstat bf:controls ?RTU .
              ?RTU rdf:type brick:RTU .
              ?RTU bf:feeds ?zone. 
              ?zone rdf:type brick:HVAC_Zone .
              ?tstat bf:uri ?uri.
              };"""
    q = thermostat_query % cfg["Building"]
    # End of FIX - delete when Brick is fixed

    threads = []
    tstat_query_data = hc.do_query(q)['Rows']
    print(tstat_query_data)
    tstats = {
        tstat["?zone"]: Thermostat(client, tstat["?uri"])
        for tstat in tstat_query_data
    }

    for zone, tstat in tstats.items():
        thread = ZoneThread(yaml_filename, tstats, zone, client,
                            zone_thermal_models[zone])
        thread.start()
        threads.append(thread)

    for t in threads:
        t.join()
Ejemplo n.º 9
0
# a Thermostat object in order to control it.
query = """
SELECT ?thermostat ?zone ?uri ?meter_uri WHERE {
    ?thermostat rdf:type/rdfs:subClassOf* brick:Thermostat .
    ?zone rdf:type brick:HVAC_Zone .
    ?meter rdf:type/rdfs:subClassOf* brick:Electric_Meter .

    ?thermostat bf:controls/bf:feeds+ ?zone .
    ?thermostat bf:uri ?uri .
    ?thermostat bf:controls/bf:hasPoint ?meter .
    ?meter bf:uri ?meter_uri .
};"""
for row in hod.do_query(query)["Rows"]:
    zone = row["?zone"]
    uri = row["?uri"]
    zone2tstat[zone] = Thermostat(c, uri)
    zone2meter[zone] = row["?meter_uri"]


def get_thermostat_meter_data(zone):
    """
    This method subscribes to the output of the meter for the given zone.
    It returns a handler to call when you want to stop subscribing data, which
    returns a list of the data readins over that time period
    """
    meter_uri = zone2meter.get(zone, "None")
    data = []

    def cb(msg):
        for po in msg.payload_objects:
            if po.type_dotted == (2, 0, 9, 1):
Ejemplo n.º 10
0
    from xbos.devices.thermostat import Thermostat

    hc = HodClient("xbos/hod", c)

    q = """SELECT ?uri ?zone FROM %s WHERE {
				?tstat rdf:type/rdfs:subClassOf* brick:Thermostat .
				?tstat bf:uri ?uri .
				?tstat bf:controls/bf:feeds ?zone .
				};""" % cfg["Building"]
    import pickle

    with open("../Thermal Data/ciee_thermal_data_demo", "r") as f:
        thermal_data = pickle.load(f)
    dm = DataManager(cfg, advise_cfg, c, ZONE)
    tstat_query_data = hc.do_query(q)['Rows']
    tstats = {tstat["?zone"]: Thermostat(c, tstat["?uri"]) for tstat in tstat_query_data}

    # TODO INTERVAL SHOULD NOT BE IN config_file.yml, THERE SHOULD BE A DIFFERENT INTERVAL FOR EACH ZONE
    from ThermalModel import *

    thermal_model = MPCThermalModel(thermal_data, interval_length=cfg["Interval_Length"])
    thermal_model.setZoneTemperaturesAndFit(
        {dict_zone: dict_tstat.temperature for dict_zone, dict_tstat in tstats.items()}, dt=cfg["Interval_Length"])
    thermal_model.setWeahterPredictions(dm.weather_fetch())

    adv = Advise(["HVAC_Zone_Centralzone"],
                 datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(
                     tz=pytz.timezone("America/Los_Angeles")),
                 dm.preprocess_occ(),
                 [80],  # [{dict_zone: dict_tstat.temperature for dict_zone, dict_tstat in tstats.items()}[ZONE]],
                 thermal_model,
Ejemplo n.º 11
0
    with open("config_file.yml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile)

    from xbos import get_client
    from xbos.services.hod import HodClient

    if cfg["Server"]:
        client = get_client(agent=cfg["Agent_IP"], entity=cfg["Entity_File"])
    else:
        client = get_client()

    hc = HodClient("xbos/hod", client)

    q = """SELECT ?uri ?zone FROM %s WHERE {
			?tstat rdf:type/rdfs:subClassOf* brick:Thermostat .
			?tstat bf:uri ?uri .
			?tstat bf:controls/bf:feeds ?zone .
			};""" % cfg["Building"]

    from xbos.devices.thermostat import Thermostat

    for tstat in hc.do_query(q)['Rows']:
        print tstat
        with open(
                "Buildings/" + cfg["Building"] + "/ZoneConfigs/" +
                tstat["?zone"] + ".yml", 'r') as ymlfile:
            advise_cfg = yaml.load(ymlfile)
        NS = NormalSchedule(cfg, Thermostat(client, tstat["?uri"]), advise_cfg)
        NS.normal_schedule()
Ejemplo n.º 12
0
    "south-berkeley-senior-center"
]

# Getting clients
client = get_client()
hc = HodClient("xbos/hod", client)

for BUILDING in buildings:
    print("================================================")
    print("")
    print("Working on building", BUILDING)
    print("")

    query_data = hc.do_query(thermostat_query % BUILDING)["Rows"]

    tstats = {d["?zone"]: Thermostat(client, d["?uri"]) for d in query_data}

    ##### RUN
    for zone, tstat in tstats.items():
        writeTstat(tstat, PROGRAMMABLE)

    # wait to let the setpoints get through
    # time.sleep(2)
    # Printing the data for every tstat
    for zone, tstat in tstats.items():
        print("")
        print("Checking zone:", zone)
        print("Checking zone uri:", tstat._uri)
        printTstat(tstat)
        print("Done checking zone", zone)
        print("")