GithubHelp home page GithubHelp logo

flux_led's Introduction

Python package codecov
Python Versions PyPi Project
GitHub Activity License
GitHub Top Language

Magic Home / Surp Life / flux_led

This is a utility for controlling stand-alone Magic Home and Surp Life devices manufactured by Zengge. The protocol was reverse-engineered by studying packet captures between a bulb and the controlling "Magic Home" mobile app. The code here dealing with the network protocol is littered with magic numbers, and ain't so pretty. But it does seem to work!

So far most of the functionality of the apps is available here via the CLI and/or programmatically.

The classes in this project could very easily be used as an API, and incorporated into a GUI app written in PyQt, Kivy, or some other framework.

Minimum python version

3.7

Available:
  • Discovering bulbs on LAN
  • Turning on/off bulb
  • Get state information
  • Setting "warm white" mode
  • Setting single color mode
  • Setting preset pattern mode
  • Setting custom pattern mode
  • Reading timers
  • Setting timers
  • Sync clock
  • Music Mode for devices with a built-in microphone (asyncio version only)
  • Remote access administration (asyncio version only)
  • Device configuration including wiring order, ic type, pixels, etc (asyncio version only)
Some missing pieces:
  • Initial administration to set up WiFi SSID and passphrase/key.
Cool feature:
  • Specify colors with names or web hex values. Requires that python "webcolors" package is installed. (Easily done via pip, easy_install, or apt-get, etc.) Use --listcolors to show valid color names.
Installation:
pip install flux_led
Examples:
Scan network:
	flux_led -s

Scan network and show info about all:
	flux_led -sSti

Turn on:
	flux_led 192.168.1.100 --on
	flux_led 192.168.1.100 -192.168.1.101 -1

Turn on all bulbs on LAN:
	flux_led -sS --on

Turn off:
	flux_led 192.168.1.100 --off
	flux_led 192.168.1.100 --0
	flux_led -sS --off
	
Set warm white, 75%
	flux_led 192.168.1.100 -w 75 -1

Set fixed color red :
	flux_led 192.168.1.100 -c Red
	flux_led 192.168.1.100 -c 255,0,0
	flux_led 192.168.1.100 -c "#FF0000"
	
Set preset pattern #35 with 40% speed:	
	flux_led 192.168.1.100 -p 35 40
	
Set custom pattern 25% speed, red/green/blue, gradual change:
	flux_led 192.168.1.100 -C gradual 25 "red green (0,0,255)"

Sync all bulb's clocks with this computer's:
	flux_led -sS --setclock
		
Set timer #1 to turn on red at 5:30pm on weekdays:
	flux_led 192.168.1.100 -T 1 color "time:1730;repeat:12345;color:red"
	
Deactivate timer #4:
	flux_led 192.168.1.100 -T 4 inactive ""

