A library to interface with Magichue(or Magichome)
Project description
python-magichue
Magichue(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.
Example
Rainbow cross-fade.
import time
import magichue
light = magichue.Light('192.168.0.20') # change address
if not light.on:
light.on = True
if light.is_white:
light.is_white = False
light.rgb = (255, 255, 255)
for hue in range(1000):
light.hue = hue / 1000
time.sleep(0.05)
Installation
$ pip install python-magichue
Usage
import magichue.
import magichue
light = magichue.Light('192.168.0.20')
Discover bulbs on lan
from magichue import discover_bulbs
print(discover_bulbs()) # returns list of bulb address
Power State
Getting power status.
print(light.on) # => True if light is on else False
Setting light on/off.
light.on = True
light.on = False
Getting color
This shows a tuple of current RGB.
print(light.rgb)
or access individually.
print(light.r)
print(light.g)
print(light.b)
White LEDs
If 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 execute light.is_white = False
before changing color.
Warm White(ww)
light.cw = 0
light.w = 255
Cold White (cw)
light.w = 0
light.cw = 255
Setting color
By rgb
light.rgb = (128, 0, 32)
or
light.r = 200
light.g = 0
light.b = 32
By hsb
light.hue = 0.3
light.saturation = 0.6
light.brightness = 255
hue, 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 bulb
Stripe bulb doesn't seem to allow jump to another color when you change color. To disable fading effect,
light.rgb = (128, 0, 20) # It fades
light.allow_fading = False # True by default
light.rgb = (20, 0, 128) # Jumps
Changing mode
Magichue blub has a built-in flash patterns.
To check current mode, just
print(light.mode.name) # string name of mode
print(light.mode.value) # integer value
and changing modes,
light.mode = magichue.RAINBOW_CROSSFADE
These 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
NORMAL
Changing the speed of mode
speed is a float value from 0 to 1.
print(light.speed)
light.speed = 0.5 # set speed to 50%
Custom Modes
You can create custom light flash patterns.
mode
- MODE_JUMP
- MODE_GRADUALLY
- MODE_STROBE
speed A float value 0 to 1
colors A list of rgb(tuple or list) which has less than 17 length.
from magichue import (
CustomMode,
MODE_JUMP,
)
# Creating Mode
mypattern1 = CustomMode(
mode=MODE_JUMP,
speed=0.5,
colors=[
(128, 0, 32),
(100, 20, 0),
(30, 30, 100),
(0, 0, 50)
]
)
# Apply Mode
light.mode = mypattern1
Other features are in development.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-magichue-0.2.9.3.tar.gz
.
File metadata
- Download URL: python-magichue-0.2.9.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80e02235ab2033976d82f757bb4d4db73b92c0fbd72773adfcd624ff64f50c73 |
|
MD5 | e50b3ac3e1cc92c2d192370a11a81cd0 |
|
BLAKE2b-256 | eef07c33df5a734b74549dec01d8b7949ae11d53186193a759c13ede80d16ed1 |
File details
Details for the file python_magichue-0.2.9.3-py3-none-any.whl
.
File metadata
- Download URL: python_magichue-0.2.9.3-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4c009677cf544564de58b83f4d11b39330d0f478208898cd25f6f4018c5c9c0 |
|
MD5 | 24d5b60192f4dcc8a31a258f1e416676 |
|
BLAKE2b-256 | 84b29ba8b341d3636bf1f42f80e980d1b95a06b11b5f558ed4111dce623a98de |