def _set_group_bri_hue_sat_trans(bridge, group_id, bri, hue, sat, trans):
    g = Group(bridge, group_id)
    g.transitiontime = trans
    g.on = True
    g.brightness = bri
    g.hue = hue
    g.saturation = sat
示例#2
0
def detect_button(pkt):
	if pkt.haslayer(DHCP):
		b = Bridge('192.168.1.103')
		b.connect()
		if pkt[Ether].src in MAC_ADDRESS_DICT.keys(): #Toggle Jacobs Room Lights
			print "Button Press Detected", pkt[Ether].src, MAC_ADDRESS_DICT[pkt[Ether].src] 
			roomGroup = Group(b,MAC_ADDRESS_DICT[pkt[Ether].src])
			roomGroup.on = not roomGroup.on
示例#3
0
def init(bridge_ip = '192.168.1.2', gamut = GamutC):
    # print(bridge_ip)
    global converter, b, group, go
    converter = Converter(gamut)
    b = Bridge(bridge_ip)
    # print(b)
    group = Group(b, 1)
    # go = Group(b, 2)
    go = b['portable']
示例#4
0
    def main(self):
        """===  Configuration ==="""
        # MAC and IPs to check for
        # IPs are set as reserved in router to avoid changes
        to_scan = {
            'D8:C4:6A:23:B4:05': '192.168.0.15/32',
            '60:F1:89:1B:F6:E4': '192.168.0.16/32'
        }
        # Group to toggle
        group_name = 'Main Room'
        # Hue hostname (also reserved IP)
        hostname = '192.168.0.11'
        device_file = '/serve/phaos/devices.txt'

        # Read the previous count from the file
        if os.path.exists(device_file):
            with open(device_file, 'r') as track_file:
                previous_count = int(track_file.readline())
        else:
            previous_count = 0

# Arping the devices
        packets = []
        for mac, ip in to_scan.iteritems():
            ans, unans = srp(Ether(dst=mac) / ARP(pdst=ip), timeout=2)
            # Track the answers
            for pair in ans:
                packets.append(pair)

        current_count = len(packets)

        # Turn on/off the lights given the devices
        print str(datetime.now(
        )), "Previous count:", previous_count, "Current count:", current_count
        if previous_count > 0 and current_count == 0:
            bridge = Bridge(hostname)
            Group(bridge, group_name).on = False
        elif previous_count == 0 and current_count > 0:
            bridge = Bridge(hostname)
            Group(bridge, group_name).on = True

# Write current count to file
        with open(device_file, 'w') as track_file:
            track_file.write(str(current_count))
示例#5
0
 def __init__(self,switch_name,switch_ioport,switch_group,switch_user):
     self.switch_name = switch_name
     self.switch_ioport = switch_ioport
     self.switch_group = switch_group
     self.switch_group_id = bridge_bureau.get_group_id_by_name(self.switch_group)
     self.time_pressed = time.time()
     self.switch_user = switch_user
     self.group_class = Group(bridge_bureau,switch_group) #Class Group
     self.lights_in_group = sorted (bridge_bureau.get_group(switch_group, 'lights'))
     self.scenes_in_group =  [x for x in scene_diction.keys() if (sorted(scene_diction[x]['lights']) == self.lights_in_group) &
                             (scene_diction[x]['name']!= 'Uit')]
     self.sofie_scene = self.find_scene_Sofie() # first scene to be ran
     self.last_scene = self.sofie_scene
示例#6
0
    def set_lights(self, on=True):
        bridge = Bridge(self.hue_hostname)

        # Turn on/off all of the configured lights
        for light, time_config in self.lights:
            # Only change them if the timing info matches
            if self.check_time_config(time_config):
                Light(bridge, light).on = on

        # Turn on/off all of the configured groups
        for group, time_config in self.groups:
            if self.check_time_config(time_config):
                Group(bridge, group).on = on
示例#7
0
    def _set_default_group(self, identifier):
        """
        Sets the group to which commands will be applied, when
        a group is not specified in the command.

        Parameters
        ----------
        identifier : str or int
            The name of the group, or it's integer id

        Notes
        -----
        If the group does not exist, 0 (all lights) will be
        used.

        """
        try:
            self.default_group = Group(self.bridge, identifier)
        except LookupError:
            self.speak_dialog('could.not.find.group', {'name': identifier})
            self.speak_dialog('using.group.0')
            self.default_group = Group(self.bridge, 0)
    def cycle():
        g = Group(b, room_group_id)
        i = 0
        lights = g.lights

        while lock_is_valid(lock):
            i += 1
            if (i >= len(lights)): i = 0

            g.transitiontime = default_transitiontime

            for j, light in enumerate(lights):
                light.on = i == j
            
            sleep(1)
    def cycle():
        g = Group(b, room_group_id)
        i = 0
        lights = g.lights

        while lock_is_valid(lock):
            i += 1
            if (i > 1): i = 0

            g.transitiontime = default_transitiontime

            for j, light in enumerate(lights):
                light.on = True
                light.transitiontime = 0
                light.brightness = max_bri
                light.saturation = max_sat

                if j % 2 == i:
                    light.hue = red_hue
                else:
                    light.hue = blue_hue
                
            sleep(0.8)
