Exemplo n.º 1
0
 def handle_nano_leaf_on_intent(self, message):
     silent_kw = message.data.get("SilentKeyword")
     MyPanels = Aurora(self.IPstring, self.tokenString)
     MyPanels.on = True
     MyPanels.brightness = 100
     if not silent_kw:
         self.speak_dialog("light.on")
def HyperLeaf(my_panels):
    PanelIDs = my_panels[1:-1]
    lower_panel = my_panels[0]
    upper_panel = my_panels[len(my_panels) - 1]
    first_panel = PanelIDs[0]
    last_panel = PanelIDs[len(PanelIDs) - 1]
    print(my_panels)
    print(lower_panel)
    print(first_panel)
    print(upper_panel)
    print(last_panel)
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
    sock.bind((UDP_IP, UDP_PORT))
    my_aurora = Aurora(IPstring,
                       tokenString)  # IP address and key for nanoleaf Aurora
    my_aurora.on = True  #Turn nanoleaf on
    my_aurora.brightness = 50  #set brightness
    sleep(1)
    strm = my_aurora.effect_stream(
    )  #set nanoleaf to streaming mode, this only works with bharat's fork of nanoleaf
    LOG.info(strm.addr)
    while True:
        data = sock.recvfrom(
            21
        )  # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21)
        now = datetime.datetime.now()  # retrieve time for debuging
        new = bytearray(data[0])  # retrieve hyperion byte array
        RGBList = list(new)  # great R-G-B list
        # print(RGBList)  # for debuging only
        PanelCount = 0  # initial condition
        for Panel in PanelIDs:  # itterate through the configured PanleID's above
            firstByteIndex = PanelCount * 3  # Red Index
            secondByteIndex = firstByteIndex + 1  # Green Index
            thirdByteIndex = secondByteIndex + 1  # Blue Index
            intPanelID = PanelIDs[
                PanelCount]  # This Panel ID ***could this not just be "Panel"
            intRedValue = RGBList[firstByteIndex]
            intGreenValue = RGBList[secondByteIndex]
            intBlueValue = RGBList[thirdByteIndex]
            # print(str(intPanelID) + " " + str(intRedValue) + " " + str(intGreenValue) + " " + str(intBlueValue))

            if intPanelID == lower_panel or intPanelID == first_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                strm.panel_set(lower_panel, intRedValue, intGreenValue,
                               intBlueValue)
                strm.panel_set(first_panel, intRedValue, intGreenValue,
                               intBlueValue)
            else:
                if intPanelID == upper_panel or intPanelID == last_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                    strm.panel_set(upper_panel, intRedValue, intGreenValue,
                                   intBlueValue)
                    strm.panel_set(last_panel, intRedValue, intGreenValue,
                                   intBlueValue)
                else:
                    strm.panel_set(intPanelID, intRedValue, intGreenValue,
                                   intBlueValue)  # set the current panel color
            PanelCount += 1  # next panel
 def show_temperature(self, temp):
     my_aurora = Aurora(self.IP, self.AUTH_TOKEN)
     red = Color("blue")
     colors = list(red.range_to(Color("red"), 50))
     color = colors[int(temp) + 10]
     hex = color.get_hex_l()[1:]
     my_aurora.rgb = hex
     my_aurora.brightness = 40
     sleep(2)
     my_aurora.on = False
def update_effect(effect_name):
    aurora = Aurora(support.get_nanoleaf_ip(), support.get_nanoleaf_token())
    aurora.on = True

    if effect_name == "Random\n":
        effect_name = aurora.effect_random()
        aurora.effect = effect_name
        return "Random - " + effect_name
    elif effect_name == "Flash Twice":
        aurora.identify()
    else:
        aurora.effect = effect_name

    return effect_name
Exemplo n.º 5
0
from nanoleaf import setup
from nanoleaf import Aurora
import time as tm
import sys
import myfunc
# auroraのip addressを見つけてトークンを作成する.
# 日によってip addressは異なる場合がある
#ipAddressList = setup.find_auroras()
#token = setup.generate_auth_token("10.0.1.2")

# auroraと接続する
#my_aurora = Aurora("10.0.1.3", "b2UeRO2H2aImB4uHYbDKtYCHJDIxuE4W")
my_aurora = Aurora("10.0.1.3", "ufeEL3sFsRYJB92XH6gDG6O5oXRIJPhB")
my_aurora.on = True
#for panel in my_aurora.panel_positions:
#  print(panel['panelId'])

# panel index
# 218, 113, 23, 101, 77, 87, 86, 209, 53

# 色の指定を行う
# animDataに入れるのは,'(panel数) (panel index) (frame数) (R) (G) (B) (W) (遷移時間)'
# (panel数)だけ最初に一つ指定
# list[0]はpanel index
# index[1]はindex + frame数
index = [['23', '53', '77', '86', '87', '101', '113', '209', '218'],
         [
             '23 1 ', '53 1 ', '77 1 ', '86 1 ', '87 1 ', '101 1 ', '113 1 ',
             '209 1 ', '218 1 '
         ]]
