def RF_on(set_dic, switch_log): script = 'RF_on.py' msg = ("") msg += (" #############################################\n") msg += (" ## Turning the RF - ON ##\n") from rpi_rf import RFDevice if 'gpio_RF' in set_dic: if not str(set_dic['gpio_RF']).strip() == '': gpio_pin = int(set_dic['gpio_RF']) else: print(" - RF gpio pin not set") else: msg += (" !! NO RF SET !!\n") msg += (" !! run config program or edit config.txt !!\n") msg += (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") pigrow_defs.write_log(script, 'Failed - due to none set in config', switch_log) return msg rfdevice = RFDevice(gpio_pin) rfdevice.enable_tx() rfdevice.tx_code(15465751, 1, 432) rfdevice.tx_repeat = 5 msg += (" ## using GPIO " + str(gpio_pin) + " ##\n") msg += (" #############################################\n") pigrow_defs.set_condition(condition_name="RF", trig_direction="on", cooldown="none") pigrow_defs.write_log(script, 'RF turned on', switch_log) return msg
def humid_off(set_dic, switch_log): script = 'humid_off.py' msg = ("\n") msg += (" #############################################\n") msg += (" ## Turning the Humidifier - OFF ##\n") if 'gpio_humid' in set_dic and not str( set_dic['gpio_humid']).strip() == '': gpio_pin = int(set_dic['gpio_humid']) gpio_pin_on = set_dic['gpio_humid_on'] import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(gpio_pin, GPIO.OUT) if gpio_pin_on == "low": GPIO.output(gpio_pin, GPIO.HIGH) gpio_pin_dir = 'high' elif gpio_pin_on == "high": gpio_pin_dir = 'low' GPIO.output(gpio_pin, GPIO.LOW) else: msg += (" !! CAN'T DETERMINE GPIO DIRECTION !!\n") msg += (" !! run config program or edit config.txt !!\n") msg += (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") pigrow_defs.write_log(script, 'Failed - no direction set in config', switch_log) return msg else: msg += (" !! NO humid SET !!\n") msg += (" !! run config program or edit config.txt !!\n") msg += (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") pigrow_defs.write_log(script, 'Failed - due to none set in config', switch_log) return msg msg += (" ## by switching GPIO " + str(gpio_pin) + " to " + gpio_pin_dir + " ##\n") msg += (" #############################################\n") pigrow_defs.set_condition(condition_name="humid", trig_direction="off", cooldown="none") pigrow_defs.write_log(script, 'humidifer turned off', switch_log) return msg
def fans_on(set_dic, switch_log): script = 'fans_on.py' msg = ("") msg += (" #############################################\n") msg += (" ## Turning the Fans - ON ##\n") if 'gpio_fans' in set_dic and not str(set_dic['gpio_fans']).strip() == '': gpio_pin = int(set_dic['gpio_fans']) gpio_pin_on = set_dic['gpio_fans_on'] import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(gpio_pin, GPIO.OUT) if gpio_pin_on == "low": GPIO.output(gpio_pin, GPIO.LOW) elif gpio_pin_on == "high": GPIO.output(gpio_pin, GPIO.HIGH) else: msg += (" !! CAN'T DETERMINE GPIO DIRECTION !!\n") msg += (" !! run config program or edit config.txt !!\n") msg += (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") pigrow_defs.write_log(script, 'Failed - no direction set in config', switch_log) return msg else: msg += (" !! NO fans SET !!\n") msg += (" !! run config program or edit config.txt !!\n") msg += (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n") pigrow_defs.write_log(script, 'Failed - due to none set in config', switch_log) return msg msg += (" ## by switching GPIO " + str(gpio_pin) + " to " + gpio_pin_on + " ##\n") msg += (" #############################################\n") pigrow_defs.set_condition(condition_name="fans", trig_direction="on", cooldown="none") pigrow_defs.write_log(script, 'fans turned on', switch_log) return msg
elif argu == '-flags': print("name=") print("set=on,off,pause") print('cooldown=') sys.exit() if "=" in argu: key = str(argu).split('=')[0] value = str(argu).split('=')[1] if key == 'set': set_direct = value elif key == 'name': trigger_name = value elif key == "cooldown": cooldown = value # Check name was supplied if trigger_name == None: print("No trigger name supplied, use --help for more informaiton.") sys.exit() if set_direct == None: print( "It was not specified what to set the condition to, use set=on,off,pause" ) print(" or use --help for more information.") sys.exit() #set the condition pigrow_defs.set_condition(condition_name=trigger_name, trig_direction=set_direct, cooldown=cooldown)
def check_value(log_path): split_chr = ">" second_split_chr = "=" value_side = 1 date_text = "time" # Check the conditions for this log # read log log_name = os.path.split(log_path)[1] print_limit(" - log changed - " + log_path, 1) if log_name in config_data.logs_to_check: with open(log_path, 'rb') as f: f.seek(-2, os.SEEK_END) while f.read(1) != b'\n': f.seek(-2, os.SEEK_CUR) last_line = f.readline().decode() # create list of trigger conditions # this should be outside the loop conditions = [] for item in config_data.trigger_conditions: #print_limit(item) if item[0] == log_name: conditions.append([ item[1], item[2], item[3], item[4], item[5], item[6], item[7] ]) if split_chr in last_line: line_items = last_line.split(split_chr) line_date = None line_value = None # find the datetime the last log was written # current this is not used for anything.... for item in line_items: if second_split_chr in item: if date_text in item: line_date = item.split(second_split_chr)[value_side] # check each trigger assocaiated wit this log for condition in conditions: val_label = condition[0] trigger = condition[1] value = condition[2] condition_name = condition[3] trig_direction = condition[4] trig_cooldown = condition[5] cmd = condition[6] # check trigger state if check_condition(condition_name, trig_direction) == True: # find the selected value in the log for item in line_items: if second_split_chr in item: if val_label in item: line_value = item.split( second_split_chr)[value_side].strip() # perform logic to see if value causes a trigger condition if not line_date == None or not line_value == None: # Above if trigger == "above": if float(value) < float(line_value): print_limit( " Vakue " + line_value + " larger than trigger value of " + str(value) + " running " + cmd, 1) os.system(cmd + " &") pigrow_defs.set_condition( condition_name, trig_direction, trig_cooldown) else: print_limit( " - trigger value conditions not met, no action", 2) # Below elif trigger == "below": if float(value) > float(line_value): print_limit( " Value " + line_value + " smaller than trigger value of " + str(value) + " running " + cmd, 1) os.system(cmd + " &") pigrow_defs.set_condition( condition_name, trig_direction, trig_cooldown) else: print_limit( " - trigger value conditions not met, no action", 2) # Window # Trigger inside a window elif trigger == "window": if ":" in value: val_min, val_max = value.split(":") if float(line_value) > float( val_min) and float(line_value) < float( val_max): print_limit( "Value greater than " + val_min + " and less than " + val_max + ", running " + cmd, 1) os.system(cmd + " &") pigrow_defs.set_condition( condition_name, trig_direction, trig_cooldown) else: print_limit( " - trigger value conditions not met, no action", 2) # Frame # trigger outside a window elif trigger == "frame": if ":" in value: val_min, val_max = value.split(":") if float(line_value) < float( val_min) and float(line_value) > float( val_max): print_limit( "Value less than " + val_min + " and greater than " + val_max + ", running " + cmd, 1) os.system(cmd + " &") pigrow_defs.set_condition( condition_name, trig_direction, trig_cooldown) else: print_limit( " - trigger value conditions not met, no action", 2) # Any # trigger on any value being recorded elif trigger == "all": os.system(cmd + " &") print_limit("Trigger set to all, running " + cmd, 1) pigrow_defs.set_condition(condition_name, trig_direction, trig_cooldown)