A library to interface with MagicHue aka MagicHome.
Project description
python-magichue
MagicHue (aka MagicHome) is a cheap smart led bulb that you can control hue/saturation/brightness and power over WiFi. They are available at Amazon or other online web shop.
I tested this library with RGB+WW+CW(v7), RGB(v8), RGB+WW(v8) bulbs.
Example
Rainbow cross-fade.
import time
import magichue
light = magichue.Light('192.168.0.20') # change to your address
light.on = True
light.is_white = False
light.saturation = 1
light.brightness = 255
for hue in range(1000):
light.hue = hue / 1000
time.sleep(0.05)
Installation
$ pip install 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 a list of bulb addresses
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) # (255, 127, 63)
or access individually:
print(light.r) # 255
print(light.g) # 127
print(light.b) # 63
White LEDs
If your bulbs support white LEDs, you can change the brightness (0-255) of white LEDs.
Enable the white led:
light.is_white = True
If white led is enabled, you can't change color of bulb!
You will need to disable it before you can change the color.
Disable the white led:
light.is_white = False
Warm White (ww)
light.cw = 0
light.w = 255
Cold White (cw)
light.w = 0
light.cw = 255
Setting Color
Red, Green, Blue (RGB)
Assign all colors with a tuple of integers:
light.rgb = (128, 0, 32)
or assign each color individually with an integer:
light.r = 200
light.g = 0
light.b = 32
Hue, Saturation, Brightness (HSB)
Hue and saturation are float values from 0 to 1.
Brightness is a integer value from 0 to 255.
light.hue = 0.3
light.saturation = 0.6
light.brightness = 255
Note About Stripe Bulb
Stripe bulb doesn't seem to allow jumping to another color when you change color.
To disable the fading effect,
light.rgb = (128, 0, 20) # Fades to set color
light.allow_fading = False # Set to True by default
light.rgb = (20, 0, 128) # Jumps to set color
Changing Modes
MagicHue bulb has built-in patterns.
Check current mode:
print(light.mode) # <Mode: NORMAL>
print(light.mode.name) # 'NORMAL'
print(light.mode.value) # 97
Set current mode:
light.mode = magichue.RAINBOW_CROSSFADE
These are the built-in modes:
RED_GRADUALLY
GREEN_GRADUALLY
BLUE_GRADUALLY
YELLOW_GRADUALLY
PURPLE_GRADUALLY
WHITE_GRADUALLY
BLUE_GREEN_GRADUALLY
RAINBOW_CROSSFADE
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 a Mode
The instance member speed is a float value from 0 to 1:
light.speed = 0.5 # set speed to 50%
Creating 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 tuples. Max length of 17 tuples.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magichue-0.2.9.2.tar.gz.
File metadata
- Download URL: magichue-0.2.9.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6835731140fc3788a3029f72f97ee001fe0b2cefe6543e2b4b47a3f13e0d1d4d
|
|
| MD5 |
39f088d124e101a8f47319c44050a385
|
|
| BLAKE2b-256 |
3f38cbedd5d077b5e503a2d2c0b8594aacc6cef0f3ae2e5d9de995177c1615a8
|
File details
Details for the file magichue-0.2.9.2-py3-none-any.whl.
File metadata
- Download URL: magichue-0.2.9.2-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38122bde2d1ceff1d773fdd14301880c46578003f639b5974f3da2dc379f0291
|
|
| MD5 |
63535546bd24c74fd386f429c126a618
|
|
| BLAKE2b-256 |
005a497d82ccc0dc855390265e2462174a29a0a88e4e52f7077e1041b37d176a
|