MagicLight/Flux WiFi Color LED Light Component

Thanks, I have updated the file.
I will soon add it to the main repository of HA.
And yes, I am working on brightness and color

1 Like

@Danielhiversen Awesome!! Please let me know if you need help testing it.

Keep us posted please.

Thanks

There is now a pr here: https://github.com/home-assistant/home-assistant/pull/2534

@tchellomello
It would be great if you could test:

  1. Are all bulbs automatically detected? If not, could you try to increase the timeout here: https://github.com/home-assistant/home-assistant/pull/2534/files#diff-e210dea810eca09f715430251856b713R60

  2. Check if turning on/off the light from the MagicLight app, will update the state in Home Assistant. And check how long it takes before it updates the state

Thanks for joining, @tchellomello!

Ok, here are the results from the updated flux_led.py. I blew away the deps folder and updated these configurations:

configuration.yaml

###  Lights  ###
light: !include light.yaml

light.yaml

#### Flux ####
- platform: flux_led
  automatic_add: True
  devices:
    192.168.0.106:
      name: flux_lamppost
    192.168.0.109:
      name: flux_living_room_lamp
#    192.168.0.120:
#      name: flux_kitchen_desk_left
#    192.168.0.128:
#      name: flux_sunroom
#    192.168.0.129:
#      name: flux_kitchen_desk_right

(I wanted some of the lights to autodetect)

Console output:

INFO:homeassistant.loader:Loaded light.flux_led from custom_components.light.flux_led
INFO:homeassistant.util.package:Attempting install of https://github.com/Danielhiversen/flux_led/archive/master.zip#flux_led==0.2
INFO:custom_components.light.flux_led:192.168.0.109
INFO:custom_components.light.flux_led:192.168.0.109
INFO:custom_components.light.flux_led:192.168.0.106
INFO:custom_components.light.flux_led:192.168.0.106
192.168.0.129,ACCF239FD35E,HF-LPB100-ZJ200 b'HF-A11ASSISTHREAD'
['192.168.0.129', 'ACCF239FD35E', 'HF-LPB100-ZJ200']
('192.168.0.129', 48899)
192.168.0.109,ACCF239FCF22,HF-LPB100-ZJ200 b'HF-A11ASSISTHREAD'
['192.168.0.109', 'ACCF239FCF22', 'HF-LPB100-ZJ200']
('192.168.0.109', 48899)
192.168.0.128,ACCF23A10D14,HF-LPB100-ZJ200 b'HF-A11ASSISTHREAD'
['192.168.0.128', 'ACCF23A10D14', 'HF-LPB100-ZJ200']
('192.168.0.128', 48899)
192.168.0.106,ACCF239FDC4E,HF-LPB100-ZJ200 b'HF-A11ASSISTHREAD'
['192.168.0.106', 'ACCF239FDC4E', 'HF-LPB100-ZJ200']
('192.168.0.106', 48899)
INFO:custom_components.light.flux_led:192.168.0.129
INFO:custom_components.light.flux_led:192.168.0.109
INFO:custom_components.light.flux_led:192.168.0.128
INFO:custom_components.light.flux_led:192.168.0.106
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_living_room_lamp, new_state=<state light.flux_living_room_lamp=off; friendly_name=flux_living_room_lamp @ 2016-07-16T10:23:22.475804-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_lamppost, new_state=<state light.flux_lamppost=off; friendly_name=flux_lamppost @ 2016-07-16T10:23:22.714487-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.accf239fd35e, new_state=<state light.accf239fd35e=off; friendly_name=ACCF239FD35E @ 2016-07-16T10:23:23.493133-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.accf23a10d14, new_state=<state light.accf23a10d14=off; friendly_name=ACCF23A10D14 @ 2016-07-16T10:23:23.637539-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=group.all_lights, new_state=<state group.all_lights=unknown; friendly_name=all lights, hidden=True, order=1, auto=True, entity_id=[] @ 2016-07-16T10:23:23.644128-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=<state group.all_lights=unknown; friendly_name=all lights, hidden=True, order=1, auto=True, entity_id=[] @ 2016-07-16T10:23:23.644128-04:00>, entity_id=group.all_lights, new_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=1, auto=True, entity_id=('light.flux_lamppost', 'light.flux_living_room_lamp', 'light.accf239fd35e', 'light.accf23a10d14') @ 2016-07-16T10:23:23.895061-04:00>>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_on, domain=light>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_off, domain=light>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=toggle, domain=light>
INFO:homeassistant.core:Bus:Handling <Event component_loaded[L]: component=light>

