def setup_platform(hass, config, add_entities, discovery_info=None): """ Set up the WiZ Light platform. """ # Assign configuration variables. # The configuration check takes care they are present. ip = config[CONF_HOST] bulb = wizlight(ip) # Add devices add_entities([WizBulb(bulb, config[CONF_NAME])])
async def send_to_device(self, colors: Colors) -> None: if len(colors) != len(config.LED_IPS): return try: ops = [ wizlight(config.LED_IPS[i]).turn_on(PilotBuilder(rgb=colors[i])) for i in range(len(config.LED_IPS)) ] loop = asyncio.get_event_loop() await asyncio.gather(*ops, loop=loop) except Exception: logging.exception("Something went wrong with LightController") await asyncio.sleep(config.CONTROLLER_ERROR_DELAY)
async def main(): """Sample code to work with bulbs.""" # Discover all bulbs in the network via broadcast datagram (UDP) # function takes the discovery object and returns a list with wizlight objects. # bulbs = await discovery.find_wizlights(discovery) # Print the IP address of the bulb on index 0 # print(f"Bulb IP address: {bulbs[0].ip}") # Iterate over all returned bulbs # for bulb in bulbs: # print(bulb.__dict__) # Turn off all available bulbs # await bulb.turn_off() # Set up a standard light #light = wizlight("192.168.0.170") light = wizlight("192.168.86.36") # Set up the light with a custom port #light = wizlight("your bulb's IP address", 12345) # The following calls need to be done inside an asyncio coroutine # to run them fron normal synchronous code, you can wrap them with # asyncio.run(..). # Turn on the light into "rhythm mode" # await light.turn_on(PilotBuilder()) # Set bulb brightness # await light.turn_on(PilotBuilder(brightness = 255)) # Set bulb brightness (with async timeout) timeout = 10 await asyncio.wait_for(light.turn_on(PilotBuilder(brightness=255)), timeout) # Set bulb to warm white # await light.turn_on(PilotBuilder(warm_white = 255)) # Set RGB values # red to 0 = 0%, green to 128 = 50%, blue to 255 = 100% # await light.turn_on(PilotBuilder(rgb = (0, 128, 255))) # Set bulb to red # await light.turn_on(PilotBuilder(warm_white = 255)) # Set RGB values # red to 0 = 0%, green to 128 = 50%, blue to 255 = 100% await light.turn_on(PilotBuilder(rgb=(255, 0, 0)))
def __init__(self, ip): self.light = wizlight(ip)
url = 'http://18.140.7.137/Pervasive_php_api/api/setting/read_single.php?id=' + user_id data = requests.get().json() brightness = int(data['brightness']) switch = int(data['switch']) #get settings print ("""current Setting : Brightness: {} switch: {} """.format(brightness,switch)) #Smart Lights local IP address light = wizlight("192.168.100.10") light2 = wizlight("192.168.100.11") lamp_state = False turn = False def button1_callback(channel): global brightness global lamp_state global light global light2 if brightness == 1 : brightness = 128 elif brightness == 128 : brightness = 255
def __init__(self, ip: str, loop): self.light = wizlight(ip) self.loop = loop self.initial_state = self.get_state()
def makeLight(name): ip = lightIpsByName[name] print("Light: {} ({})".format(name, ip)) return wizlight(ip)
import discord from discord.ext import commands import asyncio from pywizlight.bulb import wizlight, PilotBuilder # create/get the current thread's asyncio loop loop = asyncio.get_event_loop() # setup a standard light light = wizlight('IPADDY') light2 = wizlight('IPADDY') light3 = wizlight('IPADDY') from itertools import repeat import time import math class WizCog(commands.Cog): def __init__(self, bot): self.bot = bot print('Wiz Cog Loaded.') @commands.command(name='wizinfo') async def get_W1(self, ctx): """List Wiz Info.""" try: await ctx.send('Sending Wiz Command....') #message = '{"method": "getPilot", "id": 24, "params": {}}' #test = await light.sendUDPMessage(message, timeout = 60, send_interval = 0.5, max_send_datagrams = 100) #print(test) state = await light.updateState()
import asyncio import numpy as np from pywizlight.bulb import wizlight, PilotBuilder import colorsys # CW from leftmost light lights = (wizlight("192.168.0.122"), wizlight("192.168.0.162"), wizlight("192.168.0.154")) rng = np.random.default_rng() # Todo: randomize hue to be different than previous async def light_random(light): # uniform random ints # pb = PilotBuilder(rgb = tuple(map(lambda i: int(i), rng.integers(0, 256, size=3)))) # Dirichlet distribution #rgbs = np.round(255*np.random.dirichlet([1, 1, 1], 2)) # HSV with maximum saturation and value state = await lights[light].updateState() oldrgb = tuple(map(lambda i: i/255, state.get_rgb())) oldhue = int(255 * colorsys.rgb_to_hsv(oldrgb[0], oldrgb[1], oldrgb[2])[0]) while True: hue = rng.uniform(0, 360, 1) print(oldhue) print(hue) if abs(hue - oldhue) > 100 or (360 - oldhue + hue > 100) or (360 - hue + oldhue > 100): break rgb = colorsys.hsv_to_rgb(hue, 1.0, 1.0) await lights[light].turn_on(PilotBuilder(rgb = tuple(map(lambda i: int(255*i), rgb)))) async def lights_random(): # create/get the current thread's asyncio loop loop = asyncio.get_event_loop()
async def state(ip): """Get the current state of a given bulb.""" click.echo("Get the state from %s" % ip) bulb = wizlight(ip) state = await bulb.updateState() click.echo(state.__dict__["pilotResult"])
async def turn_off(ip): """Turn a given bulb off.""" click.echo("Turning off %s" % ip) bulb = wizlight(ip) await bulb.turn_off()
async def turn_on(ip): """Turn a given bulb on.""" click.echo("Turning on %s" % ip) bulb = wizlight(ip) await bulb.turn_on()