Use --timerhelp for more details on setting timers
Show help:
$ flux_led -h
Usage: usage: __main__.py [-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.

  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 LEVEL, --warmwhite=LEVEL
                        Set warm white mode (LEVEL 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


Supported Models

The following models have been tested with library.

Model Description Microphone Notes
0x01 Legacy RGB Controller no Original protocol
0x03 Legacy CCT Controller no Original protocol
0x04 UFO Controller RGBW no
0x06 Controller RGBW no
0x07 Controller RGBCW no
0x08 Controller RGB with MIC yes
0x09 Ceiling Light CCT no
0x0E Floor Lamp RGBCW no
0x10 Christmas Light no
0x16 Magnetic Light CCT no
0x17 Magnetic Light Dimmable no
0x1A Christmas Light no
0x1C Table Light CCT no
0x1E Ceiling Light RGBCW no
0x21 Bulb Dimmable no
0x25 Controller RGB/WW/CW no Supports RGB, RGBW, RGBWW, CW, DIM
0x33 Controller RGB no
0x35 Bulb RGBCW no
0x41 Controller Dimmable no
0x44 Bulb RGBW no
0x52 Bulb CCT no
0x54 Downlight RGBW no
0x62 Controller CCT no
0x93 Switch 1 Channel no
0x97 Socket no
0xA1 Addressable v1 no Supports UCS1903, SM16703, WS2811, WS2812B, SK6812, INK1003, WS2801, LB1914
0xA2 Addressable v2 yes Supports UCS1903, SM16703, WS2811, WS2811B, SK6812, INK1003, WS2801, WS2815, APA102, TM1914, UCS2904B
0xA3 Addressable v3 yes Supports WS2812B, SM16703, SM16704, WS2811, UCS1903, SK6812, SK6812RGBW (WS2814), INK1003, UCS2904B
0xA4 Addressable v4 no Supports WS2812B, SM16703, SM16704, WS2811, UCS1903, SK6812, SK6812RGBW (WS2814), INK1003, UCS2904B
0xA6 Addressable v6 yes Supports WS2812B, SM16703, SM16704, WS2811, UCS1903, SK6812, SK6812RGBW (WS2814), INK1003, UCS2904B
0xA7 Addressable v7 yes Supports WS2812B, SM16703, SM16704, WS2811, UCS1903, SK6812, SK6812RGBW (WS2814), INK1003, UCS2904B
0xE1 Ceiling Light CCT no
0xE2 Ceiling Light Assist no Auxiliary Switch not supported

Untested Models

The following models have not been tested with the library but may work.

Model Description Microphone Notes
0x02 Legacy Dimmable Controller no Original protocol, discontinued

Unsupported Models

The following models are confirmed to be unsupported.

Model Description Microphone Notes
0x18 Plant Grow Light no
0x19 Socket with 2 USB no
0x1B Aroma Fragrance Lamp no
0x1D Fill Light no
0x94 Switch 1c Watt no
0x95 Switch 2 Channel no
0x96 Switch 4 Channel no
0xD1 Digital Time Lamp no

Known Vendors

File Structure

device.py -> contains code to manipulate device as well as get any information from device that's needed.
fluxled.py -> command line code for flux_led.
pattern.py -> contains code to identify pattern as well as set patterns.
protocol.py -> contains communication protocol to communicate with differnt devices.
scanner.py -> contins scanner to scan network and identify devices on network.
sock.py -> contains code to communicate on network.
timer.py -> contains code to support setting timers on devices and getting timer information from devices.
utils.py -> contains helpers to calculate differnt parameters such as color, cct, brightness etc.

flux_led's People

Contributors

bdraco avatar beville avatar brianegge avatar chefsslaad avatar claudobahn avatar danielhiversen avatar dramamoose avatar icemanch avatar nalt avatar oblogic7 avatar shortbloke avatar tchellomello avatar wgraba avatar wuub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flux_led's Issues

Support for Christmas lights 0x1A / 0x10 (aka 6 LED Fairylights)

I have a Lytworks Smart Fairy Lights. It's a string of 300 Fairy Lights with a IR RGB Controller JT-WF-RGB-03 which reports back as a AK001-ZJ2147
I get a raw state of:
129,26,35,37,1,0,100,8,0,0,1,0,6,87,
There is 7 colours that can be set onto the string.
Setting all 6 leds to blue is:

0b0b1b2b3000101080034a0000600010000ff0000ff00020000ff0000ff00030000ff0000ff00040000ff0000ff00050000ff0000ff00060000ff0000ffaf62

red

b0b1b2b3000101070034a000060001ff00000000ff0002ff00000000ff0003ff00000000ff0004ff00000000ff0005ff00000000ff0006ff00000000ffaf61

Set Blue-red-blue-red-blue-red

Set Blue
b0b1b2b30001010b0034a0000600010000ff0000ff0002ffff000000ff00030000ff0000ff0004ffff000000ff00050000ff0000ff0006ffff000000ffac5f

Query
b0b1b2b30001010c0004818a8b9604
b0b1b2b30001010c000e811a23280000640f000001000660a2

Set Red
b0b1b2b30001010d0034a0000600010000ff0000ff0002ff00000000ff00030000ff0000ff0004ff00000000ff00050000ff0000ff0006ff00000000ffaf67

Fairly sure the frames in the middle are querying the current state. There is also a stack of presets from 1-100, and able to set a cycle.

Any suggestions on debugging the frames as the first 4 bytes look standard magic, then 0101 and a counter, then the colours.

Any help would be appreciated.

CONF_CUSTOM_EFFECT_COLORS not defaulted to []

On startup:

2021-10-18 07:16:06 ERROR (MainThread) [homeassistant.components.light] Error while setting up flux_led platform for light
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/flux_led/light.py", line 272, in async_setup_entry
    list(custom_effect_colors),
TypeError: 'NoneType' object is not iterable

It would appear the CONF_CUSTOM_EFFECT_COLORS can return empty, and then the literal_eval returns None:

custom_effect_colors = ast.literal_eval(
            options.get(CONF_CUSTOM_EFFECT_COLORS) or "[]"
        )

Automatically identify LEDENET devices

The second byte of the state string determines the type of device and the protocol it speaks. Do you have any dumps of that for the LEDENET systems? I've been figuring out how to use this to determine whether a device is RGB+W or true RGBW as well.

RGB + W combinations in single command - enhancement

I'm using some RGB 4-in-1 chip LED light strips and was trying to get the broadest colour spectrum possible by using combinations of the dedicated White LED cell in conjunction with the RGB LED cell. This allows for a range of pastel shades, though you tend to need to keep the % of white fairly low to see a difference.
After playing with the HASS UI there were times when I did end up with both LEDs on, and other times when I couldn't. So I thought I'd check what was possible in the module HASS uses.

I found I could get the desired effect, but only though sending two commands, as it's not possible to pass an RGB colour at the same time as the % White. For example:

python -m flux_led 192.168.200.58 -c 25,40,20 --on
python -m flux_led 192.168.200.58 -w 2 --on

If I wanted to leave the colour and remove the white, I couldn't use the off command, as this turns all of them off. Instead I had to set the white % to zero but set the light still to be on.
python -m flux_led 192.168.200.58 -w 0 --on

It would be a nice enhancement to be able to combine -c and -w values in a single command. How this would then be handled by the HASS UI, I'm not yet sure.

Feature request: Bluetooth support

The flux_led/BL602L20 based controllers seem to support bluetooth out of the box even if they're labeled as Wifi.
Are there any plans of supporting the BT control?

homebridge-magichome-platform

Hello there,

as you might know this is used in the homebridge-magichome-platform plugin. This will form a bridge between Apples HomeKit and Magic Home Home controllers. But it seams as if this project is no longer maintained. This is why I'm asking you. Do you have any ideas, why this is happening?

There is an issue, through wich this script uses a lot of cpu time. ps -aux reports:

python /usr/lib/node_modules/homebridge-magichome-platform/src/flux_led.py 10.0.0.252 -i

Restarting node solves the problem but I would like some other fix.

support for wifi370 led strip controllers

I have an (older?) wifi led strip controller, described as wifi370 on the box.
https://nl.aliexpress.com/item/Original-Wifi-RGB-LED-controller-for-Iphone-Ipad-Android-mobile-phone-2-3Version-IOS-system-DC7/1032823060.html

this device is supported by the magic home app, and it seems to be a 'propper' flux_led device, but it has some significant differences.

this library recognizes it while scanning, but this device uses a different set of commands and does not use a checksum to send data.
eg, turn on is CC 23 33 rather than 71 23 0F
status is EF 01 77 rather than 81 8A 8B

this device also returns only 11 bytes of status rather than the 14 this library expects.

I managed to do a python conversion based on https://github.com/sidoh/ledenet_api

it can be found here: https://github.com/marcwagner/alarmclock/blob/master/ledenet_api.py

I can probably integrate my code into this project so that it can also work with homeassistant. However, due to some of the differences I am worried about breaking compatibility.

so, two questions: should I integrate my code and is there an easy way to recognize the different flavors of protocol?

Mode always returns "DIM"

My device is a Controller RGB/WW/CW (0x25).

This is the code I used:

import asyncio
import logging
import pprint

from flux_led.aiodevice import AIOWifiLedBulb

logging.basicConfig(level=logging.DEBUG)

ip = "192.168.1.160"

async def go():
    bulb = AIOWifiLedBulb(ip)

    def _async_updated():
        pprint.pprint(["State Changed!", bulb.raw_state])

    await bulb.async_setup(_async_updated)

    print(bulb.operating_mode)

    await bulb.async_set_device_config(operating_mode="RGB")

    await bulb.async_update();

    print(bulb.operating_mode)


asyncio.run(go())

and this is the output:

DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:flux_led.aioprotocol:('192.168.1.160', 5577) => 0x81 0x8A 0x8B 0x96 (4)
DEBUG:flux_led.aioprotocol:('192.168.1.160', 5577) <= 0x81 0x25 0x24 0x61 0x21 0x13 0x26 0x26 0x26 0x00 0x01 0x00 0x00 0xD2 (14)
DEBUG:flux_led.base_device:192.168.1.160: set_available: Received message 81252461211326262600010000d2
DEBUG:flux_led.base_device:192.168.1.160: State: LEDENETRawState(head=129, model_num=37, power_state=36, preset_pattern=97, mode=33, speed=19, red=38, green=38, blue=38, warm_white=0, version_number=1, cool_white=0, color_mode=0, check_sum=210)
DEBUG:flux_led.base_device:192.168.1.160: unmapped raw state: 129,37,36,97,33,19,38,38,38,0,1,0,0,210,
DEBUG:flux_led.base_device:192.168.1.160: Mapped State: LEDENETRawState(head=129, model_num=37, power_state=36, preset_pattern=97, mode=33, speed=19, red=38, green=38, blue=38, warm_white=0, version_number=1, cool_white=0, color_mode=0, check_sum=210)
['State Changed!',
 LEDENETRawState(head=129, model_num=37, power_state=36, preset_pattern=97, mode=33, speed=19, red=38, green=38, blue=38, warm_white=0, version_number=1, cool_white=0, color_mode=0, check_sum=210)]
DEBUG:flux_led.aiodevice:192.168.1.160: device_config: wiring=None operating_mode=DIM
DIM
DEBUG:flux_led.aioprotocol:('192.168.1.160', 5577) => 0x62 0x03 0x0F 0x74 (4)
DEBUG:flux_led.aioprotocol:('192.168.1.160', 5577) => 0x81 0x8A 0x8B 0x96 (4)
DIM

Cannot set 0 brightness for warm white channel

The following command/argument list:

python -m flux_led -w 0 1.2.3.4

Returns the following error message:

Usage: usage: __main__.py [-sS10cwpCiltThe] [addr1 [addr2 [addr3] ...].

__main__.py: error: An operation must be specified

Zero percent does not seem to be recognized as a valid brightness setting.

One percent does work:

 python -m flux_led -w 1 1.2.3.4

Hao Deng Mesh Downlight Support

I recently picked up some Zengge/HaoDeng/MagicHome/MagicHue (who's to say..) recess downlights, which are BLE mesh, and have a gateway. I've gone down a number of rabbit holes, but this component seems most promising, but it won't connect to the gateway locally. I can telnet to it on port 5577 though. Might be a case of the plugin always expecting a single light where technically these would present as an array of 1 or more of them when backhauled over the mesh.

https://www.amazon.com/gp/product/B0974P1459/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&th=1

My other thought was to try and create a ble/wifi bridge on esphome, but that will not be fun.

tks

Question: android implementation

Hello,

I'm using this script instead of the MagicHome app becouse this one actually WORKS!

Has anyone tried to create a GUI for this app? Typing command lines in android is not very pleasant.

Setting brightness is not supported.

I'm currently implementing a Domoticz plugin using your library as api to handle the command to the real devices.
So far, i have succeeded in a basic setup, but when i want to set the brightness (or level) is "screws" up the brightness in the device, and sets it to 0.
There is no function available for setting the brightness regardless of the mode. so i use the getrgb, calculate the incoming value in 255 scale and call setrgbw with that calculated brightness

Older firmwares split responses into multiple packets

2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) => 0x81 0x8A 0x8B 0x96 (4)
2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) <= 0x81 (1)
2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) <= 0x54 0x23 0x61 (3)
2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) <= 0x21 0x1F 0x59 0x22 (4)
2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) <= 0xFF 0x00 (2)
2021-11-04 16:54:14 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.210.39', 5577) <= 0x04 0x00 0xF0 0x07 (4)