Note: 2 of the autodiscovered devices didn’t get assigned - ACCF239FCF22 and ACCF239FDC4E

On/Off of discovered and defined lights worked as expected!

Nice!

I think they were not added to Home Assistant after auto discovery, because they where manually added in the config.
If a bulb is manually added in the config, it will not be added by auto discovery. Does that make sense?

Hello @mplawner @Danielhiversen

I just have one Flux Wifi bulb so I tested it using the automatic discovery and hard-coding it on the configuration file.

It worked on both scenarios. I did not get duplicated entries. When specifying the light bulb manually, the auto-discovery does not add it since it already has been added to HASS.

Both configurations worked as expected. When using auto-discovery

  - platform: flux_led
    automatic_add: true
    devices:
      192.168.169.165:
        name: Garage

When controlling the flux_led bulb via Home Assistant, the frontend is very responsive and the switch provided an accurate report regarding the bulb state (on/off).

I just got one problem when using the MagicLight app. When turning the light bulb via the MagicLight app it took 30 seconds and the frontend got refreshed reporting the light was on, which is not bad.

    570313-04:00>, old_state=<state sensor.denver=12:18; icon=mdi:clock, friendly_name=Denver @ 2016-07-16T14:18:00.522849-04:00>>
    16-07-16 14:19:00 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.accf23920e4a, new_state=<state light.accf23920e4a=on; friendly_name=Garage @ 2016-07-16T14:19:00.711636-04:00>, old_state=<state light.accf23920e4a=off; friendly_name=Garage @ 2016-07-16T14:16:30.836096-04:00>>

The problem was when turning the light bulb off via MagicLight, the front end did not get updated even after 3 minutes. Just after restarting HASS, it then updated to off status. It seems to be a problem on the call refreshState() by the flux_led.py library. I’ll try to run some further tests later to instantiate the object manually to see if the library is working as expected.

The good news is that when controlling the light bulb via HA only, worked 100%.

  16-07-16 14:27:16 custom_components.light.flux_led: 192.168.169.165
  16-07-16 14:27:17 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state light.accf23920e4a=off; friendly_name=Garage @ 2016-07-16T14:27:17.166625-04:00>, old_state=None, entity_id=light.accf23920e4a>
  16-07-16 14:27:17 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=None, old_state=<state group.all_lights=off; order=0, auto=True, icon=mdi:lightbulb, entity_id=('light.stairs', 'light.nightstand_marcelo', 'light.floor_lamp_right', 'light.island', 'light.bathtub_master', 'light.loft_tv', 'light.floor_lamp_middle', 'light.cabinets', 'light.floor_lamp_left', 'light.shower_master'), friendly_name=Hue Lights @ 2016-07-16T14:26:56.510877-04:00>, entity_id=group.all_lights>
  16-07-16 14:27:17 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state group.all_lights=off; order=0, auto=True, icon=mdi:lightbulb, entity_id=('light.stairs', 'light.nightstand_marcelo', 'light.floor_lamp_right', 'light.island', 'light.bathtub_master', 'light.loft_tv', 'light.floor_lamp_middle', 'light.accf23920e4a', 'light.cabinets', 'light.floor_lamp_left', 'light.shower_master'), friendly_name=Hue Lights @ 2016-07-16T14:27:17.167743-04:00>, old_state=None, entity_id=group.all_lights>
  
  -- turning it on
  16-07-16 14:28:49 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, domain=homeassistant, service_call_id=139651160347704-1, service_data=entity_id=light.accf23920e4a>
