Giter VIP home page Giter VIP logo

python-limitlessled's Introduction

Build Status PyPI version

python-limitlessled

python-limitlessled controls LimitlessLED bridges. It supports white, rgbw and rgbww bulb groups as well as the bridge-led of newer wifi bridges.

Install

pip install limitlessled

Usage

Configure

Your bridge(s) must be set up and bulbs joined prior to using this module.

Group names can be any string, but must be unique amongst all bridges.

from limitlessled.bridge import Bridge
from limitlessled.group.rgbw import RGBW
from limitlessled.group.rgbww import RGBWW
from limitlessled.group.white import WHITE

bridge = Bridge('<your bridge ip address>')
bridge.add_group(1, 'bedroom', RGBW)
# A group number can support two groups as long as the types differ
bridge.add_group(2, 'bathroom', WHITE)
bridge.add_group(2, 'living_room', RGBW)
bridge.add_group(2, 'kitchen', RGBWW)

Get access to groups either via the return value of add_group, or with the LimitlessLED object.

bedroom = bridge.add_group(1, 'bedroom', RGBW)
# or
limitlessled = LimitlessLED()
limitlessled.add_bridge(bridge)
bedroom = limitlessled.group('bedroom')

# The bridge led can be controlled and acts as a RGBW group
bridge_led = bridge.bridge_led

Control

Turn on:

bedroom.on = True

Change brightness:

bedroom.brightness = 0.5 # 0.0 through 1.0

Change temperature (white groups only)

bedroom.temperature = 0.5 # 0.0 through 1.0

Change color (rgbw groups only)

LimitlessLED RGBW bulbs can represent only the hue component of RGB color. There are 256 possible values, starting with blue as 0. Maximum saturation and value are always used. This means that most RGB colors are not supported. There are two special cases: Black (0, 0, 0) is simply all LEDs turned off. White (255, 255, 255) is the RGB LEDs off and the white LED on. Note that the actual color of the white LED depends on whether the bulb is a cool white or a warm white bulb.

from limitlessled import Color
bedroom.color = Color(255, 0, 0) # red

Transition

bedroom.transition(brightness=1.0, temperature=0.1) # white groups

from limitlessled import Color
bedroom.transition(brightness=1.0, color=Color(0, 255, 0)) # rgbw groups

Pipelines

Pipelines specify a sequence of stages, each stage being a command. Pipelines are not executed until called as an argument to a group's enqueue method.

Pipelines are executed in a thread (per group). Multiple pipelines can be started on a group; they will queue and execute in the order received.

A bridge can run multiple pipelines concurrently provided they are on different groups. Note that concurrency is achieved by interleaving commands, and as a consequence, pipeline execution can take longer than specified and each pipeline may use fewer transition steps depending on the number of concurrently executing pipelines.

from limitlessled import Color
from limitlessled.pipeline import Pipeline

pipeline = Pipeline() \
    .on() \
    .brightness(0.7) \
    .color(0, 0, 255) \
    .transition(color=Color(255, 0, 0))
    
bedroom.enqueue(pipeline)

Stop the currently-running pipeline:

bedroom.stop()
Commands

Turn on

Pipeline().on()

Turn off

Pipeline().off()

Set brightness

Pipeline().brightness(0.5)

Set temperature

Pipeline().temperature(0.5)

Set color

Pipeline().color(255, 0, 0)

Transition

Pipeline().transition(...)

Wait

Pipeline.().wait(4) # in seconds

Repeat

stages is how many previous stages to repeat iterations is how many times to repeat stages

Default stages is 1, default iterations is infinite.

Pipeline().repeat(stages=2, iterations=3)

Callback

def my_function():
    pass

Pipeline().callback(my_function)

Append

p1 = Pipeline.off()

p2 = Pipeline.on().append(p1)

Contributions

Pull requests welcome. Some areas for enhancement include

  • Discovery
  • Pairing

Disclaimer

