Giuseppe Parrello

 

How to manage MagicHome Smart devices


In this page I provide you with script codes in order to manage MagicHome Smart devices, mainly led controllers and bulbs.


Command Line

To manage MagicHome Smart devices via the command line, please take note of the following requirements:

To manage the MagicHome Smart devices, just run the command "flux_led" followed by some parameters. To get a list of available parameters, run the command "flux_led --help", the following output shows the parameters that can be used with the command "flux_led":

Usage: usage: flux_led [-sS10cwpCiltThe] [addr1 [addr2 [addr3] ...].

A utility to control Flux WiFi LED Bulbs.

Options:
  -h, --help            show this help message and exit
  -s, --scan            Search for bulbs on local network
  -S, --scanresults     Operate on scan results instead of arg list
  -i, --info            Info about bulb(s) state
  --getclock            Get clock
  --setclock            Set clock to same as current time on this computer
  -t, --timers          Show timers
  -T NUM MODE SETTINGS, --settimer=NUM MODE SETTINGS
                        Set timer. NUM: number of the timer (1-6). MODE:
                        inactive, poweroff, default, color, preset, or
                        warmwhite. SETTINGS: a string of settings including
                        time, repeatdays or date, and other mode specific
                        settings.   Use --timerhelp for more details.
  --protocol=PROTOCOL   Set the device protocol. Currently only supports
                        LEDENET

  Program help and information option:
    -e, --examples      Show usage examples
    --timerhelp         Show detailed help for setting timers
    -l, --listpresets   List preset codes
    --listcolors        List color names

  Power options (mutually exclusive):
    -1, --on            Turn on specified bulb(s)
    -0, --off           Turn off specified bulb(s)

  Mode options (mutually exclusive):
    -c COLOR, --color=COLOR
                        Set single color mode.  Can be either color name, web
                        hex, or comma-separated RGB triple
    -w LEVELWW, --warmwhite=LEVELWW
                        Set warm white mode (LEVELWW is percent)
    --coldwhite=LEVELCW
                        Set cold white mode (LEVELCW is percent)
    -p CODE SPEED, --preset=CODE SPEED
                        Set preset pattern mode (SPEED is percent)
    -C TYPE SPEED COLORLIST, --custom=TYPE SPEED COLORLIST
                        Set custom pattern mode. TYPE should be jump, gradual,
                        or strobe. SPEED is percent. COLORLIST is a space-
                        separated list of color names, web hex values, or
                        comma-separated RGB triples

  Other options:
    -v, --volatile      Don't persist mode setting with hard power cycle (RGB
                        and WW modes only).

Most of the parameters require the IP address of the Smart device, for example if the IP address of the Smart device is 192.168.1.20, to know the current state of the device just run the command "flux_led -i 192.168.1.20".
For a list of usage examples, just run the command "flux_led -e", while for a list of setting timers, just run the command "flux_led --timerhelp".
With the command line, it is also possible to set a color flow, one example is the command " flux_led 192.168.1.20 -C gradual 65 "#0029ff #00ff00 #0000ff #ffff00" " to have a gradual flow blue/green/blue/yellow at 65% speed.

 

Python language

The following script shows some information about the MagicHome Smart device, turns the device off and on, sets the Red color and brightness to 20%, after 5 seconds sets the Green color and brightness to 50%, finally after 5 seconds sets the Blue color and brightness to 100% and returns to the default color:

import time
from flux_led import WifiLedBulb

bulbipaddress = "192.168.1.20"

def main():
    bulb = WifiLedBulb(bulbipaddress)
    print (bulb)
    bulb.refreshState()
    redcolor, greencolor, bluecolor = bulb.getRgb()
    bulbstatus = bulb.isOn()
    brightnessval = bulb.brightness
    print("Turn off bulb")
    bulb.turnOff()
    time.sleep(2)
    print("Turn on bulb")
    bulb.turnOn()
    time.sleep(2)
    print("Set Red color + 20% brightness")
    bulb.setRgb(255,0,0, brightness=20)
    time.sleep(2)
    print("Set Green color + 50% brightness")
    bulb.setRgb(0,255,0, brightness=50)
    time.sleep(2)
    print("Set Blue color + 100% brightness")
    bulb.setRgb(0,0,255, brightness=100)
    time.sleep(2)
    print("Set default color")
    bulb.refreshState()
    bulb.setRgb(redcolor, greencolor, bluecolor, brightness=brightnessval)
    
if __name__ == '__main__':
    main()

The following script turns on the MagicHome Smart device, sets a gradual color flow for 10 seconds, sets the same color flow but in Jump mode for 10 seconds, sets the same color flow but in Strobo mode for 10 seconds, and finally returns to the default color:

import time
from flux_led import WifiLedBulb, utils

bulbipaddress = "192.168.1.20"

def getPatternColors(color_list_str):
    str_list = color_list_str.split(' ')
    color_list = []
    for s in str_list:
        c = utils.color_object_to_tuple(s)
        if c is not None:
            color_list.append(c)
        else:
            raise Exception
    return color_list

def main():
    bulb = WifiLedBulb(bulbipaddress)
    bulb.refreshState()
    bulb.turnOn()
    redcolor, greencolor, bluecolor = bulb.getRgb()
    color_list = getPatternColors("#0029ff #00ff00 #0000ff #ffff00")
    print("Set gradual flow")
    bulb.setCustomPattern(color_list, 100, "gradual")
    time.sleep(10)
    print("Set jump flow")
    bulb.setCustomPattern(color_list, 100, "jump")
    time.sleep(10)
    print("Set strobe flow")
    bulb.setCustomPattern(color_list, 100, "strobe")
    time.sleep(10)
    print("Set default color")
    bulb.refreshState()
    bulb.setRgb(redcolor, greencolor, bluecolor)
    
if __name__ == '__main__':
    main()