16-07-16 14:28:49 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, domain=light, service_call_id=139651160347704-2, service_data=entity_id=['light.accf23920e4a']>
16-07-16 14:28:50 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state light.accf23920e4a=on; friendly_name=Garage @ 2016-07-16T14:28:50.416387-04:00>, old_state=<state light.accf23920e4a=off; friendly_name=Garage @ 2016-07-16T14:27:17.166625-04:00>, entity_id=light.accf23920e4a>

  -- turning it off
  16-07-16 14:29:22 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_off, domain=homeassistant, service_call_id=139651160347704-3, service_data=entity_id=light.accf23920e4a>
  16-07-16 14:29:22 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_off, domain=light, service_call_id=139651160347704-4, service_data=entity_id=['light.accf23920e4a']>
  16-07-16 14:29:22 homeassistant.core: Bus:Handling <Event state_changed[L]: new_state=<state light.accf23920e4a=off; friendly_name=Garage @ 2016-07-16T14:29:22.946541-04:00>, old_state=<state light.accf23920e4a=on; friendly_name=Garage @ 2016-07-16T14:28:50.416387-04:00>, entity_id=light.accf23920e4a>
  16-07-16 14:29:22 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=139651160347704-4>

I’ll share my findings about the other tests.

Best Regards,
mmello

To make it easier to debug, try to add
_LOGGER.info(self._bulb.raw_sate[2])
after self._bulb.refreshState() in the update function in flux_led.py

See if it changes when you turn off the lights from the app

The code will soon be included in HA: https://github.com/home-assistant/home-assistant/pull/2534

So it is time to get color working.

@mplawner: Is there any support to set the brightness in the flux_led.py script?

Is see two relevant function

  • Set warm white mode
  • Set single color mode.

Is warm white mode the same as color temperature?

Cool! Yes, definitely.

The light has 2 modes as you identified. In warm white mode it acts as a normal light bulb and has a brightness function that is set by the --warmwhite parameter (in percentage).

In the color mode there isn’t a brightness function. There is a setting --custom that takes 3 parameters: type, speed, and colorlist. Type is jump, gradual, or strobe. Color list is a space separated list of colors to be cycled through by “type.”

@Danielhiversen Support for colors would be great and allow me to get rid of the MagicHome app. Thanks for your effort.

I have added an initial version for color and brightness support: https://github.com/home-assistant/home-assistant/blob/flux_light_color/homeassistant/components/light/flux_led.py

Would be great if you can test it.

Thanks, Daniel!

I cannot do a full regression at this moment, but here is what I’ve done so far:

  1. Removed all traces of previous version (removed deps flux* directories, remove custom light and replaced with new version)
  2. Autodiscovery - Removed all devices and set the automatic add to true in my configuration.yaml

Results of autodiscovery and startup log:
Found 4/5 lights on my network, but this is consistent with what MagicLight found as well. (I’ve found that these aren’t always autodiscovered via the app.)

