def TurnLightsOff(self): from core import ffScheduler from core import ffLocation if self._disabled: logging.critical('Contact Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.lights: for light in self.lights: ffCommand(light, "off", send_event=self._send_event) if self.actions_contact_closed: for device, action in self.actions_contact_closed.iteritems(): ffCommand(device, action, send_event=self._send_event) if 'hue' in device: sleep(0.5)
def TurnLightsOff(self): from core import ffScheduler from core import ffLocation if self._disabled: logging.critical('Switch Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.lights: for light in self.lights: ffCommand(light, "off", send_event=self._send_event) if self.actions_switch_off: for device, action in self.actions_switch_off.iteritems(): ffCommand(device, action, send_event=self._send_event) if 'hue' in device: sleep(0.5)
def setOn(self, args={}): self._state = True ffCommand(self._controller_id, {'switch': { 'node': self._node, 'on': True }})
def TurnLightsOff(self): if self._disabled: logging.critical('Motion Events Disabled') return -2 for light in self.lights: ffCommand(light, "off")
def manual_command(request): device_names = {} for d in deviceDB.find({},{"config.name":1,"id":1}): device_names[d.get('config').get('name')] = d.get('id') device_list = '' for name, did in device_names.iteritems(): device_list += str(name) + ' - ' + str(did) + '<br>' form = ''' <html> <h1>Manual Command</h1> <br> <form action="manual_command" method="POST" id="command"> <textarea form ="command" name="myCommand" id="myCommand" rows="6" cols="70" wrap="soft"></textarea> <input type="submit"> </form> Sample Commands <br> <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"on"}}'>{"device":"hue-light-8", "command":{"switch":"on"}}</a> <br> <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"off"}}'>{"device":"hue-light-8", "command":{"switch":"off"}}</a> <br> <a href='?myCommand={"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}'>{"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}</a> <br> <a href='?myCommand={"device":"ZachPresence", "command":{"presence":true}}'>{"device":"ZachPresence", "command":{"presence":true}}</a> <br> <a href='?myCommand={"device":"ZachPresence", "command":{"presence":false}}'>{"device":"ZachPresence", "command":{"presence":false}}</a> <br> <a href='?myCommand={"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}'>{"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}</a> <br> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"on"}}'>{"device":"hue-light-3", "command":{"switch":"on"}}</a> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"off"}}'>{"device":"hue-light-3", "command":{"switch":"off"}}</a> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}</a><br> <a href='?myCommand={"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}'>{"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}</a> <br> <br> <a href='?myCommand={"device":"home","routine":true, "force":true}'>{"device":"home","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"home-daylight","routine":true, "force":true}'>{"device":"home-daylight","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"night","routine":true, "force":true}'>{"device":"night","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"away","routine":true, "force":true}'>{"device":"away","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"sexy","routine":true, "force":true}'>{"device":"sexy","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"morning","routine":true, "force":true}'>{"device":"morning","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"sunset","routine":true, "force":true}'>{"device":"sunset","routine":true, "force":true}</a> <br> <br> <a href="http://www.w3schools.com/colors/colors_hex.asp"> Color Names </a><br> <br> Devices:<br>''' + device_list + ''' </html> ''' if request.method == 'POST' or request.args.get('myCommand'): try: command = json.loads(request.args.get('myCommand')[0]) if command.get('routine'): myCommand = ffCommand(command.get('device'),command.get('command'), routine=command.get('routine'), force=command.get('force'), source='Web: Manual Command').result else: myCommand = ffCommand(command.get('device'),command.get('command'), source='Web: Manual Command').result return form + '<br><br> Last Command: ' + str(request.args.get('myCommand')[0]) + 'Sucessfully sent to device: ' + str(myCommand) except ValueError: return form + '<br><br>Last Command Failed - INVALID JSON FORMAT ' + str(request.args.get('myCommand')[0]) else: return form + str(request.args)
def runFade(self): if self._run: if self._startLevel and self._endLevel: lightCommand = ffCommand( self._deviceID, { 'setLight': { 'ct': str(self._currentK) + 'K', 'transitiontime': self._delay * 10, 'level': self._currnetL, 'ctfade': True } }) self._currnetL += self._lStep else: lightCommand = ffCommand( self._deviceID, { 'setLight': { 'ct': str(self._currentK) + 'K', 'transitiontime': self._delay * 10, 'ctfade': True } }) if self._timeRemaining > 0: ffScheduler.runInS(int(self._delay), self.runFade, replace=True, job_id=self._deviceID) self._currentK -= self._step self._timeRemaining -= self._delay
def setOff(self, args={}): self._state = False ffCommand(self._controller_id, {'switch': { 'node': self._node, 'on': False }})
def set_light(self, value): logging.critical("SET_LIGHT") ffCommand(self._bridge, { 'sendLightCommand': { 'lightCommand': value, 'lightID': self._light_id } })
def refresh_hue(self): rawLightData = self._hueBridge.get_lights() for light, lightData in rawLightData.iteritems(): deviceID = 'hue-light-' + str(light) updateEvent =ffCommand(deviceID,{'update':lightData}) rawGroupData = self._hueBridge.get_groups() for group, groupData in rawGroupData.iteritems(): deviceID = 'hue-group-' + str(group) updateEvent = ffCommand(deviceID,{'update':groupData})
def runFade(self): if self._run: if self._startLevel and self._endLevel: lightCommand = ffCommand(self._deviceID, {'setLight':{'ct':str(self._currentK)+'K','transitiontime':self._delay*10,'level':self._currnetL, 'ctfade':True}}) self._currnetL += self._lStep else: lightCommand = ffCommand(self._deviceID, {'setLight':{'ct':str(self._currentK)+'K','transitiontime':self._delay*10, 'ctfade':True}}) if self._timeRemaining > 0: ffScheduler.runInS(int(self._delay), self.runFade, replace=True, job_id=self._deviceID) self._currentK -= self._step self._timeRemaining -= self._delay
def sensorHandler(self, event={}): from core import ffScheduler from core import ffLocation logging.critical("ENTERNING LUX HANDELER") lux = int(event.event.get('luminance')) if event.event.get( 'luminance') is not None else None if lux is None or lux == '': return -2 logging.critical('LUX: ' + str(lux)) change_value = self.lux_level if self._disabled: logging.critical('Lux Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") retunr - 2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if lux <= change_value: if self.lights: for light in self.lights: ffCommand(light, "on", send_event=self._send_event) if self.actions_lux_low: for device, action in self.actions_lux_low.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) if lux > change_value: if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def switchHandler(self, event={}): from core import ffScheduler from core import ffLocation if self._disabled: logging.critical('Switch Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") return -2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if event.event.get('on'): if self.lights: for light in self.lights: ffCommand(light, "on", send_event=self._send_event) if self.actions_switch_on: for device, action in self.actions_switch_on.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) #Hack to be fixed soon if self.actions_switch_on_delayed: ffScheduler.cancel(self._id + "delayed") ffScheduler.runInM(self.delay_time, self.SwitchOnDelayed, replace=True, job_id=self._id + "delayed") if not event.event.get('on'): if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def sensorHandler(self, event={}): from core import ffScheduler from core import ffLocation logging.critical("ENTERNING LUX HANDELER") lux = int(event.event.get('luminance')) if event.event.get('luminance') is not None else None if lux is None or lux == '': return -2 logging.critical('LUX: ' + str(lux)) change_value = self.lux_level if self._disabled: logging.critical('Lux Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") retunr -2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if lux <= change_value: if self.lights: for light in self.lights: ffCommand(light,"on", send_event=self._send_event) if self.actions_lux_low: for device, action in self.actions_lux_low.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) if lux > change_value: if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def api_control(request): request.setHeader('Content-Type', 'application/json') body = json.loads(request.content.read()) device = body.get('device') command = body.get('command') result = ffCommand(device,command) return json.dumps({'action':'recieved'})
def api_control(request): request.setHeader('Content-Type', 'application/json') body = json.loads(request.content.read()) device = body.get('device') command = body.get('command') result = ffCommand(device, command) return json.dumps({'action': 'recieved'})
def set_light(self, value): light_id = self._light_id lightCommand = ffCommand( self._bridge, {'sendLightRequest': { 'lightID': light_id, 'data': value }})
def motionHandeler(self, event={}): logging.critical('Motion Handeler!!!##') from core import ffScheduler from core import ffLocation logging.critical('Entered Motion Handeler') if self._disabled: logging.critical('Motion Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") return -2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if event.event.get('motion'): for light in self.lights: ffCommand(light, "on", send_event=self._send_event) for device, action in self.actions_on_motion_active.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) if not event.event.get('motion'): if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def switchHandler(self, event={}): from core import ffScheduler from core import ffLocation if self._disabled: logging.critical('Switch Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") return -2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if event.event.get('on'): if self.lights: for light in self.lights: ffCommand(light,"on", send_event=self._send_event) if self.actions_switch_on: for device, action in self.actions_switch_on.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) #Hack to be fixed soon if self.actions_switch_on_delayed: ffScheduler.cancel(self._id+"delayed") ffScheduler.runInM(self.delay_time, self.SwitchOnDelayed, replace=True, job_id=self._id+"delayed") if not event.event.get('on'): if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def motionHandeler(self, event={}): logging.critical('Motion Handeler!!!##') from core import ffScheduler from core import ffLocation logging.critical('Entered Motion Handeler') if self._disabled: logging.critical('Motion Events Disabled') return -2 if self.run_modes: if ffLocation.mode not in self.run_modes: logging.critical("Not in mode to run") return -2 if self.no_run_modes: if ffLocation.mode in self.no_run_modes: logging.critical("In no run mode") return -2 if self.run_dark is not None: if not ffLocation.isDark: logging.critical("Not running because is dark") return -2 if self.run_light is not None: if not ffLocation.isLight: logging.critical("Not running because is light") return -2 if event.event.get('motion'): for light in self.lights: ffCommand(light,"on", send_event=self._send_event) for device, action in self.actions_on_motion_active.iteritems(): ffCommand(device, action, send_event=self._send_event) ffScheduler.cancel(self._id) if not event.event.get('motion'): if self.delay_time is None: self.TurnLightsOff() else: ffScheduler.runInM(self.delay_time, self.TurnLightsOff, replace=True, job_id=self._id)
def get_all_node_data(self, args={}): if self._network is None: ffEvent(self._id,{'zwave':'network_not_ready'}) #logging.critical('Zwave not ready') return 1 returnData = {} for node in self._network.nodes: nodeData = {} nodeData['node'] = node nodeData['manufacturer_name'] = self._network.nodes[node].manufacturer_name nodeData['product_name'] = self._network.nodes[node].product_name nodeData['product_id'] = self._network.nodes[node].product_id nodeData['product_type'] = self._network.nodes[node].product_type nodeData['device_type'] = self._network.nodes[node].device_type nodeData['command_classes_as_string'] = self._network.nodes[node].command_classes_as_string nodeData['ready'] = self._network.nodes[node].is_ready nodeData['failed'] = self._network.nodes[node].is_failed now = time() if self._lastNodeUpdate.get(node) is None or int(self._lastNodeUpdate.get(node) - now) > 1: for val in self._network.nodes[node].get_switches(): self._network.nodes[node].refresh_value(val) self._lastNodeUpdate[node] = now sleep(1) dataValues = {} for a,b in self._network.nodes[node].values_to_dict().iteritems(): dataValues[b['label']] = b nodeData['data'] = dataValues returnData['node-'+str(node)] = nodeData if self._oldData == returnData: logging.debug('Zwave No Change') else: chnageData = {} for oA, oB in self._oldData.iteritems(): if oB != returnData[oA]: chnageData[oA] = returnData[oA] #logging.critical(str(returnData[oA])) ffCommand('zwave-' + str(oA), {'update' : returnData[oA]}, source='ffZwave') self._oldData = returnData
def echo_change_mode(intent): global routine_list mode = intent.get('slots').get('mode').get('value').lower() close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) < 1: get_routines_list() close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) > 0: routine = close_matches[0] myCommand = ffCommand(routine, None, routine=True, source="Echo command", force=True) if myCommand.result: return make_response("Changed mode to " + str(routine), "Changed mode to " + str(routine)) return make_response("Error changing mode to " + str(mode), "Error changing mode to " + str(mode), card_title="Firefly Smart Home Error")
def echo_dimmer(intent): global device_list device = intent.get('slots').get('device').get('value').lower() level = int(intent.get('slots').get('level').get('value')) close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'setLight' : {'level':level}}) if myCommand.result: return make_response("Set " + str(device) + " to " + str(level) + " percent.", "Set " + str(device) + " to " + str(level) + "percent.") return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def ifttt_change_mode(request): global routine_list mode = request.get('mode').lower() if mode is None: return False close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) < 1: get_routines_list() close_matches = difflib.get_close_matches(mode, routine_list) if len(close_matches) > 0: routine = close_matches[0] myCommand = ffCommand(routine, None, routine=True, source="Echo command", force=True) if myCommand.result: return True return False
def echo_switch(intent): global device_list device = intent.get('slots').get('device').get('value').lower() state = intent.get('slots').get('state').get('value') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch':state}) if myCommand.result: return make_response("Turned " + str(device) + " " + str(state), "Turned " + str(device) + " " + str(state)) return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def ifttt_switch(request): global device_list device = request.get('device').lower() if device is None: return False state = request.get('state') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch':state}) if myCommand.result: return True return False
def ifttt_switch(request): global device_list device = request.get('device').lower() if device is None: return False state = request.get('state') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch': state}) if myCommand.result: return True return False
def echo_switch(intent): global device_list device = intent.get('slots').get('device').get('value').lower() state = intent.get('slots').get('state').get('value') close_matches = difflib.get_close_matches(device, device_list.keys()) logging.critical(device_list) logging.critical(close_matches) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'switch': state}) if myCommand.result: return make_response("Turned " + str(device) + " " + str(state), "Turned " + str(device) + " " + str(state)) return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def echo_dimmer(intent): global device_list device = intent.get('slots').get('device').get('value').lower() level = int(intent.get('slots').get('level').get('value')) close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) < 1: get_device_list() close_matches = difflib.get_close_matches(device, device_list.keys()) if len(close_matches) > 0: device = close_matches[0] myCommand = ffCommand(device_list.get(device), {'setLight': { 'level': level }}) if myCommand.result: return make_response( "Set " + str(device) + " to " + str(level) + " percent.", "Set " + str(device) + " to " + str(level) + "percent.") return make_response("Error finding device " + str(device), "Error finding device " + str(device), card_title="Firefly Smart Home Error")
def setOn(self, args={}): self._state = True ffCommand(self._controller_id,{'switch' : {'node':self._node, 'on':True}})
def set_light(self, value): light_id = self._light_id lightCommand = ffCommand(self._bridge,{'sendLightRequest' : {'lightID':light_id,'data':value}})
def set_light(self, value): logging.critical("SET_LIGHT") ffCommand(self._bridge, {'sendLightCommand':{'lightCommand':value,'lightID': self._light_id}})
def setOff(self, args={}): self._state = False ffCommand(self._controller_id,{'switch' : {'node':self._node, 'on':False}})
def manual_command(request): device_names = {} for d in deviceDB.find({}, {"config.name": 1, "id": 1}): device_names[d.get('config').get('name')] = d.get('id') device_list = '' for name, did in device_names.iteritems(): device_list += str(name) + ' - ' + str(did) + '<br>' form = ''' <html> <h1>Manual Command</h1> <br> <form action="manual_command" method="POST" id="command"> <textarea form ="command" name="myCommand" id="myCommand" rows="6" cols="70" wrap="soft"></textarea> <input type="submit"> </form> Sample Commands <br> <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"on"}}'>{"device":"hue-light-8", "command":{"switch":"on"}}</a> <br> <a href='?myCommand={"device":"hue-light-8", "command":{"switch":"off"}}'>{"device":"hue-light-8", "command":{"switch":"off"}}</a> <br> <a href='?myCommand={"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}'>{"device":"ZachPushover", "command":{"notify":{"message":"New Test Message"}}}</a> <br> <a href='?myCommand={"device":"ZachPresence", "command":{"presence":true}}'>{"device":"ZachPresence", "command":{"presence":true}}</a> <br> <a href='?myCommand={"device":"ZachPresence", "command":{"presence":false}}'>{"device":"ZachPresence", "command":{"presence":false}}</a> <br> <a href='?myCommand={"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}'>{"device":"hue-group-4", "command":{"setLight":{"preset":"cloudy", "transitiontime":40,"effect":"none","level":100,"alert":"lselect"}}}</a> <br> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"colorloop","level":50}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}'>{"device":"hue-light-3", "command":{"setLight":{"effect":"none","level":50}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"on"}}'>{"device":"hue-light-3", "command":{"switch":"on"}}</a> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"switch":"off"}}'>{"device":"hue-light-3", "command":{"switch":"off"}}</a> <br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"red","level":100}}}</a><br> <a href='?myCommand={"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}'>{"device":"hue-light-3", "command":{"setLight":{"name":"blue","level":100}}}</a><br> <a href='?myCommand={"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}'>{"device":"hue-group-4", "command":{"ctfade":{"startK":6500, "endK":2700, "fadeS":900}}}</a> <br> <br> <a href='?myCommand={"device":"home","routine":true, "force":true}'>{"device":"home","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"home-daylight","routine":true, "force":true}'>{"device":"home-daylight","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"night","routine":true, "force":true}'>{"device":"night","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"away","routine":true, "force":true}'>{"device":"away","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"sexy","routine":true, "force":true}'>{"device":"sexy","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"morning","routine":true, "force":true}'>{"device":"morning","routine":true, "force":true}</a> <br> <a href='?myCommand={"device":"sunset","routine":true, "force":true}'>{"device":"sunset","routine":true, "force":true}</a> <br> <br> <a href="http://www.w3schools.com/colors/colors_hex.asp"> Color Names </a><br> <br> Devices:<br>''' + device_list + ''' </html> ''' if request.method == 'POST' or request.args.get('myCommand'): try: command = json.loads(request.args.get('myCommand')[0]) if command.get('routine'): myCommand = ffCommand(command.get('device'), command.get('command'), routine=command.get('routine'), force=command.get('force'), source='Web: Manual Command').result else: myCommand = ffCommand(command.get('device'), command.get('command'), source='Web: Manual Command').result return form + '<br><br> Last Command: ' + str( request.args.get('myCommand') [0]) + 'Sucessfully sent to device: ' + str(myCommand) except ValueError: return form + '<br><br>Last Command Failed - INVALID JSON FORMAT ' + str( request.args.get('myCommand')[0]) else: return form + str(request.args)
def SwitchOnDelayed(self): if self.actions_switch_on_delayed: for device, action in self.actions_switch_on_delayed.iteritems(): ffCommand(device, action, send_event=self._send_event) if 'hue' in device: sleep(0.5)
def executeRoutine(self, force=False): from time import sleep from datetime import datetime, time from core import ffLocation from core.utils.notify import Notification as ffNotification logging.debug("Executing Routine: " + self._name) if not force: if self._mode_no_run: if ffLocation.mode in self._mode_no_run: logging.debug( 'Returning: Set to not execute in mode: ' + ffLocation.mode) return if self._mode_run: if ffLocation.mode not in self._mode_run: logging.debug( 'Returning: Set to not execute in mode: ' + ffLocation.mode) return if self._run_time_ranges or self._no_run_time_ranges: now = datetime.now().time() if self._run_time_ranges: for timeRange in self._run_time_ranges: startH, startM = timeRange.get('start_time').split(':') startH = int(startH) startM = int(startM) endH, endM = timeRange.get('end_time').split(':') endH = int(endH) endM = int(endM) if startH <= endH: if not (now >= time(startH, startM) and now <= time(endH, endM)): logging.critical("Not in time range to run routine") return else: if not (now >= time(startH, startM) or now <= time(endH, endM)): logging.critical("Not in time range to run routine") return if self._no_run_time_ranges: for timeRange in self._no_run_time_ranges: startH, startM = timeRange.get('start_time').split(':') startH = int(startH) startM = int(startM) endH, endM = timeRange.get('end_time').split(':') endH = int(endH) endM = int(endM) logging.critical(str(startH) + ' ' + str(endH)) if startH <= endH: if now >= time(startH, startM) and now <= time(endH, endM): logging.critical("In time range to not run routine") return else: if now >= time(startH, startM) or now <= time(endH, endM): logging.critical("In time range to not run routine") return for device, commands in self._actions.iteritems(): ffCommand(device, commands) if 'hue' in device: sleep(0.5) if ffLocation: if ffLocation.isLightOffset(sunrise_offset=self._sunrise_offset): for device, commands in self._actions_day.iteritems(): ffCommand(device, commands) if 'hue' in device: sleep(0.5) elif ffLocation.isDark: for device, commands in self._actions_night.iteritems(): ffCommand(device, commands) if 'hue' in device: sleep(0.5) if self._mode: ffLocation.mode = self._mode if self._notification_devices and self._notification_message: for device in self._notification_devices: ffNotification(device, self._notification_message)
def set_group(self, value): group_id = self._group_id groupCommand = ffCommand(self._bridge,{'sendGroupRequest' : {'groupID':group_id,'data':value}})
def auto_refresh(): refresh_command = ffCommand('nest', 'update', source='NEST-UPDATER')