Package: python-magichue
python-magichueMagichue(as known as Magichome, FluxLED, etc.) is a cheap smart led bulb that you can controll hue/saturation/brightnes and power over WiFi. They are available at Amazon or other online web shop.I tested this library with RGBWWCW(v7), RGB(v8), RGBWW(v8) bulbs.Now it is possible to use Remote API !ExampleRainbow cross-fade.importtimeimportmagichueuser='username@example.com'password='password'api=magichue.RemoteAPI.login_user_password(user=user,password=password)light=api.get_online_bulbs()[0]# local_device_ips = magcihue.discover_bulbs()# light = magichue.LocalLight(local_device_ips[0])ifnotlight.on:light.on=Trueiflight.is_white:light.is_white=Falselight.rgb=(0,0,0)light.brightness=255light.saturation=1forhueinrange(1000):light.hue=hue/1000time.sleep(0.05)Installation$ pip install python-magichueUsageRemote APINow it's available to use MagicHome HTTP API.You have to login and register your bulb with MagicHome account in advance.Login with Username/Passwordapi=magichue.RemoteAPI.login_with_user_password(user='xxx',password='xxx')print(api.token)# you can show TOKEN and save it.Login with TokenIt is recommended to use token string.TOKEN='xxx'api=magichue.RemoteAPI.login_with_token(TOKEN)Make bulb instanceTOKEN='xxx'api=magichue.RemoteAPI.login_with_token(TOKEN)light=RemoteLight(api=api,macaddr='xxx')Discover bulbsLocal bulbsfrommagichueimportdiscover_bulbs,LocalLightaddrs=discover_bulbs()# returns list of bulb addresslight=magichue.LocalLight(addrs[0])Remote bulbsfrommagichueimportRemoteAPITOKEN='xxx'api=magichue.RemoteAPI.login_with_token(TOKEN)online_bulbs=api.get_online_bulbs()light=online_bulbs[0]# Getting online device information.online_devices=api.get_online_devices()# It is also possible to retrieve all device info binded with your account.all_devices=api.get_all_devices()Power StateGetting power status.print(light.on)# => True if light is on else FalseSetting light on/off.light.on=Truelight.on=False# orlight.turn_on()light.turn_off()Getting colorThis shows a tuple of current RGB.print(light.rgb)or access individually.print(light.r)print(light.g)print(light.b)White LEDsIf your bulbs support white leds, you can change brightness(0-255) of white leds.To use white led,light.is_white=True# light.is_white = False  # This disables white led.If white led is enabled, you can't change color of bulb!So, you need to executelight.is_white = Falsebefore changing color.Warm White(ww)light.cw=0light.w=255Cold White (cw)light.w=0light.cw=255Setting colorBy rgblight.rgb=(128,0,32)orlight.r=200light.g=0light.b=32By hsblight.hue=0.3light.saturation=0.6light.brightness=255hue, saturation are float value from 0 to 1. brightness is a integer value from 0 to 255.
These variables are also readable.Note about stripe bulbStripe bulb doesn't seem to allow jump to another color when you change color.
To disable fading effect,light.rgb=(128,0,20)# It fadeslight.allow_fading=False# True by defaultlight.rgb=(20,0,128)# JumpsBulb clockprint(light.get_current_time())Changing modeMagichue blub has a built-in flash patterns.To check current mode, justprint(light.mode.name)# string name of modeprint(light.mode.value)# integer valueand changing modes,light.mode=magichue.RAINBOW_CROSSFADEThese are built-in modes.RAINBOW_CROSSFADE
RED_GRADUALLY
GREEN_GRADUALLY
BLUE_GRADUALLY
YELLOW_GRADUALLY
BLUE_GREEN_GRADUALLY
PURPLE_GRADUALLY
WHITE_GRADUALLY
RED_GREEN_CROSSFADE
RED_BLUE_CROSSFADE
GREEN_BLUE_CROSSFADE
RAINBOW_STROBE
GREEN_STROBE
BLUE_STROBE
YELLOW_STROBE
BLUE_GREEN_STROBE
PURPLE_STROBE
WHITE_STROBE
RAINBOW_FLASH
NORMALChanging the speed of modespeed is a float value from 0 to 1.print(light.speed)light.speed=0.5# set speed to 50%Custom ModesYou can create custom light flash patterns.modeMODE_JUMPMODE_GRADUALLYMODE_STROBEspeedA float value 0 to 1colorsA list of rgb(tuple or list) which has less than 17 length.frommagichueimport(CustomMode,MODE_JUMP,)# Creating Modemypattern1=CustomMode(mode=MODE_JUMP,speed=0.5,colors=[(128,0,32),(100,20,0),(30,30,100),(0,0,50)])# Apply Modelight.mode=mypattern1Other features are in development.DebuggingPutting this snippet to begging of your code, this library outputs debug log.importloggginglogging.basicConfig(level=logging.DEBUG)