INFO:homeassistant.loader:Loaded light.flux_led from custom_components.light.flux_led
INFO:homeassistant.util.package:Attempting install of https://github.com/Danielhiversen/flux_led/archive/master.zip#flux_led==0.4
INFO:homeassistant.util.package:Attempting install of https://github.com/Danielhiversen/flux_led/archive/master.zip#flux_led==0.4
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=light.accf239fcf22, new_state=<state light.accf239fcf22=off; friendly_name=ACCF239FCF22 @ 2016-07-20T10:08:51.879382-04:00>, old_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=light.accf23a10d14, new_state=<state light.accf23a10d14=off; friendly_name=ACCF23A10D14 @ 2016-07-20T10:08:51.911364-04:00>, old_state=None>
WARNING:homeassistant.core:WorkerPool:All 15 threads are busy and 46 jobs pending
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.881897-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d390>, <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.887267-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d2b8>, <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.904027-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d1e0>, <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.932457-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d108>, <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.939034-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6e56a858>, <Event state_changed[L]: entity_id=light.accf239fdc4e, new_state=<state light.accf239fdc4e=off; friendly_name=ACCF239FDC4E @ 2016-07-20T10:08:51.873946-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.944475-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d390>, <Event state_changed[L]: entity_id=light.accf239fcf22, new_state=<state light.accf239fcf22=off; friendly_name=ACCF239FCF22 @ 2016-07-20T10:08:51.879382-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.951903-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6e56a858>, <Event state_changed[L]: entity_id=light.accf23a10d14, new_state=<state light.accf23a10d14=off; friendly_name=ACCF23A10D14 @ 2016-07-20T10:08:51.911364-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.970879-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d390>, <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.973669-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d2b8>, <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.978796-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d1e0>, <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:51.989156-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d108>, <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:52.007980-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6e56a858>, <Event state_changed[L]: entity_id=light.accf239fedac, new_state=<state light.accf239fedac=off; friendly_name=ACCF239FEDAC @ 2016-07-20T10:08:51.896007-04:00>, old_state=None>)
WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-20T10:08:52.076137-04:00: (<function SensorTemplate.__init__.<locals>.template_sensor_state_listener at 0x6dd3d2b8>, <Event state_changed[L]: entity_id=light.accf239fcf22, new_state=<state light.accf239fcf22=off; friendly_name=ACCF239FCF22 @ 2016-07-20T10:08:51.879382-04:00>, old_state=None>)
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=unknown; entity_id=[], order=3, friendly_name=all lights, auto=True, hidden=True @ 2016-07-20T10:08:52.210173-04:00>, old_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=None, old_state=<state group.all_lights=unknown; entity_id=[], order=3, friendly_name=all lights, auto=True, hidden=True @ 2016-07-20T10:08:52.210173-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=off; entity_id=('light.accf239fdc4e', 'light.accf239fcf22', 'light.accf23a10d14', 'light.accf239fedac'), order=3, friendly_name=all lights, auto=True, hidden=True @ 2016-07-20T10:08:52.306985-04:00>, old_state=None>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: domain=light, service=turn_on>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: domain=light, service=turn_off>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: domain=light, service=toggle>
INFO:homeassistant.core:Bus:Handling <Event component_loaded[L]: component=light>

On/Off from HA:
Used light.accf239fdc4e
Note: This light was previously set at full brightness (255) and set to warmwhite mode.
Results:

  • Turn on via HA switch on the light

  • However, no state change in HA (state remained off)

  • Note, I’ve noticed this inconsistently since the last update

    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_data=entity_id=light.accf239fdc4e, domain=homeassistant, service_call_id=1981200080-3, service=turn_on>
    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_data=entity_id=[‘light.accf239fdc4e’], domain=light, service_call_id=1981200080-4, service=turn_on>
    INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id=1981200080-4>
    INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id=1981200080-3>

Dim from HA:
Used light.accf239fcf22
Note: This light was previously set at a dim level (250) and set to warmwhite mode.
Results:

  • Checked for option to set dim in properties on frontend - none available

  • Turn on via HA switch on the light

  • No state change in HA (state remained off)

  • Errors in log

    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_data=entity_id=light.accf239fcf22, domain=homeassistant, service_call_id=1981200080-5, service=turn_on>
    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_data=entity_id=[‘light.accf239fcf22’], domain=light, service_call_id=1981200080-6, service=turn_on>
    ERROR:homeassistant.core:BusHandler:Exception doing job
    Traceback (most recent call last):
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 835, in job_handler
    func(arg)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 688, in _execute_service
    service(call)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 547, in call
    self.func(call)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/init.py”, line 229, in handle_light_service
    light.update_ha_state(True)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py”, line 166, in update_ha_state
    attr = self.state_attributes or {}
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/init.py”, line 281, in state_attributes
    value = getattr(self, prop)
    File “/home/pi/.homeassistant/custom_components/light/flux_led.py”, line 103, in brightness
    return self._bulb.getWarmWhite255()
    File “/home/pi/.homeassistant/deps/flux_led/init.py”, line 570, in getWarmWhite255
    if mode == “ww”:
    NameError: name ‘mode’ is not defined
    INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id=1981200080-5>
    ERROR:homeassistant.core:BusHandler:Exception doing job
    Traceback (most recent call last):
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 835, in job_handler
    func(arg)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/event.py”, line 179, in pattern_time_change_listener
    action(now)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py”, line 180, in _update_entity_states
    entity.update_ha_state(True)
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py”, line 166, in update_ha_state
    attr = self.state_attributes or {}
    File “/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/init.py”, line 281, in state_attributes
    value = getattr(self, prop)
    File “/home/pi/.homeassistant/custom_components/light/flux_led.py”, line 103, in brightness
    return self._bulb.getWarmWhite255()
    File “/home/pi/.homeassistant/deps/flux_led/init.py”, line 570, in getWarmWhite255
    if mode == “ww”:
    NameError: name ‘mode’ is not defined
    ERROR:homeassistant.core:BusHandler:Exception doing job
    (error repeats)