Not affiliated with LimitlessLED and/or marketers/manufacturers of rebranded devices.

python-limitlessled's People

Contributors

amelchio avatar ash-vd avatar bobdrummond avatar corneyl avatar happyleavesaoc avatar janlo avatar kamaradclimber avatar keesschollaart81 avatar robiinn avatar rubenverhoef avatar smwa avatar soldag 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

Watchers

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

python-limitlessled's Issues

Support for LS2 RGB-CCT led strip controller

Recently I installed a RGB CCT ledstrip over the full length of my living room. The dream is to use an Amazon echo dot with a harmony hub so I can start a movie activity by voice and the tv, receiver, firetv are all turned on, as well as the led strip.
I'm trying to control the ledstrip with Home Assistant through the build-in python-limitlessled library. But can't get it to work. After lots of browsing I found out the LS2 controller I'm using talks a different protocol.

My hardware:

  • Milight LS2 ledstrip controller
  • Milight FUT089 remote
  • Milight iBox 2 wifi bridge
  • Raspberry Pi 3B

I found a Java bridge emulator with which I can log the traffic between the app and the bridge.
Hopefully you guys can use this to update the library with support for the new milight components.

Traffic log between app and bridge

On Zone 1
22 Bytes From App (192.168.2.8) Tue Jan 02 18:39:12 CET 2018
80 00 00 00 11 B9 01 00 12 00 31 00 00 0A 06 01 00 00 00 01 00 43 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:39:12 CET 2018
88 00 00 00 03 00 12 00 

Off Zone 1
22 Bytes From App (192.168.2.8) Tue Jan 02 18:39:53 CET 2018
80 00 00 00 11 B9 01 00 15 00 31 00 00 0A 06 02 00 00 00 01 00 44 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:39:53 CET 2018
88 00 00 00 03 00 15 00 

On Zone 2
22 Bytes From App (192.168.2.8) Tue Jan 02 18:41:02 CET 2018
80 00 00 00 11 B9 01 00 17 00 31 00 00 0A 06 01 00 00 00 02 00 44 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:41:02 CET 2018
88 00 00 00 03 00 17 00 

Off Zone 2
22 Bytes From App (192.168.2.8) Tue Jan 02 18:41:42 CET 2018
80 00 00 00 11 B9 01 00 18 00 31 00 00 0A 06 02 00 00 00 02 00 45 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:41:42 CET 2018
88 00 00 00 03 00 18 00 

On Zone All
22 Bytes From App (192.168.2.8) Tue Jan 02 18:42:57 CET 2018
80 00 00 00 11 B9 01 00 1B 00 31 00 00 0A 06 01 00 00 00 00 00 42 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:42:57 CET 2018
88 00 00 00 03 00 1B 00 

Off Zone All
22 Bytes From App (192.168.2.8) Tue Jan 02 18:43:10 CET 2018
80 00 00 00 11 B9 01 00 1C 00 31 00 00 0A 06 02 00 00 00 00 00 43 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:43:10 CET 2018
88 00 00 00 03 00 1C 00 

Keep alive (every 10s)
7 Bytes From App (192.168.2.8) Tue Jan 02 18:44:18 CET 2018
D0 00 00 00 02 B9 01 

12 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:44:18 CET 2018
D8 00 00 00 07 AC CF 23 F5 7A D4 01 

Change color Blue Zone 1
22 Bytes From App (192.168.2.8) Tue Jan 02 18:45:41 CET 2018
80 00 00 00 11 B9 01 00 20 00 31 00 00 0A 01 AB AB AB AB 01 00 E9 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:45:41 CET 2018
80 00 00 00 11 B9 01 00 21 00 31 00 00 0A 01 AB AB AB AB 01 00 E9 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:45:42 CET 2018
88 00 00 00 03 00 20 00 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:45:42 CET 2018
88 00 00 00 03 00 21 00 