Exemplo n.º 6
0
 def handle_nano_leaf_off_intent(self, message):
     silent_kw = message.data.get("SilentKeyword")
     MyPanels = Aurora(self.IPstring, self.tokenString)
     MyPanels.on = False
     if not silent_kw:
         self.speak_dialog("light.off")
Exemplo n.º 7
0
 def do_cinema_mode(self, my_id, terminate):
     addr = self.get_ifaces()
     if len(addr) == 0:
         LOG.info("no UDP network connection detected")
     elif len(addr) == 1:
         iface, my_ip = addr.popitem()
         LOG.info("UDP network connection found")
         self.UDP_IP = my_ip
     LOG.info("Starting Nanoleaf Cinema Mode: " + str(my_id))
     all_panels = self.get_panels()
     panel_ids = all_panels[1:-1]
     lower_panel = all_panels[0]
     upper_panel = all_panels[len(all_panels) - 1]
     first_panel = panel_ids[0]
     last_panel = panel_ids[len(panel_ids) - 1]
     try:
         LOG.info('Attempting to open the socket connection')
         sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
         sock.bind((self.UDP_IP, self.UDP_PORT))
         sock.settimeout(5)
         socket_open = True
     except Exception as e:
         LOG.error(e)
         LOG.info('Socket Connection Failed')
         socket_open = False
     LOG.info('Connecting to Aurora at: ' + self.IPstring + " : " +
              self.tokenString)
     my_aurora = Aurora(
         self.IPstring,
         self.tokenString)  # IP address and key for nanoleaf Aurora
     my_aurora.on = True  # Turn nanoleaf on
     my_aurora.brightness = 50  # set brightness
     sleep(1)
     LOG.info('Attempting to switch to cinema mode')
     try:
         strm = my_aurora.effect_stream()  # set nanoleaf to streaming mode
         LOG.info('Aurora Successfully switched to cinema mode')
         LOG.info('waiting for udp data')
         while True:
             if not socket_open:
                 break
             try:
                 raw_data = sock.recvfrom(
                     21
                 )  # hyperion sends 3 bytes (R,G,B) for each configured light (3*7=21)
                 byte_data = bytearray(
                     raw_data[0])  # retrieve hyperion byte array
                 rgb_list = list(byte_data)  # great R-G-B list
                 # LOG.info(rgb_list)  # for debuging only
                 panel_count = 0  # initial condition
                 for each_panel in panel_ids:  # itterate through the configured PanleID's above
                     # Todo - Determine if I can use Panel instead of PanelID's
                     # Todo - If we can use Panel then the PanelCount should not be required
                     # LOG.info('Panel: ' + str(each_panel) + " - Panel ID:" + str(panel_ids[panel_count]))
                     first_byte_index = panel_count * 3  # Red Index
                     second_byte_index = first_byte_index + 1  # Green Index
                     third_byte_index = second_byte_index + 1  # Blue Index
                     int_panel_id = panel_ids[
                         panel_count]  # This Panel ID ***could this not just be "Panel"
                     # int_panel_id = each_panel
                     int_red_value = rgb_list[first_byte_index]
                     int_green_value = rgb_list[second_byte_index]
                     int_blue_value = rgb_list[third_byte_index]
                     if int_panel_id == lower_panel or int_panel_id == first_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                         strm.panel_set(lower_panel, int_red_value,
                                        int_green_value, int_blue_value)
                         strm.panel_set(first_panel, int_red_value,
                                        int_green_value, int_blue_value)
                     else:
                         if int_panel_id == upper_panel or int_panel_id == last_panel:  # condition to handle two panels on the same vertical axis, or configure hyperion to drive this as well
                             strm.panel_set(upper_panel, int_red_value,
                                            int_green_value, int_blue_value)
                             strm.panel_set(last_panel, int_red_value,
                                            int_green_value, int_blue_value)
                         else:
                             strm.panel_set(int_panel_id, int_red_value,
                                            int_green_value, int_blue_value
                                            )  # set the current panel color
                     panel_count += 1  # next panel
             except Exception as e:
                 LOG.error(e)
                 LOG.info('Socket Timeout Error - No Data Received')
                 break
             if terminate():
                 LOG.info('Stop Signal Received')
                 break
     except Exception as e:
         LOG.error(e)
         LOG.info('Aurora Failed to launch cinema mode')
     my_aurora.on = False  # Turn nanoleaf off
     try:
         sock.close()
         LOG.info('Socket Closed')
     except Exception as e:
         LOG.error(e)
         LOG.info('Socket Closure Failed!')
     LOG.info("Nanoleaf Cinema Mode Ended: " + str(my_id))