Sorry, that’s all I can test for now. I will pick this up later.

Next test - With Devices identified:

Setup

  1. Removed all traces of previous version (removed deps flux* directories, remove custom light and replaced with new version)
  2. Autodiscovery - Added back in all devices and left the automatic add to true in my configuration.yaml

Results: Looks ok.

INFO:homeassistant.loader:Loaded light.flux_led from custom_components.light.flux_led
INFO:homeassistant.util.package:Attempting install of https://github.com/Danielhiversen/flux_led/archive/master.zip#flux_led==0.4
INFO:homeassistant.util.package:Attempting install of https://github.com/Danielhiversen/flux_led/archive/master.zip#flux_led==0.4
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_kitchen_desk_left, new_state=<state light.flux_kitchen_desk_left=off; friendly_name=flux_kitchen_desk_left @ 2016-07-20T12:43:35.803009-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_sunroom, new_state=<state light.flux_sunroom=off; friendly_name=flux_sunroom @ 2016-07-20T12:43:35.807469-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_lamppost, new_state=<state light.flux_lamppost=off; friendly_name=flux_lamppost @ 2016-07-20T12:43:35.849386-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_kitchen_desk_right, new_state=<state light.flux_kitchen_desk_right=off; friendly_name=flux_kitchen_desk_right @ 2016-07-20T12:43:36.139219-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=light.flux_living_room_lamp, new_state=<state light.flux_living_room_lamp=off; friendly_name=flux_living_room_lamp @ 2016-07-20T12:43:36.198285-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=group.all_lights, new_state=<state group.all_lights=unknown; friendly_name=all lights, hidden=True, order=0, entity_id=[], auto=True @ 2016-07-20T12:43:36.246578-04:00>>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=<state group.all_lights=unknown; friendly_name=all lights, hidden=True, order=0, entity_id=[], auto=True @ 2016-07-20T12:43:36.246578-04:00>, entity_id=group.all_lights, new_state=None>
INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=None, entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=0, entity_id=('light.flux_kitchen_desk_left', 'light.flux_kitchen_desk_right', 'light.flux_lamppost', 'light.flux_sunroom', 'light.flux_living_room_lamp'), auto=True @ 2016-07-20T12:43:36.261558-04:00>>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_on, domain=light>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_off, domain=light>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=toggle, domain=light>
INFO:homeassistant.core:Bus:Handling <Event component_loaded[L]: component=light>

On/Off from HA:
Used light.flux_lamppost (in previous test, this device was autodiscovered as: light.accf239fdc4e)
Note: This light was previously set at full brightness (255) and set to warmwhite mode.
Results:

  • Turn on via HA switched on the light (as in previous test)

  • However, no state change in HA (state remained off)

    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_call_id=1981187824-3, service_data=entity_id=light.flux_lamppost, service=turn_on, domain=homeassistant>
    INFO:homeassistant.core:Bus:Handling <Event call_service[L]: service_call_id=1981187824-4, service_data=entity_id=[‘light.flux_lamppost’], service=turn_on, domain=light>
    INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id=1981187824-4>
    INFO:homeassistant.core:Bus:Handling <Event service_executed[L]: service_call_id=1981187824-3>