Change color Red Zone 1
22 Bytes From App (192.168.2.8) Tue Jan 02 18:46:20 CET 2018
80 00 00 00 11 B9 01 00 22 00 31 00 00 0A 01 FD FD FD FD 01 00 31 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:46:20 CET 2018
88 00 00 00 03 00 22 00 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:46:21 CET 2018
80 00 00 00 11 B9 01 00 23 00 31 00 00 0A 01 FD FD FD FD 01 00 31 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:46:21 CET 2018
88 00 00 00 03 00 23 00 

Change Saturation Zone 1 full warm
22 Bytes From App (192.168.2.8) Tue Jan 02 18:48:01 CET 2018
80 00 00 00 11 B9 01 00 24 00 31 00 00 0A 03 00 00 00 00 01 00 3F 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:48:01 CET 2018
80 00 00 00 11 B9 01 00 25 00 31 00 00 0A 03 00 00 00 00 01 00 3F 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:48:01 CET 2018
88 00 00 00 03 00 24 00 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:48:01 CET 2018
88 00 00 00 03 00 25 00 

Change Saturation Zone 1 full bright
22 Bytes From App (192.168.2.8) Tue Jan 02 18:48:34 CET 2018
80 00 00 00 11 B9 01 00 26 00 31 00 00 0A 03 60 00 00 00 01 00 9F 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:48:34 CET 2018
80 00 00 00 11 B9 01 00 27 00 31 00 00 0A 03 60 00 00 00 01 00 9F 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:48:34 CET 2018
88 00 00 00 03 00 26 00 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:48:34 CET 2018
88 00 00 00 03 00 27 00 

Change Brightness Zone 1 least bright
22 Bytes From App (192.168.2.8) Tue Jan 02 18:49:37 CET 2018
80 00 00 00 11 B9 01 00 28 00 31 00 00 0A 04 01 00 00 00 01 00 41 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:49:37 CET 2018
88 00 00 00 03 00 28 00 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:49:37 CET 2018
80 00 00 00 11 B9 01 00 29 00 31 00 00 0A 04 01 00 00 00 01 00 41 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:49:38 CET 2018
88 00 00 00 03 00 29 00 

Change Brightness Zone 1 most bright
22 Bytes From App (192.168.2.8) Tue Jan 02 18:50:04 CET 2018
80 00 00 00 11 B9 01 00 2A 00 31 00 00 0A 04 61 00 00 00 01 00 A1 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:50:04 CET 2018
88 00 00 00 03 00 2A 00 

22 Bytes From App (192.168.2.8) Tue Jan 02 18:50:04 CET 2018
80 00 00 00 11 B9 01 00 2B 00 31 00 00 0A 04 61 00 00 00 01 00 A1 

8 Bytes From Bridge (192.168.2.21) Tue Jan 02 18:50:04 CET 2018
88 00 00 00 03 00 2B 00 

new release

Could you release a new version of this package on pypi (so I can use easily my patch) ?

Thanks

Support for RGB (not RGBW) lights?

Hi,

I note the library doesn't appear to currently support RGB lights. Although limitless stopped selling the plain RGB ones a while ago there are other people currently making things which are compatible with them - like pool lights (http://www.davey.com.au/products/pool-lights/pal-4000-series-led-lights-with-remote-control.html)

The RGB commands are documented under "LimitlessLED RGB CommandSet " on http://www.limitlessled.com/dev/ . The main problem I can see is that there's no concept of a group with the RGB ones, so I'm not sure how to integrate it into the existing paradigm - perhaps only allow creation of group '1' of type RGB?

Attempting to send commands throw exceptions when a session hasn't started