示例#10
0
 def handler(self, message):
     if message.type == 'ConnectLightsIntent' \
             or self.connected or self._connect_to_bridge():
         group = self.default_group
         if "Group" in message.data:
             name = message.data["Group"].lower()
             group_id = self.groups_to_ids_map[name]
             group = Group(self.bridge, group_id)
         try:
             handler_function(self, message, group)
         except PhueRequestTimeout:
             self.speak_dialog('unable.to.perform.action')
         except Exception as e:
             if 'No route to host' in e.args:
                 if self.user_supplied_ip:
                     self.speak_dialog('no.route')
                     return
                 else:
                     self.speak_dialog('could.not.communicate')
                     if self._connect_to_bridge(True):
                         self.handle_intent(message)
             else:
                 raise
示例#11
0
# If the app is not registered and the button is not pressed, press the button $
b1.connect()

H3 = huelights()
# hueLights = json.dumps(b1.get_light(), indent=4 )
# print(hueLights)

#lights = b1.get_light()
#print(lights)

#print("Hue Light: " + str(b1.get_light() ))

#b2 = doorbell()
#print("Bell: " + str(b2))

g1 = Group(b1, 1)

allLights = AllLights(g1)

#print(b1.ip)
if debug > 9: print(b1.config_file_path)


def getLightInfo(activeBulb):
    if debug > 9:
        allinfo = b1.get_light(activeBulb)
        #     print("getLightInfo: " , allinfo)
        name = b1.get_light(activeBulb, "name")
        print("name %s", name)

        state = b1.get_light(activeBulb, "type")
def hue_set_all_on(b): Group(b, room_group_id).on = True
def hue_set_all_high_bri(b): _set_group_bri(b, room_group_id, max_bri)
def hue_set_all_off(b): Group(b, room_group_id).on = False
def hue_set_all_on(b): Group(b, room_group_id).on = True
def _set_group_bri(bridge, group_id, bri):
    g = Group(bridge, group_id)
    g.transitiontime = default_transitiontime
    g.on = True
    g.brightness = bri
示例#15
0
import random
import time, datetime
import skywriter
import signal
from queue import Queue
from collections import deque
import requests
import json
import random
import pychromecast

b = Bridge('10.0.0.80')
b.connect() #Comment out after first run
url = "http://10.0.0.34:8080/post/"
# group = Group(b, "Living room")
group = Group(b, "Office")
lights = group.lights
media_controller = None
stop_threads = False