Exemplo n.º 8
0
 def nanoAction(message):
     global settings
     print("       < %s in queue" % q.qsize())
     part = 1
     # for Mixer and YouTube events
     if len(json.loads(message)["event"].split("_")) == 3:
         part = 2
     event = json.loads(message)["event"].split("_")[part].lower()
     try:
         host = settings["nanoleaf"]
         token = settings["nanoleaf_token"]
         host2 = settings["nanoleaf2"]
         token2 = settings["nanoleaf2_token"]
         device = nl12
         if event + "_device" in settings:
             device = settings[event + "_device"]
         if event == "connected":
             print("         + devices")
             if host != "":
                 print("           o " + nl1 + " (" + host + ")")
             if host2 != "":
                 print("           o " + nl2 + " (" + host2 + ")")
             print("         + waiting for events ...")
             return
         elif event == "naec":
             data = json.loads(
                 json.loads(message, encoding='utf-8-sig')["data"])
             effect_new = data["effect_new"]
             duration = int(data["effect_duration"])
             effect_default = data["effect_default"]
             parameter = data["effect_parameter"]
         elif event == "naecupdate":
             readSettings()
             return
         elif settings[event + "_effect"] != '':
             effect_new = settings[event + "_effect"]
             duration = int(settings[event + "_effectduration"])
             effect_default = settings["default_effect"]
             if (event == "host"):
                 data = json.loads(
                     json.loads(message, encoding='utf-8-sig')["data"])
                 if (int(data["viewers"]) < int(
                         settings["host_minviewers"])):
                     return
             elif (event == "cheer"):
                 data = json.loads(
                     json.loads(message, encoding='utf-8-sig')["data"])
                 if (int(data["bits"]) < int(settings["cheer_minbits"])):
                     return
         else:
             return
         if (event == "host"):
             print("         + " + event + " (" + str(data["viewers"]) +
                   " viewers)")
         elif (event == "cheer"):
             print("         + " + event + " (" + str(data["bits"]) +
                   " bits)")
         else:
             print("         + " + event)
         print("         + actions")
         if host != "" and '1' in device:
             my_aurora = Aurora(host, token)
             my_aurora.on = True
             my_aurora.effect = effect_new
         else:
             print("no '1' in " + device)
         if host2 != "" and '2' in device:
             my_aurora2 = Aurora(host2, token2)
             my_aurora2.on = True
             my_aurora2.effect = effect_new
         if duration > 0:
             durationtext = " for " + str(duration) + " seconds"
         else:
             durationtext = ""
         print("           o change effect to '" + effect_new + "'" +
               durationtext)
         if duration > 0:
             time.sleep(duration)
             if host != "" and '1' in device:
                 my_aurora.effect = effect_default
             if host2 != "" and '2' in device:
                 my_aurora2.effect = effect_default
             print("           o change effect to '" + effect_default + "'")
     except KeyError:
         pass
     except ValueError:
         print("Could not convert data to an integer.")
     except:
         print("Unexpected error:", sys.exc_info()[0])
         raise
Exemplo n.º 9
0
#---------------------------------------
#	Set Variables
#---------------------------------------
path = os.path.dirname(__file__)
settingsFile = "NAEC.json"
settings = {}

#---------------------------------------
#	Get settings
#---------------------------------------
try:
    with codecs.open(os.path.join(path, settingsFile),
                     encoding='utf-8-sig',
                     mode='r') as file:
        settings = json.load(file, encoding='utf-8-sig')
        print("read settings file: ", path + "\\" + settingsFile)
except:
    print("Unexpected error:", sys.exc_info())
    sys.exit("cannot read settings file")
    pass

#---------------------------------------
#	Nanoleaf Aurora actions
#---------------------------------------
my_aurora = Aurora(settings["nanoleaf"], settings["nanoleaf_token"])
if len(sys.argv) > 1:
    my_aurora.on = True
    my_aurora.effect = sys.argv[1]
else:
    my_aurora.on = False
Exemplo n.º 10
0
import PIL.ImageGrab
import math
import time
import colorsys
from nanoleaf import Aurora

backsplash = Aurora("nanoleaf", "gsFyJGvYGQzs818SsmBgn9eVyYe51WFg")
backsplash.on = True
info = backsplash.info
panel_list = []
for panel in info["panelLayout"]["layout"]["positionData"]:
    #print(str(panel["panelId"])+"\t"+str(panel["x"])+"\t"+str(panel["y"]))
    x = panel["x"]
    y = panel["y"]
    angle = math.radians(60)
    new_x = math.floor((x * math.cos(angle) + y * math.sin(angle)) / 75 + 2.5)
    new_y = 1 - math.floor((-x * math.sin(angle) + y * math.cos(angle)) / 172 +
                           0.75)
    unset_color = (-1, -1, -1)
    panel_list.append({
        "panelId": str(panel["panelId"]),
        "x": new_x,
        "y": new_y,
        "color": unset_color
    })
effect = {"command": "display", "animType": "static", "loop": False}
while True:
    im = PIL.ImageGrab.grab()
    im.thumbnail([5, 2])
    px = im.load()
    panel_strings = []