Danielhiversen / flux_led

A utility for controlling Flux WiFi Smart LED Light Bulbs
GNU Lesser General Public License v3.0
158 stars 144 forks source link

Brightness only device not working correctly in HomeAssistant #132

Closed brianegge closed 3 years ago

brianegge commented 3 years ago

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.

bdraco commented 3 years ago

Looks like a 0x21 is the same as a 0x41

It might just work if we add it to the database

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

bdraco commented 3 years ago

Assuming you are using the dev branch here https://github.com/bdraco/flux_led_custom, I pushed the changes there

bdraco commented 3 years ago

I ordered https://www.amazon.com/gp/product/B07J5B3R5L/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 to validate this, but they look exactly the same as 0x41 so I'm 99% it will just work.

Usually we can use the same mapping for model as long as the second byte is the same: 0x*1

brianegge commented 3 years ago

I picked up this update and it's working well in home-assistant. I've created a PR in HA (https://github.com/home-assistant/core/pull/57979) which will probably go nowhere.

bdraco commented 3 years ago

@brianegge Are these devices bulbs ?

If so we should change the description to Smart Bulb Dimmable https://github.com/Danielhiversen/flux_led/blob/0516c2e9931b00e693488f166a4d91303f5abec1/flux_led/models_db.py#L256

So we match up with the others

https://github.com/Danielhiversen/flux_led/blob/0516c2e9931b00e693488f166a4d91303f5abec1/flux_led/models_db.py#L286 https://github.com/Danielhiversen/flux_led/blob/0516c2e9931b00e693488f166a4d91303f5abec1/flux_led/models_db.py#L306 https://github.com/Danielhiversen/flux_led/blob/0516c2e9931b00e693488f166a4d91303f5abec1/flux_led/models_db.py#L326

bdraco commented 3 years ago

Looks like they are according to the android app

brianegge commented 3 years ago

FWIW, my model numbers are AK001-ZJ2101 and AK001-ZJ2104

bdraco commented 3 years ago

Thanks. Would you mind opening a PR to add those to the database as well?