Cold white mode not properly supported on newer bulbs

This encompasses two issues: warm white mode isn't set correctly, and there is a new bulb type hex value.

comment says:

# LEDENET devices support two white outputs for cold and warm. We set
# the second one here - if we're only setting a single white value,
# we set the second output to be the same as the first

This doesn't seem like the right thing to do, because on my newer bulbs it causes both the warm and cold lights to be activated at the same time, resulting in a not-warm appearance. Simply appending 00 fixes the issue.

The new bulb type is 0x35. Example messages: 8135236101050000000007ff0f55

I'm making a PR for these issues

Next Release timing with updates?

Not sure if this should be asked as an issue or some other way.

When will the next release go out and pypy updated?

I'm asking because some of the fixes from the last commit will help the integration being worked on in Home Assistant. There's also another pull I'm going to propose to fix some of the output from the code that was added in my last pull request. It'd be great to have it added before another release.

Thanks for your time.

Use non-zero exit code if command fails?

Hi there,

Love the project, awesome work.

I just have one request: I might be able to do it if I have time to go through the code, but I have a set of lights that don't connect consistently to my wifi. If I use flux_led via bash in Linux, I'll have errors, like

Unable to connect to bulb at [redacted_ip]: bytearray index out of range

or

Unable to connect to bulb at [10.0.0.16]: timed out