I noticed this with HomeAssistant. When my hub device was unplugged, the entire lights section (I think including some non-milight devices) was failing to initialize with an error that looked like this:

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 153, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "uvloop/future.pyx", line 230, in __iter__ (uvloop/loop.c:110600)
  File "uvloop/future.pyx", line 432, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:113980)
  File "uvloop/future.pyx", line 101, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:108900)
  File "/usr/local/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/light/limitlessled.py", line 118, in setup_platform
    lights.append(LimitlessLEDGroup.factory(group))
  File "/usr/src/app/homeassistant/components/light/limitlessled.py", line 178, in factory
    return LimitlessLEDRGBWWGroup(group)
  File "/usr/src/app/homeassistant/components/light/limitlessled.py", line 314, in __init__
    self.group.on = True
  File "/usr/local/lib/python3.5/site-packages/limitlessled/group/__init__.py", line 83, in on
    cmd = self.command_set.off()
  File "/usr/local/lib/python3.5/site-packages/limitlessled/group/commands/v6.py", line 303, in off
    return self._build_command(0x04, 0x02)
  File "/usr/local/lib/python3.5/site-packages/limitlessled/group/commands/v6.py", line 111, in _build_command
    self._group_number)
  File "/usr/local/lib/python3.5/site-packages/limitlessled/group/commands/__init__.py", line 44, in __init__
    self._bytes = bytearray(bytes)
TypeError: an integer is required

It looks like this is because it failed to fetch session ID bytes (wb1 and wb2 in the docs/code), so they remain set to None. The code that builds a command packet tries to build a byte array with the session ID values being set to None, which causes the above failure.

Seems like it might make sense to skip or queue commands that are being sent before a session has successfully started? If it makes sense to fail, seems like it'd be best to do so with a more helpful error message.

Transition from white to color fails for RGBW groups.