fire_graph = {
	"base_red_1": {
		"transition_to": 1,
		"hue": 4000,
		"saturation": 253,
		"brightness": 141,
		"edges": [
			{
				"dest": "base_red_2",
				"weight": 0.80
			},
示例#16
0
# Changing Hue colors with target
import libs
from phue import Bridge, Group
import time
import sys
import oscilliate_group as osc
import reset


bridge_ip = '192.168.1.2'
b = Bridge(bridge_ip)
g = Group(b, 1)
up = True
delay_mode = 'FAST'

osc.OPTIONS = {
'r': 255,
'g': 255,
'b': 255,
'dr': 0,
'dg': 0,
'db': 0,
'ddr': 0,
'ddg': -5,
'ddb': -6,
'brightness': 255,
'dbrightness': 0,
'ddbrightness': 0
}

osc.TARGET = {
示例#17
0
# sleep(2)
# test_light.on = False
# sleep(2)
print(b.groups)

nb_group = b.groups
#print(len(nb_group))

print(b.get_group_id_by_name('control_group'))

#print(b.lights)

#b.create_group('control_group', [3, 4, 5])
b.set_group(group_id='control_group', parameter='lights', value=[5])

gr0 = Group(b, 'control_group')
gr0.on = True
gr0.brightness = 254
gr0.colortemp_k = 3500
sleep(3)
gr0.on = False
b.set_group(group_id='control_group', parameter='lights', value=[3, 4])

gr0 = Group(b, 'control_group')
gr0.on = True
gr0.brightness = 254
gr0.colortemp_k = 3500
sleep(3)
gr0.on = False
# print(b.get_group_id_by_name('control_group'))
示例#18
0
def lightsAction(message, philips_bridge):
    """Makes the appropriate calls to the phue API for changing light settings based on message and
    generates a response.

    Args:
        message (str): An incoming text message.
        apis['philips_bridge']: Instance of phue API bridge object

    Returns:
        A message indicating what action was taking with the phue API.
    """
    # set default answer to error message
    answer = "Something went wrong..."
    # by default, set lights to all lights
    lights = philips_bridge.lights
    # get the names of all lights
    light_names = [l.name.lower() for l in lights]
    # get the name of all rooms (Hue calls these 'groups')
    groups = philips_bridge.get_group()
    room_names = [groups[key]['name'] for key in groups]

    # look for room-specific mentions in the sms. If room name mentioned
    # set lights equal to all lights in this group
    mentioned_room = ''
    for room in room_names:
        if re.search(room.lower(), message):
            mentioned_room = room.lower() + ' '
            lights = Group(philips_bridge, room).lights

    # use regex and cascading rules to determine action to take with lights
    # 1) Setting lights to a certain % intensity
    if re.search(r"%|\bpercent\b|\bdim\b", message):
        """
        Example text:
            - 'dim bedroom lights'
            - 'set lights to 50%'
        """
        # if the word is dim is mentioned, set to 15%
        if re.search('dim', message):
            intensity = '15'
        # else find the value that directly proceeds '%' or 'percent'
        else:
            intensity = re.findall(r'(\w+)\s*(%|percent)\s*', message)[0][0]
        try:
            for l in lights:
                l.on = True
                # normalize % intensity to a value between 0-254
                l.brightness = int(int(intensity) / 100 * 254)
                answer = "Setting {}lights to {}%...\U0001F4A1".format(
                    mentioned_room, intensity)
        except:
            answer = 'Something went wrong while trying to change your lights brightness...'

    # 2) Turning lights off
    elif re.search(r"\boff\b", message):
        """
        Example text:
            - 'turn off the bedroom lights'
            - 'turn off the lights'
        """
        try:
            for l in lights:
                l.on = False
            answer = "Turning {}lights off...\U0001F4A1".format(mentioned_room)
        except:
            answer = 'Something went wrong while trying to turn your lights off...'
    # 3) Turning lights on
    elif re.search(r"\bon\b", message):
        """
        Example text:
            - 'turn on the bedroom lights'
            - 'turn on the lights'
        """
        try:
            for l in lights:
                l.on = True
                l.brightness = 254
            answer = "Turning {}lights on...\U0001F4A1".format(mentioned_room)

        except:
            answer = 'Something went wrong while trying to turn your lights on...'
    # 4) Warming or cooling lights
    elif re.search(r"\bwarm\b|\bcool\b", message, re.IGNORECASE):
        """
        Example text:
            - 'Warm the bedroom lights'
            - 'Cool the lights'
        """
        warmOrCool = ''
        # check if warm or cool was mentioned
        if re.search(r'warm', message, re.IGNORECASE):
            warmOrCool = 'Warming'
        elif re.search(r'cool', message, re.IGNORECASE):
            warmOrCool = 'Cooling'
        # turn on and then warm or cool lights accordingly
        try:
            for l in lights:
                l.on = True
                # cool or warm lights
                if warmOrCool == 'Warming':
                    l.colortemp_k = 2000
                    # additionaly set lights to 60% brightness
                    l.brightness = 152
                elif warmOrCool == 'Cooling':
                    l.colortemp_k = 6500
                    # additionaly set lights to 80% brightness
                    l.brightness = 254
            answer = "{} {}lights...\U0001F4A1".format(warmOrCool,
                                                       mentioned_room)
        except Exception as exception:
            answer = 'Something went wrong while trying to warm or cool your lights...'
    # 5) Change the lights color
    # NOTE THIS IS A BIT OF A HACK, NEEDS TO BE IMPROVED
    else:
        """
        Example text:
            - 'Turn the lights blue'
            - 'Turn the bedroom lights red'
        """
        # tokenize
        tokens = tokenize.wordpunct_tokenize(message)
        # filter stopwords
        tokens_filtered = remove_stopwords(tokens)
        # join filtered message
        message_filtered = ' '.join(tokens_filtered)
        print("(Highly) processed input: ", message_filtered)
        # find the mention of a color name
        color = re.findall(r'\s*lights?\s*(\w+)', message_filtered)[0]
        # THIS IS A TEMPORARY HACK
        colors = {
            'blue': 40000,
            'red': 100,
            'green': 30000,
            'orange': 4000,
            'pink': 60000,
            'purple': 50000,
        }
        try:
            for l in lights:
                l.on = True
                l.brightness = 254
                # this is necessary to reproduce colours accurately
                l.colortemp_k = 2000
                l.hue = colors[color]
            answer = "Turning {}lights {}...\U0001F4A1".format(
                mentioned_room, color)
        except:
            answer = 'Something went wrong while trying to change the color of yours lights...'
    # return final answer
    return answer
示例#19
0
#!/usr/bin/env python

import RPi.GPIO as GPIO
import SimpleMFRC522
import http.server
from phue import Bridge, Group
import threading
import random
import time, datetime
from queue import Queue
from collections import deque
import sys

b = Bridge('10.0.0.80')
b.connect() #Comment out after first run
group = Group(b, "Office")
if(len(sys.argv) > 1 and sys.argv[1]=="LR"):
	group = Group(b, "Living room")
lights = group.lights
print(lights)
print(lights[0].hue)

passive = ""
default_state = None

def lightning_effect(sound=False):
	print("lightning_effect - sound={}".format(sound))
	start_state = {
		"hue": lights[0].hue,
		"saturation": lights[0].saturation,
		"brightness":lights[0].brightness,
示例#20
0
 def _find_group(self, group_name):
     group_id = self._find_fuzzy(self.groups_to_ids_map, group_name)
     if group_id is not None:
         return Group(self.bridge, group_id)