After waiting for about 2 minutes for a status change, I noticed the error from the previous run repeating (so apparently had nothing to do with the dim):

ERROR:homeassistant.core:BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 835, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/event.py", line 179, in pattern_time_change_listener
    action(now)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 180, in _update_entity_states
    entity.update_ha_state(True)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 166, in update_ha_state
    attr = self.state_attributes or {}
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/__init__.py", line 281, in state_attributes
    value = getattr(self, prop)
  File "/home/pi/.homeassistant/custom_components/light/flux_led.py", line 103, in brightness
    return self._bulb.getWarmWhite255()
  File "/home/pi/.homeassistant/deps/flux_led/__init__.py", line 570, in getWarmWhite255
    if mode == "ww":
NameError: name 'mode' is not defined

Hello @mplawner @Danielhiversen,

I ran a few tests using the upstream/flux_light_color branch. Basically got 2 errors straight of the box as reported by @mplawner

      ERROR:homeassistant.core:BusHandler:Exception doing job
      Traceback (most recent call last):
        File "/home/mdemello/devel/home-assistant/homeassistant/core.py", line 835, in job_handler
          func(arg)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/event.py", line 179, in pattern_time_change_listener
          action(now)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 180, in _update_entity_states
          entity.update_ha_state(True)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity.py", line 166, in update_ha_state
          attr = self.state_attributes or {}
        File "/home/mdemello/devel/home-assistant/homeassistant/components/light/__init__.py", line 281, in state_attributes
          value = getattr(self, prop)
        File "/home/mdemello/devel/home-assistant/homeassistant/components/light/flux_led.py", line 103, in brightness
          return self._bulb.getWarmWhite255()
        File "/home/mdemello/.homeassistant/deps/flux_led/__init__.py", line 570, in getWarmWhite255
          if mode == "ww":
      NameError: name 'mode' is not defined

      ERROR:homeassistant.core:BusHandler:Exception doing job
      Traceback (most recent call last):
        File "/home/mdemello/devel/home-assistant/homeassistant/core.py", line 835, in job_handler
          func(arg)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/event.py", line 179, in pattern_time_change_listener
          action(now)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 180, in _update_entity_states
          entity.update_ha_state(True)
        File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity.py", line 166, in update_ha_state
          attr = self.state_attributes or {}
        File "/home/mdemello/devel/home-assistant/homeassistant/components/light/__init__.py", line 281, in state_attributes
          value = getattr(self, prop)
        File "/home/mdemello/devel/home-assistant/homeassistant/components/light/flux_led.py", line 108, in rgb_color
          return self._bulb.getRgb()
        File "/home/mdemello/.homeassistant/deps/flux_led/__init__.py", line 591, in getRgb
          if mode == "color":Turned
      NameError: name 'mode' is not defined

First I modified the library to instead mode to be self.mode. Also, there was a typo which was making a NoneType to be returned. After looking at the library, instead returning the self.raw_state[9] it should be self.raw_sate[9].

As explained by @mplawner, warm white supports brightness but color does not. After the modifications below, it worked as expected for warm white and setting different colors. Created the PR https://github.com/Danielhiversen/flux_led/pull/1

      ↪ git diff master                                                                                  
      diff --git a/flux_led/__init__.py b/flux_led/__init__.py
      index f1219de..a7064c8 100755
      --- a/flux_led/__init__.py
      +++ b/flux_led/__init__.py
      @@ -567,8 +567,8 @@ class WifiLedBulb():
                      self.turnOn(False)
              
              def getWarmWhite255(self):
      -               if mode == "ww":
      -                       return int(self.raw_state[9])
      +               if self.mode == "ww":
      +                       return int(self.raw_sate[9])
                      return 255
       
              def setWarmWhite(self, level, persist=True):
      @@ -588,7 +588,7 @@ class WifiLedBulb():
                      self.__write(msg)
       
              def getRgb(self):
      -               if mode == "color":
      +               if self.mode == "color":
                              red = self.raw_sate[6]
                              green = self.raw_sate[7]
                              blue = self.raw_sate[8]

