def handle_post(self, data): obj = json.loads(data) keys = obj.keys() json_response = "{" for key in keys: if key in Control.tri_states_actuators: value = obj.get(key) if value in Control.tri_states: setattr(self, "_Control__" + key, value) print key, getattr(self, "_Control__" + key) try: tri_state_relay_output(key, value) except: print "the relay don't have the actuator, please review" json_response += '''"%s" : "%s",''' % (key, value) else: print value, "tri illegal state" elif key in Control.bi_states_actuators: value = obj.get(key) if value in Control.bi_states: setattr(self, "_Control__" + key, value) print key, getattr(self, "_Control__" + key) try: bi_state_relay_output(key, value) except: print "the relay don't have the actuator, please review" json_response += '''"%s" : "%s", ''' % (key, value) else: print value, "illegal state" else: print key, "bi illegal actuator" json_response += '''"status" : "%s", ''' % "success" json_response += '''"update_time" : "%s"''' % get_current_time() json_response += "}" return json_response
def heating_control(Indoor, Parameter): # ok if Indoor.get_temperature() < Parameter.get_heating_start_lowest_temperature(): bi_state_relay_output("heating", "on") auto_heating = "on" elif Indoor.get_temperature() > Parameter.get_heating_stop_highest_temperature(): bi_state_relay_output("heating", "on") auto_heating = "off"
def fogging_control(Indoor, Parameter): if float(Indoor.get_temperature()) > float(Parameter.get_temperature_to_open_fogging()) + 1: bi_state_relay_output("fogging", "on") auto_fogging = "on" elif float(Indoor.get_temperature()) < float(Parameter.get_temperature_to_open_fogging()) - 1: bi_state_relay_output("fogging", "off") auto_fogging = "off"
def co2_control(Indoor, Parameter): global auto_co2 if Indoor.get_co2() < Parameter.get_co_2_lower_limit(): bi_state_relay_output("co2", "on") auto_co2 = "on" elif Indoor.get_co2() > Parameter.get_co_2_upper_limit(): bi_state_relay_output("co2", "off") auto_co2 = "off"
def cooling_pad_control(Indoor, Parameter): global auto_cooling_pad if float(Indoor.get_temperature()) > float(Parameter.get_temperature_to_open_cooling_pad()) + 1: bi_state_relay_output("cooling_pad", "on") auto_cooling_pad = "on" # self.control.set_cooling_pad("on") elif float(Indoor.get_temperature()) < float(Parameter.get_temperature_to_open_cooling_pad()) - 1: bi_state_relay_output("cooling_pad", "off") auto_cooling_pad = "off"
def fogging_control(Indoor,Parameter): if float(Indoor.get_temperature())>float(Parameter.get_temperature_to_open_fogging())+1: bi_state_relay_output("fogging", "on") auto_fogging="on" # Control.set_fogging("on") # if Control.get_thermal_screen()=="on" # Control.set_thermal_screen("off") elif float(Indoor.get_temperature())<float(Parameter.get_temperature_to_open_fogging())-1: bi_state_relay_output("fogging", "off") auto_fogging="off"
def lighting_control(Outdoor, Parameter): global t1, t2, t3, t4, t5, lighting_stop_time, lighting_stop_time2, lighting_stop_time3, lighting_open_time, lighting_open_time2 month = int(get_current_month()) hour = int(get_current_hour()) if auto_lighting_1 == "off" and auto_lighting_2 == "off": if month > Parameter.get_month_to_open_lighting( ) and month < Parameter.get_month_to_close_lighting(): if hour > Parameter.get_period_1_start_lighting( ) and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif hour > Parameter.get_period_2_start_lighting( ) and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = float(get_time() - lighting_open_time) t2 = float(get_time() - lighting_open_time2) if t1 > 30 and t1 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" if t2 > 30 and t2 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if hour > Parameter.get_period_1_start_lighting( ) and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif hour > Parameter.get_period_2_start_lighting( ) and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 30 and t3 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t4 > 30 and t4 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t5 > 30 and t5 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off"
def lighting_control(Outdoor, Parameter): global t1, t2, t3, t4, t5, lighting_stop_time, lighting_stop_time2, lighting_stop_time3, lighting_open_time, lighting_open_time2 global auto_lighting_1, auto_lighting_2 month = int(get_current_month()) hour = int(get_current_hour()) if auto_lighting_1 == "off" and auto_lighting_2 == "off": if month > Parameter.get_month_to_open_lighting() and month < Parameter.get_month_to_close_lighting(): if hour > Parameter.get_period_1_start_lighting() and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif hour > Parameter.get_period_2_start_lighting() and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = float(get_time() - lighting_open_time) t2 = float(get_time() - lighting_open_time2) if t1 > 30 and t1 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" if t2 > 30 and t2 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if hour > Parameter.get_period_1_start_lighting() and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif hour > Parameter.get_period_2_start_lighting() and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 30 and t3 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t4 > 30 and t4 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t5 > 30 and t5 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off"
def lighting_control(Control, Outdoor, Parameter): global lighting_stop_time, lighting_stop_time2, lighting_stop_time3 auto_lighting_1 = Control.get_lighting_1() auto_lighting_2 = Control.get_lighting_2() if auto_lighting_1 == "off" and auto_lighting_2 == "off": if get_current_month() > Parameter.get_month_to_open_lighting( ) and get_current_month() < Parameter.get_month_to_close_lighting(): if get_current_time() > Parameter.get_period_1_start_lighting( ) and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting( ) and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = int(get_time() - lighting_open_time) t2 = int(get_time() - lighting_open_time2) if t1 > 1750 and t1 < 1850: bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" # Control.set_lighting_2("on") if t2 > 1750 and t2 < 1850: # Control.set_lighting_2("on") bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if get_current_time() > Parameter.get_period_1_start_lighting( ) and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting( ) and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 1750 and t3 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t4 > 1750 and t4 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t5 > 1750 and t5 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") else: bi_state_relay_output("ligting_2", "off") bi_state_relay_output("ligting_1", "off")
def lighting_control(Control,Outdoor,Parameter): global lighting_stop_time,lighting_stop_time2,lighting_stop_time3 auto_lighting_1 = Control.get_lighting_1() auto_lighting_2 = Control.get_lighting_2() if auto_lighting_1=="off" and auto_lighting_2=="off": if get_current_month()>Parameter.get_month_to_open_lighting() and get_current_month()<Parameter.get_month_to_close_lighting(): if get_current_time()>Parameter.get_period_1_start_lighting() and get_current_time()<Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation()<Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_1", "on") auto_lighting_1="on" lighting_open_time=get_time() elif get_current_time()>Parameter.get_period_2_start_lighting() and get_current_time()<Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation()<Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_2", "on") auto_lighting_2="on" lighting_open_time2=get_time() elif auto_lighting_1=="on" and auto_lighting_2=="off": t1=int(get_time()-lighting_open_time) t2=int(get_time()-lighting_open_time2) if t1>1750 and t1<1850: bi_state_relay_output("ligting_2", "on") auto_lighting_2="on" # Control.set_lighting_2("on") if t2>1750 and t2<1850: # Control.set_lighting_2("on") bi_state_relay_output("ligting_2", "on") auto_lighting_2="on" elif auto_lighting_1=="on" and auto_lighting_2=="on": if get_current_time()>Parameter.get_period_1_start_lighting() and get_current_time()<Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation()>Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1="off" lighting_stop_time=get_time() elif get_current_time()>Parameter.get_period_2_start_lighting() and get_current_time()<Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation()>Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1="off" lighting_stop_time2=get_time() else: # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1="off" lighting_stop_time3=get_time() elif auto_lighting_1=="off" and auto_lighting_2=="on": t3=get_time()-lighting_stop_time3 t4=get_time()-lighting_stop_time2 t5=get_time()-lighting_stop_time if t3>1750 and t3<1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t4>1750 and t4<1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t5>1750 and t5<1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") else: bi_state_relay_output("ligting_2", "off") bi_state_relay_output("ligting_1", "off")