...Which, if my strip isn't available, makes sense.

That's an error condition-- I realize that the script loops through bulbs to try and set them all, but the sys.exit(0) at the end doesn't give an indication to a shell script that there may have been errors based on the exit code.

Would you be willing to change this, or would you accept a pull request?

Devices appear off when turned on and don't react to commands

Since updating to HA 2023.8 I have issues with my Magic Home RGBCCT wifi led controllers (AK001-ZJ2101, firmware 1.06). I have 4 of them and they all misbehave since the update:

  1. When turned on, they turn on with the last color and brightness instead of the one I requested
  2. After being turned on, they report that they have turned off, but they are actually turned on:
    image
    image
  3. Once turned on commands to change the color or brightness don't work.
  4. Turning the devices off works correctly

Changing the color or brightness is only possible after the device has been turned on but before HA reports that it's off. Therefore chaging the color now requires three steps:

  1. Turn off
  2. Turn on
  3. Set color

I checked the behaviour with the native app using local control and the device indeed reports that it's turned off after it was turned on via HA. However, if I disable the HA integration then they behave correctly in the Magic Home app.

Relevant error logs:
image

Release to pypi

Hi!
Can you please release v 0.2.3 of flux_led to pypi?

Thanks!

Can't set colors or brightness

Using Ledenet strip module. Only the functions/animations, on off works but not set color
Any help would be greatly appreciated

Magic Home SPI controller - not working

Hi,

I've a "Magic Home SPI Controller v3" with a WS2812B. It seems it only partially works.
When running a scan-command (-s) i get a valid response:

1 bulbs found
  2CF443C91854 192.168.11.220    (mac is modified)

When i run a "-i 192.168.11.220" command i get this exception:

  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python37\lib\site-packages\flux_led\__main__.py", line 1830, in <module>
    main()
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python37\lib\site-packages\flux_led\__main__.py", line 1807, in main
    print("{} [{}] {}".format(info['id'], info['ipaddr'], bulb))
  File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python37\lib\site-packages\flux_led\__main__.py", line 736, in __str__
    pattern = rx[3]
TypeError: 'NoneType' object is not subscriptable

I did some debugging and saw what the issue is... One of the responses is:

81 a1 23 00 64 64 2a d5 00 02 03 00 59 6b	= solid color
81 a1 23 00 65 64 2a d5 00 02 03 00 59 6b	= function 1
81 a1 23 00 66 64 00 00 47 02 03 00 59 b4    = function 2
81 a1 23 00 67 64 ff ff ff 02 03 00 59 6b    = function 3

Initial pairing instructions

Hi,

as the app did not work for my led strip (AK001-ZJ200 as reported by HF-A11ASSISTHREAD), I decided to dig a bit how to do it without the app and wrote this up just in case someone else wants to do the same, or if someone wants to try to integrate this to the code-base.

I found a link to a spec sheet from https://github.com/vikstrous/zengge-lightcontrol which describes the 48899 port communication to some extent: http://www.hi-flying.com/downloadsfront.do?method=picker&flag=all&id=dc406e44-84ec-4be1-ab11-a4ce403f6d3f&fileId=0f147d14-d0aa-4fc8-b01f-36e43418d19d .

For starters you must connect to the network advertised by the device LEDnetXXXX or similar.
It should also be noted that some commands require passing a \r while others do not.
On successful commands this device yields +ok= (for queries followed by the response).

The wifi mode can be queried and set with the AT+WMODE command, so the first step was to change the controller from AP to STA mode:

echo 'AT+WMODE=STA\r' | nc -u  10.10.123.3 48899

This device required STA all uppercase, a diversion from that spec sheet.

Setting the SSID and the key worked as follows:

echo 'AT+WSSSID=<NETWORK>' | nc -u 10.10.123.3 48899
echo 'AT+WSKEY=WPA2PSK,AES,<PASSWORD>' | nc -u 10.10.123.3 48899