Another problem noticed is that if the light bulb is already on, it does not get its state updated. Modifying the library to force the self.refreshState() addressed the issue. I’ve added this modification on the same PR as https://github.com/Danielhiversen/flux_led/pull/1

Please let me know what you guys think, but so far it’s working great.

Best Regards,
mmello

Great, I have merged your pull request.

Woah! It works!

I’ll run through testing later but the first thing I did notice is that it takes a few switches on and off for the status in HA to update.

Great.
You should check if you actually have to trigger the switches several times or maybe you just have to wait a bit before HA notice the change

Triggering each switch a few times eventually works - but that makes it as reliable as those Amazon Dash buttons :wink:

I’ve kept track now, it isn’t a matter of time for HA to notice. I’ve waited a few hours now.

Sorry, not sure what exactly it triggering this error, but I did want to share (note that the lights don’t seem to be functioning now):

ERROR:homeassistant.core:BusHandler:Exception doing job
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 835, in job_handler
    func(arg)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/event.py", line 179, in pattern_time_change_listener
    action(now)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 180, in _update_entity_states
    entity.update_ha_state(True)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 163, in update_ha_state
    self.update()
  File "/home/pi/.homeassistant/custom_components/light/flux_led.py", line 127, in update
    self._bulb.refreshState()
  File "/home/pi/.homeassistant/deps/flux_led/__init__.py", line 474, in refreshState
    self.__write(msg)
  File "/home/pi/.homeassistant/deps/flux_led/__init__.py", line 733, in __write
    self.__writeRaw(bytes)
  File "/home/pi/.homeassistant/deps/flux_led/__init__.py", line 726, in __writeRaw
    self.socket.send(bytes)
BrokenPipeError: [Errno 32] Broken pipe

When I run this I get this in my logs. The jobs just get higher and higher. The bulb works the first couple requests, then stops working completely.

ARNING:homeassistant.core:WorkerPool:All 22 threads are busy and 265 jobs pending
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:16:59.374600-04:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0xb6172b30>>, (<homeassistant.core.Service object at 0xae1e49e0>, <ServiceCall light.turn_on: brightness=255, entity_id=['light.indicator_light']>))
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:17:00.903957-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:17:00.505530-04:00>)
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:17:30.678266-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:17:30.504933-04:00>)
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:18:00.817979-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:18:00.502436-04:00>)
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:18:30.887221-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:18:30.505484-04:00>)
Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-    21T20:18:32.428964-04:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0xb6172b30>>, (<homeassistant.core.Service object at 0xafa49ee0>, <ServiceCall light.turn_off: entity_id=['light.indicator_light']>))
    Jul 22 00:26:15 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:19:00.56872

 WARNING:homeassistant.core:WorkerPool:All 22 threads are busy and 1057 jobs pending
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:16:59.374600-04:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0xb6172b30>>, (<homeassistant.core.Service object at 0xae1e49e0>, <ServiceCall light.turn_on: brightness=255, entity_id=['light.indicator_light']>))
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:17:00.903957-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:17:00.505530-04:00>)
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:17:30.678266-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:17:30.504933-04:00>)
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:18:00.817979-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:18:00.502436-04:00>)
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:18:30.887221-04:00: (<function EntityPlatform._update_entity_states at 0xafa46f60>, <Event time_changed[L]: now=2016-07-21T20:18:30.505484-04:00>)
Jul 22 00:26:59 pidome hass[9955]: WARNING:homeassistant.core:WorkerPool:Current job from 2016-07-21T20:18:32.428964-04:00: (<bound method ServiceRegistry._execute_service of <homeassistant.core.ServiceRegistry object at 0xb6172b30>>, (<homeassistant.core.Service object at 0xafa49ee0>, <ServiceCall light.turn_off: entity_id=['light.indicator_light']>))