def flic_test(): light_info_deveui = file_WR.RW_light_info_read() sensor_id = 'A81758FFFE030461' status = light_info_deveui[sensor_id]["flic_status"] if status == 1: addresses = [['14/2/41', 1, 0], ['14/2/46', 1, 0], ['14/3/81', 4, 0], ['14/3/101', 4, 0], ['14/3/121', 4, 190], ['14/3/141', 4, 190], ['14/3/161', 4, 230], ['14/3/181', 4, 230], ['14/3/201', 4, 230], ['14/3/221', 4, 230]] for add in addresses: if add[1] == 1: if sdl_knx.set_led(tunnel, toknx(add[0]), add[2]): print('1') return 1 else: if sdl_knx.set_rgb(tunnel, toknx(add[0]), [0, 0, 0, add[2]]): print('1') return 1 file_WR.RW_light_info_update('presentation', 'flic_status', 0) return "All lights" else: zone_name = "presentation" color = [0, 0, 0, 253] file_WR.RW_light_info_update('presentation', 'flic_status', 1) if sdl_knx.set_light_zone(tunnel, zone_name, color): restart() return "Unable to write to the KNX bus" else: return "All lights were set successfully"
def active_zone(zone_name='0_0'): global tunnel if request.method == 'POST': file_WR.RW_light_info_update(zone_name, 'active', 1) return "Active light activated in " + zone_name elif request.method == 'DELETE': file_WR.RW_light_info_update(zone_name, 'active', 0) return "Active light deactivated in " + zone_name
def flic_presentation_hold(): zone_z = 'PRESENTATION_' section = ['C', 'D', 'E', 'F', 'G', 'H', 'X', 'Y', 'A', 'B'] file_WR.RW_light_info_update('presentation', 'flic_status', 0) for sec in section: global tunnel if sec in ['X', 'A', 'Y', 'B']: zone_name = zone_z + sec color = [0, 0, 0, 240] if sdl_knx.set_light_zone(tunnel, zone_name, color): restart() return "Unable to write to the KNX bus" # else: # return "All lights were set successfully" if sec in ['C', 'D']: zone_name = zone_z + sec color = [0, 0, 0, 200] if sdl_knx.set_light_zone(tunnel, zone_name, color): restart() return "Unable to write to the KNX bus" # else: # return "All lights were set successfully" else: zone_name = zone_z + sec color = [0, 0, 0, 0] if sdl_knx.set_light_zone(tunnel, zone_name, color): restart() return "Unable to write to the KNX bus" # else: # return "All lights were set successfully" return "All lights were set successfully"
def set_light_zone(tunnel, zone_name, color): addresses = [] if len(zone_name.split('_')) == 3: name0 = zone_name.split('_')[0].upper() name1 = zone_name.split('_')[1].upper() name2 = zone_name.split('_')[2].upper() i = 0 for x in range(0, len(constants.LIGHT_LOOKUP_TABLE)): if constants.LIGHT_LOOKUP_TABLE[x][0].split('_')[0] == name0: if constants.LIGHT_LOOKUP_TABLE[x][0].split('_')[1] == name1: if constants.LIGHT_LOOKUP_TABLE[x][0].split( '_')[2] == name2: addresses.append([ constants.LIGHT_LOOKUP_TABLE[x][1], constants.LIGHT_LOOKUP_TABLE[x][2] ]) i = i + 1 elif len(zone_name.split('_')) == 2: name0 = zone_name.split('_')[0].upper() name1 = zone_name.split('_')[1].upper() i = 0 for x in range(0, len(constants.LIGHT_LOOKUP_TABLE)): if constants.LIGHT_LOOKUP_TABLE[x][0].split('_')[0] == name0: if constants.LIGHT_LOOKUP_TABLE[x][0].split('_')[1] == name1: addresses.append([ constants.LIGHT_LOOKUP_TABLE[x][1], constants.LIGHT_LOOKUP_TABLE[x][2] ]) i = i + 1 elif len(zone_name.split('_')) == 1: name0 = zone_name.split('_')[0].upper() i = 0 for x in range(0, len(constants.LIGHT_LOOKUP_TABLE)): if constants.LIGHT_LOOKUP_TABLE[x][0].split('_')[0] == name0: addresses.append([ constants.LIGHT_LOOKUP_TABLE[x][1], constants.LIGHT_LOOKUP_TABLE[x][2] ]) i = i + 1 for x in range(0, len(addresses)): print(addresses[x][0]) if addresses[x][1] == 1: if set_led(tunnel, toknx(addresses[x][0]), color[3]): print('1') return 1 elif addresses[x][1] == 4: if set_rgb(tunnel, toknx(addresses[x][0]), color): print('1') return 1 file_WR.RW_light_info_update(zone_name, "brightness_level", color[3]) return 0
def flic_click_zone(zone_name='0_0'): global tunnel sensor_id = "" for line in constants.LORA_SENSOR: if zone_name in line: sensor_id = line[0] light_info_deveui = file_WR.RW_light_info_read() status = light_info_deveui[sensor_id]["flic_status"] if status == 0: color = [0, 0, 0, 235] file_WR.RW_light_info_update(zone_name, 'flic_status', 1) else: color = [0, 0, 0, 0] file_WR.RW_light_info_update(zone_name, 'flic_status', 0) if sdl_knx.set_light_zone(tunnel, zone_name, color): restart() return "Unable to write to the KNX bus" else: return "All lights were set successfully"
def zone_light_threshold(zone_name='0_0', num='0'): """Updates, with PUT, the second light level of the light slope """ if request.method == 'PUT': if request.json: zone_name = zone_name.upper() file_WR.RW_light_info_update(zone_name, 'light_threshold' + num, request.json['value']) return "light threshold " + num + " from " + zone_name + " was updated to " + str( request.json['value'])
def all_on(tunnel, brightness): set_all_led(tunnel, brightness) set_all_rgb(tunnel, [0, 0, 0, brightness]) for x in constants.LORA_SENSOR: file_WR.RW_light_info_update(x[1], "brightness_level", brightness)
def lora(): """ This methods handle every messages sent by the LORA sensors and is also respoonsible of automatic lightning :return: """ global active_light_switch global tunnel light_info_deveui = file_WR.RW_light_info_read() hour = int(strftime("%H", localtime())) day = datetime.datetime.today().weekday() lowerbound = 290 upperbound = 500 # we suppose that there is no need for light between 21 and 6 and during the weekend # however the active switch button is deactivated after the first all_off call to prevent # automatic turn off if somebody is working on the week-end or after 21h for example if hour < 7 or hour > 20 or day == 7 or day == 6: if active_light_switch == 1: sdl_knx.all_off(tunnel) active_light_switch = 0 return "Non Active Time" else: if active_light_switch == 0: sdl_knx.all_on(tunnel, 235) active_light_switch = 1 active_light_switch = 1 try: sensorID = request.json['DevEUI'].upper() active = light_info_deveui[sensorID]['active'] zone_name = light_info_deveui[sensorID]['zone_name'] sensor_model = light_info_deveui[sensorID]['sensor_model'] current_brightness = light_info_deveui[sensorID][ 'brightness_level'] captured_light = request.json['Light'] except: return 'Unable to read the required parameters' if zone_name != 0 and active: # Only ERS sensor can detect motion if there is no motion for more than 14 min, turn off if sensor_model == 'ERS': motion_data = file_WR.RW_motion_data_update( zone_name, request.json['Motion']) if not motion(motion_data, zone_name): sdl_knx.set_light_zone(tunnel, zone_name[0, 0, 0, 0]) file_WR.RW_light_info_update(zone_name, "brightness_level", 0) return "No motion in the room light was turned off" if lowerbound < captured_light < upperbound: return "no adjustments needed" elif captured_light >= upperbound: if current_brightness != 0: lower_bright = 3 * current_brightness / 4 if lower_bright < 70: if not sdl_knx.set_light_zone(tunnel, zone_name, [0, 0, 0, 0]): return "Artificial light turned off" else: delta = current_brightness - lower_bright for x in range(1, int(delta), 5): if not sdl_knx.set_light_zone( tunnel, zone_name, [0, 0, 0, current_brightness - x]): sleep(4) return "Decreasing the artificial light" return "Already no artificial light" # Here we will hardcode a value for the lights. A captured light below 100 is very dark so we will directly # go to a 65% light elif captured_light < 80: if current_brightness == 210 or current_brightness == 230: hardcoded_bright = 230 else: hardcoded_bright = 210 # correspond to 65% regarding the range 0-255 if not sdl_knx.set_light_zone(tunnel, zone_name, [0, 0, 0, hardcoded_bright]): return "The artificial light has been set to 65% " return " The system wasn't able to set the new brightness value" else: # if there is currently no artificial light and that the captured light is too low we should increase # significantly the light therefore we start the incrementation at 50 to 120 as a base step if current_brightness == 0: for x in range(50, 200, 7): if not sdl_knx.set_light_zone(tunnel, zone_name, [0, 0, 0, x]): sleep(4) return "Artificial light has been activated" else: # if there is already artificial light and that we are below the threshold we increase the light # of 20% if current_brightness >= 250: return "Already fully lighted" for x in range( current_brightness, min(int(current_brightness + 255 / 100 * 15), 255), 5): if not sdl_knx.set_light_zone(tunnel, zone_name, [0, 0, 0, x]): sleep(4) return "Artificial light has been increased" return "Something"