The first two parameters needs to be adjusted accordingly depending on used encryption mode and cipher, this device accepted only all-uppercase variants. Note that adding \r after the password would include that in it, the same is probably true for the name of the network.

After that the device can be rebooted and will hopefully connect to the network:

echo 'AT+Z\r' | nc -u 10.10.123.3 48899

Apparently some sort of software version can be requested by using VER, FVER and/or LVER, on my device only LVER did give a response:

AT+LVER\r
+ok=33_17_20170825_IR

It would be nice to have this integrated into this library & script, but I don't unfortunately have time for it. Hopefully this can be helpful to someone who wants to implement it, and maybe it helps someone who is looking into how to get these paired without the official "magic home" app.

Add output channel remap ability

There seems to be some discrepancies between different LED strip manufacturers on what color wires mean what, or which bytes control which output channels.

To minimize confusing wiring or electrical work, support the ability to remap output channels per-device. Once the mapping is determined for the device, interacting with the flux_led API should be able to cause colors to change correctly (ie, setting the red channel value in the API causes the red LED's to turn on on the strip).

Magic Home Gradient On/Off Function?

Hello! I'm pretty new to HA and ultra new to Flux/Magic Home as I'm trying to get my fish tank light integrated into HA for gradual on/off as well as being able to control it from my dashboard. I'm using a Lominie 4 Channels WiFi Controller for Upgraded F20 S120 P80 S20 P30 (WiFi-4 Channels) which is getting picked up as an 0x6 device by the Magic Home integration.

I'm running HA Container as I'm running all my HA stuff on a Ubuntu machine. The light is found via the Magic Home integration with no problem and basic controls like turning the light on/off, as well as jumping between "colors" (the light isn't true RGB as it's it's just using different white lights for those channels).

I saw in the Magic Home App that there is the ability to do gradient on/off. Is this something that could be brought into the Flux_led/Magic Home integration? It would be awesome to have my HA trigger the gradient on/off at various times, as it's currently not possible within the Magic Home App to schedule a gradient on/off event..

Attached is a copy of the diagnostics for the controller if it will help and provide any insight.

I've tried writing a few different scripts including using a float for "transition" thinking maybe that would get it to work, but I've had no luck. Maybe I'm just missing something, or maybe it's not implemented yet (as this appears to be a newish controller).

Any help would be appreciated. Thanks!

config_entry-flux_led-5afc1c443403de0f6e305599c965a57c.json.txt

Documentation is out of date

  1. led_flux.py does not exist.
  2. Installing via pip works however however python -m flux_led fails with
No module named flux_led.__main__; 'flux_led' is a package and cannot be directly executed
  1. The section Set warm white, 75% says to use -0 but this turns the light off.

I was able to find a workaround for (1) and (2) by executing flux_led/__init__.py directly.

Home Assistant Component flux_led needs speed setting

flux_led.py in home assistant sends effects like so:

if effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)

Could the speed setting, set as 50 in this case, be set by the user when they send the effect?

Distinguish RGB and RGBW LED Controllers

Hello Dear.

I have RGB and RGBW led controller and i want to distinguish these two type of LEDs.

Is there any command that determined whether the led is RGB or RGBW?

Thank you.

5 channel RGBWW controller support; header 0x8125

@gerth2 and I have a controller that uses a variation of the LEDENET controller: https://www.amazon.com/gp/product/B01DY56N8U/

We've had some discussions over in this WIP PR: #42

Basically, we both get packets from the controller that look like this (14 bytes):

81 25 23 61 21 06 38 05 06 f9 01 00 0f 9d
0 Unknown
1 Type?
2 On/Off (23/24)
3 Effect
4 Unknown
5 Speed
6 Red
7 Green
8 Blue
9 Warm White
10 Unknown (always 01 so far)
11 Cold White
12 White/Color mode (f0 when colors were set, 0f when whites were set)
13 Checksum (I think?)

The Magic Color app sends packets that look like this (9 bytes):

31 bc c1 ff 00 00 f0 0f ac
31 00 00 00 d9 8a 0f 0f b2
0 Command
1 Red
2 Green
3 Blue
4 Warm White
5 Cold White
6 Write mode (f0 for color, 0f for white) -- should try ff to see if both can be written
7 Unknown
8 Checksum

@mjg59 you may be interested in the details here, as it seems related to #22 although with a different protocol variation.

Edit: corrected white/color mode byte meaning in status packet

Add RGBCW Light control?

Hi,

This doesn't support my RGBCW lights and I wanted to see if it could with some a minor adjustments. A fix may be near line 700 where the mode code for this light responds as 01, interpreted as WW in the comments. It looks a little different in the code however at line 601 where 01 actually registers as DIM and not RGBM. I am curious if then before making a 01 device register as a WW or DIM? light if we could run another conditional to see if it could recognize something closer to a RGBW controller - that might be all it takes to get this working for an RGBCW light.

I have a mockup at home in C# and know the commands well.

Here is an example response from the Magic Light RGBCW device:
RGBCW
# 81 35 24 61 01 05 FE 00 00 00 07 00 0F 55
(this is my RGBCW device response)

#     81 25 23 61 21 06 38 05 06 f9 01 00 0f 9d
#     |  |  |  |  |  |  |  |  |  |  |  |  |  |
#     |  |  |  |  |  |  |  |  |  |  |  |  |  checksum
#     |  |  |  |  |  |  |  |  |  |  |  |  color mode (f0 colors were set, 0f whites, 00 all were set)
#     |  |  |  |  |  |  |  |  |  |  |  cool-white  0x00 to 0xFF
#     |  |  |  |  |  |  |  |  |  |  version number
#     |  |  |  |  |  |  |  |  |  warmwhite  0x00 to 0xFF
#     |  |  |  |  |  |  |  |  blue  0x00 to 0xFF
#     |  |  |  |  |  |  |  green  0x00 to 0xFF
#     |  |  |  |  |  |  red 0x00 to 0xFF
#     |  |  |  |  |  speed: 0x01 = highest 0x1f is lowest
#     |  |  |  |  Mode WW(01), WW+CW(02), RGB(03), RGBW(04), RGBWW(05)
#     |  |  |  preset pattern
#     |  |  off(23)/on(24)
#     |  type
#     msg head

(this is the response expected taken from code - note Mode does not define RGBCW accurately for this device and the comments are a little different than the code.) At least maybe update the comments from
# | | | | Mode WW(01), WW+CW(02), RGB(03), RGBW(04), RGBWW(05)
to
# | | | | Mode(if61) DIM(01), CCT(02), RGB(03), RGBW(04), RGBWW(05)
and if we can include RGBCW lights to
# | | | | Mode(if61) DIM+RGBCW(01), CCT(02), RGB(03), RGBW(04), RGBWW(05)

Thank you so much for your help in understanding this one!

Support for MagicLight v7 RGBCW bulbs

I bought these exact bulbs and color control doesn't seem to be working with it in Home Assistant:
https://www.amazon.com/gp/product/B07VQLZBNW/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1

The bulbs display their model number as v7 inside the MagicLight Android app (which is interesting because some older bulbs I purchased that only support rgb show as v8 and work fine).

Setting the color temperature (CCT) from inside the Android app gets the light to use brighter LEDs whereas if you select a color it uses LEDs that aren't nearly as powerful. If the bulb is setup in HA with the mode as rgbw it allows you to control the color temperature but not the color. Even though you can change the color temperature it is very buggy and often times will just turn the bulb off.

These bulbs are incredibly cheap and when using the brighter white LEDs the bulb is actually pretty bright. The main reason I purchased them was to setup some cheap outdoor color bulbs for Christmas/Holiday lighting. I have Hue but $50 per bulb for outdoor color lighting is just too much. At this price point I wouldn't mind buying more bulbs if support was added for them.

If someone needs a bulb to help get this done I would be willing to buy and ship one if it is within the mainland USA.

wrong members accessed from webcolors package

Not sure what webcolors version is expected, but:

❯ flux_led --listcolors
Traceback (most recent call last):
  File "/home/francisco/.local/bin/flux_led", line 8, in <module>
    sys.exit(main())
  File "/home/francisco/.pyenv/versions/flux_led/lib/python3.9/site-packages/flux_led/__main__.py", line 1718, in main
    (options, args) = parseArgs()
  File "/home/francisco/.pyenv/versions/flux_led/lib/python3.9/site-packages/flux_led/__main__.py", line 1655, in parseArgs
    for c in utils.get_color_names_list():
  File "/home/francisco/.pyenv/versions/flux_led/lib/python3.9/site-packages/flux_led/__main__.py", line 110, in get_color_names_list
    for key in list(webcolors.css2_hex_to_names.keys()):
AttributeError: module 'webcolors' has no attribute 'css2_hex_to_names'

This member exists in uppercase (CSS2_HEX_TO_NAMES), not lowercase.

Commands for changing strip type/order

Query strip order

63 ...

Setting strip order

RGBW 0x06
62 06 02 0f 79 - RGB/W GRB W
62 04 02 0f 77 - RGB&W GRB W
62 04 01 0f 77 - RGB&W RGB W
62 04 03 0f 77 - RGB&W BRG W

RGBCW 0x07

62 05 0f 0f 85 - RGB&CCT / WCBRG
62 07 0f 0f 87 - RGB/CCT / WCBRG
62 07 01 0f 79 - RGB/CCT / RGBCW
62 07 02 0f 7a - RGB/CCT / GRBCW
62 07 0c 0f 84 - RGB/CCT / CBRGW

RGB 0x33 / 0x08

62 00 01 0f 73 - RGB
62 00 02 0f 73 - GRB
62 00 03 0f 73 - BRG

Query
62 00 02 0f 73
Response
0f 62 00 71
But we can get it all from 0x81

0x25

62 01 0f 72 - DIM
62 02 0f 73 - CCT
62 03 0f 74 - RGB
62 04 0f 74 - RGB&W
62 05 0f 74 - RGB&CCT

0xA1

0000   63 12 21 36 <-- Query
0000   63 00 32 05 00 00 00 00 00 00 02 9c <-- Response

Set

62 08 00 04 00 00 00 00 00 00 02 f0 60 <- set 2048
62 04 00 04 00 00 00 00 00 00 02 f0 5c <- set 1024
62 04 00 04 00 00 00 00 00 00 00 f0 5a

        #pos  0  1  2  3  4  5  6  7  8  9 10 11 12
        #    62 04 00 04 00 00 00 00 00 00 02 f0 5c <- checksum 
        #     |  |  |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  |  |  always 0xf0
        #     |  |  |  |  |  |  |  |  |  |  wiring type (0 indexed, RGB or RGBW)
        #     |  |  |  |  |  |  |  |  |  ?? always 00
        #     |  |  |  |  |  |  |  |  ?? always 00
        #     |  |  |  |  |  |  |  n?? always 00
        #     |  |  |  |  |  |  ?? always 00
        #     |  |  |  |  |  ?? always 00
        #     |  |  |  |  ?? always 00
        #     |  |  |  ic type (01=UCS1903, 02=SM16703, 03=WS2811, 04=WS2812B, 05=SK6812, 06=INK1003, 07=WS2801, 08=LB1914)
        #     |  |  num pixels (16 bit, low byte)
        #     |  num pixels (16 bit, high byte)
        #     msg head
        #

0xA2

0000    63 12 21 0f a5 <-- Query
0000   0f 63 00 32 00 01 01 04 32 01 dd <-- Response

Set

0000   62 00 32 00 01 01 04 32 01 0f dc <-set 50
0000   62 01 2c 00 06 01 04 32 01 0f dc


        #pos  0  1  2  3  4  5  6  7  8  9 10 
        #    62 01 2c 00 06 01 04 32 01 0f dc 
        #     |  |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  |  checksum
        #     |  |  |  |  |  |  |  |  |  ?? always 0x0f
        #     |  |  |  |  |  |  |  |  segments (music mode)
        #     |  |  |  |  |  |  |  num pixels (music mode)
        #     |  |  |  |  |  |  wiring type (0 indexed, RGB or RGBW)
        #     |  |  |  |  |  ic type (01=WS2812B, 02=SM16703, 03=SM16704, 04=WS2811, 05=UCS1903, 06=SK6812, 07=SK6812RGBW, 08=INK1003, 09=UCS2904B)
        #     |  |  |  |  segments
        #     |  |  |  ?? always 00
        #     |  |  num pixels (16 bit, low byte)
        #     |  num pixels (16 bit, high byte)
        #     msg head
        #


0xA3



0000   b0 b1 b2 b3 00 01 01 4f 00 05 63 12 21 0f a5 66
63 12 21 0f a5 <-- Query
0000   b0 b1 b2 b3 00 01 01 4f 00 0b 00 63 00 90 00 01 07 08 90 01 94 4a
63 00 90 00 01 07 08 90 01 94 <-- response
        #pos  0  1  2  3  4  5  6  7  8  9
        #    63 01 2c 00 01 07 08 96 01 45 
        #     |  |  |  |  |  |  |  |  |  |   
        #     |  |  |  |  |  |  |  |  |  |   
        #     |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  checksum
        #     |  |  |  |  |  |  |  |  segments (music mode)
        #     |  |  |  |  |  |  |  num pixels (music mode)
        #     |  |  |  |  |  |  wiring type (0 indexed, RGB or RGBW)
        #     |  |  |  |  |  ic type (01=WS2812B, 02=SM16703, 03=SM16704, 04=WS2811, 05=UCS1903, 06=SK6812, 07=SK6812RGBW, 08=INK1003, 09=UCS2904B)
        #     |  |  |  |  segments
        #     |  |  |  ?? (always 0x00)
        #     |  |  num pixels (16 bit, low byte)
        #     |  num pixels (16 bit, high byte)
        #     msg head
        #

Set

        #pos  0  1  2  3  4  5  6  7  8  9 10
        #    62 01 2c 00 01 07 08 96 01 0f 45  
        #     |  |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  |  |  
        #     |  |  |  |  |  |  |  |  |  |  checksum
        #     |  |  |  |  |  |  |  |  |  ?? (always 0x0f)
        #     |  |  |  |  |  |  |  |  segments (music mode)
        #     |  |  |  |  |  |  |  num pixels (music mode)
        #     |  |  |  |  |  |  wiring type (0 indexed, RGB or RGBW)
        #     |  |  |  |  |  ic type (01=WS2812B, 02=SM16703, 03=SM16704, 04=WS2811, 05=UCS1903, 06=SK6812, 07=SK6812RGBW, 08=INK1003, 09=UCS2904B)
        #     |  |  |  |  segments
        #     |  |  |  ?? (always 0x00)
        #     |  |  num pixels (16 bit, low byte)
        #     |  num pixels (16 bit, high byte)
        #     msg head
        #

https://github.com/Danielhiversen/flux_led/blob/master/flux_led/models_db.py#L120

Brightness only device not working correctly in HomeAssistant

Hi, I have a number of brightness only devices, such as these: https://smile.amazon.com/gp/product/B07J5B3R5L/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

These present themselves in the webui as

Unknown Model (0x21)
by FluxLED/Magic Home
Firmware: 2

and in the debug log

2021-10-17 21:32:46 DEBUG (MainThread) [flux_led.aioprotocol] ('192.168.254.233', 5577) <= 0x81 0x21 0x23 0x61 0x41 0x01 0xFF 0x00 0x00 0x00 0x02 0x00 0x00 0x69 (14)
2021-10-17 21:32:46 DEBUG (MainThread) [flux_led.device] 192.168.254.233: State: LEDENETRawState(head=129, model_num=33, power_state=35, preset_pattern=97, mode=65, speed=1,
red=255, green=0, blue=0, warm_white=0, version_number=2, cool_white=0, color_mode=0, check_sum=105)
2021-10-17 21:32:46 DEBUG (MainThread) [flux_led.device] 192.168.254.233: unmapped raw state: 129,33,35,97,65,1,255,0,0,0,2,0,0,105,

The problem is when I turn them on, the brightness doesn't get set and it stays off. Setting the brightness seems to adjust only the 'w' color, which seems to be ignored by this type of device.

The devices are quite useful, because any number of single color LED devices include a barrel connector and they are plug in play.

The only value you can set for a brightness only device is the 'r' channel I think. My work-around is as follows:

+++ b/homeassistant/components/flux_led/light.py
@@ -256,7 +256,7 @@ async def async_setup_entry(
     try:
         custom_effect_colors = ast.literal_eval(
             options.get(CONF_CUSTOM_EFFECT_COLORS) or "[]"
-        )
+        ) or []
     except (ValueError, TypeError, SyntaxError, MemoryError) as ex:
         _LOGGER.warning(
             "Could not parse custom effect colors for %s: %s", entry.unique_id, ex
@@ -454,7 +454,7 @@ class FluxLight(FluxEntity, CoordinatorEntity, LightEntity):
             return
         # Handle Brightness Only Color Mode
         if self.color_mode == COLOR_MODE_BRIGHTNESS:
-            await self._device.async_set_levels(w=brightness)
+            await self._device.async_set_levels(r=brightness)
             return
         raise ValueError(f"Unsupported color mode {self.color_mode}")

With the above, I can turn it on and off, and slide the brightness in the gui, but the brightness is not reflected back, so it's half working. Sorry - I know the above patch is for the HA component, but it seems like the fix needs to be in the driver or likely both.

When running via HomeAssistant state isn't always correctly reflected

Per issue initially raised against HomeAssistant: home-assistant/core#11565

Investigation showed that raw data received by flux_led running under HASS was different to flux_led running via the command line and appeared to be sensitive as to how quickly/often it was queried.

A simple test program:

import flux_led
from time import sleep
light = flux_led.WifiLedBulb("192.168.200.170")
while True:
    light.update_state(retry=2)
    power_state = light.raw_state[2]
    if power_state == 0x23:
        print("ON")
    elif power_state == 0x24:
        print("OFF")
    sleep(5)

Shows that if you change the sleep interval from 5 to 30 seconds, at 5 second pools changes made to the state of the LEDs is captured, at 30 seconds, it can take several minutes before the raw data reflects the current state.

Littering the code with print statements and checking if any errors or timeout in the socket was occurring showed no such evidence.

I have 4 different device types in use for testing which all exhibit this problem:

  • White UFO (ZJ-WFUF-107F
  • Mini (ZJ-MWIR-RGBW)
  • Sunix White (SU705)
  • Sunix Black (SU794)

RuntimeWarning: Wrong order of execution?

Hi,

if I issue any python -m flux_led ... command, I receive the following runtime warning:

/Users/rene/miniconda3/lib/python3.6/runpy.py:125: RuntimeWarning: 'flux_led.__main__' found in sys.modules after import of package 'flux_led', but prior to execution of 'flux_led.__main__'; this may result in unpredictable behaviour

The commands run fine on the device but I wonder whether this warning could turn into a bug at some point.

Greetings
René

Allow controlling 2.4G remotes

Remote control settings seem possible on these devices (AK001-ZJ2148 and AK001-ZJ2149 verified)

    LEDENETHardware(
        model="AK001-ZJ2148",  # seen on older Addressable v3
        chip=LEDENETChip.BL602,
        rf_remote=True,  # verified
    ),
    LEDENETHardware(
        model="AK001-ZJ2149",  # seen on newer Addressable v3
        chip=LEDENETChip.BL602,
        rf_remote=True,  # verified
    ),

Query
b0 b1 b2 b3 00 01 01 45 00 04 2b 2c 2d 84 19 <-- request: 2.4G remote control settings

Query Responses
b0 b1 b2 b3 00 01 01 5e 00 0e 2b 01 00 00 00 00 29 00 00 00 00 00 00 55 de <-- response: don't allow remotes
b0 b1 b2 b3 00 01 01 45 00 0e 2b 02 00 00 00 00 29 00 00 00 00 00 00 56 c7 <-- response: open to all remotes
b0 b1 b2 b3 00 01 01 5c 00 0e 2b 03 00 00 00 00 29 00 00 00 00 00 00 57 e0 <-- response: only allow specific remotes
b0 b1 b2 b3 00 01 01 e3 00 0e 2b 03 00 02 00 00 00 00 00 00 00 00 00 30 19 <-- '2 remotes, The controller can only be controlled after pairing with the device`

Commands
b0 b1 b2 b3 00 01 01 4e 00 10 2a 01 ff ff ff ff ff 00 00 00 00 00 00 00 0f 35 90 <-- set don't allow remotes
b0 b1 b2 b3 00 01 01 57 00 10 2a 02 ff ff ff ff ff 00 00 00 00 00 00 00 0f 36 9b <-- set open to all remotes
b0 b1 b2 b3 00 01 01 59 00 10 2a 03 ff ff ff ff ff 00 00 00 00 00 00 00 0f 37 9f <-- only allow specific remotes
b0 b1 b2 b3 00 01 01 f3 00 10 2a ff ff 01 ff ff ff 00 00 00 00 00 00 00 f0 16 f7 <-- clear pairings

Support sunrise/sunset timers

Currently timers have no support for sunrise/sunset types. The iPhone app and 2nd generation bulbs support this feature out-of-the-box. The timers allow for gradual warm light brightness changes over a duration (supplied in minutes).

We should be able to read and write this timer state to bulbs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.