The RGBW group set the target color to None if there is a transition from RGB_WHITE (https://github.com/happyleavesaoc/python-limitlessled/blob/master/limitlessled/group/rgbw.py#L117). It then calls hue_of_color(color) (https://github.com/happyleavesaoc/python-limitlessled/blob/master/limitlessled/group/rgbw.py#L129) which causes a TypeError: 'NoneType' object is not iterable:

Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/home/hass/.homeassistant/deps/limitlessled/pipeline.py", line 32, in run
    self._queue.get().run(self._event)
  File "/home/hass/.homeassistant/deps/limitlessled/pipeline.py", line 109, in run
    self._execute_stage(i, stage, stop)
  File "/home/hass/.homeassistant/deps/limitlessled/pipeline.py", line 167, in _execute_stage
    self._group.transition(*stage.args, **stage.kwargs)
  File "/home/hass/.homeassistant/deps/limitlessled/group/rgbw.py", line 129, in transition
    self._transition(duration, hue_of_color(color), brightness)
  File "/home/hass/.homeassistant/deps/limitlessled/util.py", line 15, in hue_of_color
    return rgb_to_hsv(*[x / 255 for x in color])[0]
TypeError: 'NoneType' object is not iterable

V6 maintainer wanted

Looking for someone with a V6 bridge who is willing to test and approve V6-bridge related pull requests. I only have a V5 bridge.

Keep alive packet frequency

Looks like this is currently set to one second:

https://github.com/happyleavesaoc/python-limitlessled/blob/master/limitlessled/bridge.py#L26

This probably doesn't have any measurable negative effects, but thought I'd share some reasons it make make sense for this to be something closer to 5 seconds:

  1. The documentation suggests every 5 seconds.
  2. In practice, unrenewed sessions seem to stay active for something like 60 seconds.
  3. While it's probably insignificant in every regard that matters, it does contribute to congestion. The place this is likeliest to matter is on the hub which probably has relatively limited throughput. I'm using an ESP8266 as a Milight hub, and I've noticed a fair amount of UDP packets dropped when lots of stuff is sent at a time (up to 25% in the worst circumstances).

How do I use this?

How do I turn on a bulb which is in Zone 5 on the 8-zone remote?

From SSH, is this done using a command, or do I need to install something to make this work?

Single Color LED controller

I have a single color MiLight led controller and i can't get it to work with python-limitlessled. I'm running the following python code:

from limitlessled.bridge import Bridge
from limitlessled.group.rgbw import RGBW
from limitlessled.group.rgbww import RGBWW
from limitlessled.group.white import WHITE

bridge = Bridge('192.168.0.42')
# A group number can support two groups as long as the types differ
bridge.add_group(1, 'hoek', WHITE)

hoek = bridge.add_group(1, 'hoek', WHITE)

hoek.on = True

Does someone has any idea? is the single color led controller supported?
image

Unable to connect shortly after ending a session

Hey! I have some RGB led strips hooked up to the latest mi-light module thing, and I've found that I'm unable to start a new connection shortly after I closed a previous one, both with this library and my own C# lib. The iOS app for mi-light does not have this issue however, so I'm wondering if there's a way to fix this issue?

Version 5 bridge broken

It looks like #7 broke support for my version 5 bridge. I noticed this after upgrading Home Assistant the other day, suddenly my Limitlessled hub stopped responding. Working through it, it looks like there isn't any response from the bridge. E.g.

from limitlessled.bridge import Bridge
from limitlessled.group.rgbw import RGBW

b = Bridge("...", port=8899, version=5)
l = b.add_group(4, "lamp", RGBW)

l.on = True

does nothing, whereas if I downgrade to the commit tagged as 1.0.2 it works fine. Am I just doing something wrong? I'm willing to do the legwork to debug this and fix it, but I need a little guidance.

No module named queue

Hey,
thaks for the great Work.
Currently i have a problem if i try to start my programm:

Traceback (most recent call last): File "test.py", line 2, in <module> from limitlessled.bridge import Bridge File "/usr/local/lib/python2.7/dist-packages/limitlessled/bridge.py", line 3, in <module> import queue ImportError: No module named queue

Is there a solution for this?

\Zmash

Barebones Script Issue

Just wondering if I can get some feedback on a script I am running.
Script runs without error and ngrep verifies that I am definitely sending the commands to the bridge but no commands are working.

Presently, my script is as follows:

from limitlessled.bridge import Bridge
from limitlessled.group.rgbww import RGBWW
bridge = Bridge('192.168.1.61')

bridge.add_group(1, 'living', RGBWW)
living = bridge.add_group(1, 'living', RGBWW)

living.on = True

help for debugging ?

Hi,
I cannot control my MiLight version 6 bridge led from my PC with Python Limitlessled. Here is my code to switch the color of the bridge led :
` from limitlessled.bridge import Bridge
from limitlessled.group.rgbw import RGBW
from limitlessled.group.rgbww import RGBWW
from limitlessled.group.white import WHITE

bridge = Bridge('192.168.0.44')

bridge_led = bridge.bridge_led

bridge_led.on = True

from limitlessled import Color

bridge_led.color = Color(255, 0, 0) # red `

Am I missing something ? No error message, but nothing happens.

I have successfully tested the IP address and the port using a java https://github.com/JasperG/Colorland or a windows app http://www.limitlessled.com/download/LimitlessLEDv6.zip. Both app allow me to switch the color of the brige led.

Could you advice some other test I could use to find the cause of my fail ?

Thanks

Issues with dual white cct leds

Hi everybody and thank you for the awesome job.

I'm using the library to control 2 RGB bulbs and 2 dual white cct leds via a iBox2 (v6) bridge.

Everything is fine with the RGB bulbs. They turn on and off without any problems.
Instead, I'm unable to control the 2 white leds. Here is the code I'm using.

from limitlessled.bridge import Bridge
from limitlessled.group.rgbw import RGBW
from limitlessled.group.rgbww import RGBWW
from limitlessled.group.white import WHITE
bridge = Bridge('192.168.1.77')
living = bridge.add_group(3,'living',WHITE)
living.on = True

I don't get any error messages. Simply, the lights don't turn on.
I'm able to control them using the Mi-Light Android app, choosing the Multizone temperature/brightness controller.

Am I doing something wrong?

Thank you!

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.