Written some Osram Lightify support

Slightly jumped the gun here, wasn’t running the latest HA. Have updated to 0.28.2 and updated the gist as well as my repo for those interested.

Thanks @MindrustUK

I’m currently testing it and I’ll post my findings

@MindrustUK thanks for the good work. It has been working flawless so far.

Would be awesome to have this approved on the HA 0.29

Great work!!

Thanks @tchellomello I’ll try and run tox etc and put in a pull request when I get a chance, I’ve found one weird bug but I think that might be Home-assistant it’s self rather than the osram code. For some reason if I turn on lights it seems to persistently call a scene but again I’ll run some more tests on that when I have time.

1 Like

I’m extremely new to home assistant (just installed on Sunday) and have been loving it so far, when it works. I’ve been having the same issue reported above where home assistant seems to lose connection to the lightify hub and requires a restart to work again. It seems to be losing connection within 2 hours of restart. I have updated my component to @MindrustUK’s linked code but have continued to experience the same problem.

Again, being extremely new to home assistant, I didn’t know of any other way to update other than to copy and paste the code into the .py file using nano, If there is a better way of doing this or if this is the incorrect way of going about it, please let me know.

I’m currently running version 0.28.2 on a raspberry pi b+ (yeah I know I need to upgrade)

Thanks for all the work you all put into this!

Edit: I updated my osramlightify.py Didn’t realize there was a lightify/init.py will update that one as well.

@tharealoc, can you add:

logger: default: info logs: homeassistant.components.light: debug

To your configuration and start hass interactively and tell me if you see any odd traces / output? If I can get something to go on I can try and help resolve this.

@MindrustUK I’ve added that to my configuration and had it run for a couple days. The gateway not responding to commands from HA has continued after updating the lightify component and init files to your most recent code. I’ll add the log files as soon as I can figure out how to view them.

Thanks for making this component @MindrustUK!

Unfortunately I’m having the same problem as tharealoc. I’m running on HA 0.29.5 and I copied your updated init.py and osramlightify.py over the corresponding files.
The problem appears when I rapidly fire events. E.g. if i slide over the colours or click them a bit fast. Then apparently some worker threads are created which will never end, and then the pipeline seems full and can’t handle new commands.

Here’s a possible error:

16-10-01 16:24:49 homeassistant.components.http: Serving /api/services/light/turn_on to 192.168.1.107 (auth: True)
16-10-01 16:24:50 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1979282640-33, domain=light, service_data=entity_id=light.lightstrip1, rgb_color=[44, 255, 115]>
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on Attempting to turn on light: <bound method Light.name of <lightify.Light object at 0x7126bb50>>
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on requested transition time for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 0
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on requested ATTR_RGB_COLOR for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 44 255 115
16-10-01 16:24:50 homeassistant.components.http: Serving /api/services/light/turn_on to 192.168.1.107 (auth: True)
16-10-01 16:24:50 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1979282640-34, domain=light, service_data=entity_id=light.lightstrip1, rgb_color=[69, 220, 0]>
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on Attempting to turn on light: <bound method Light.name of <lightify.Light object at 0x7126bb50>>
16-10-01 16:24:50 homeassistant.components.http: Serving /api/services/light/turn_on to 192.168.1.107 (auth: True)
16-10-01 16:24:50 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1979282640-35, domain=light, service_data=entity_id=light.lightstrip1, rgb_color=[69, 220, 0]>
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on Attempting to turn on light: <bound method Light.name of <lightify.Light object at 0x7126bb50>>
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on requested transition time for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 0
16-10-01 16:24:50 homeassistant.components.light.osramlightify: turn_on requested ATTR_RGB_COLOR for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 69 220 0
16-10-01 16:24:51 homeassistant.components.http: Serving /api/services/light/turn_on to 192.168.1.107 (auth: True)
16-10-01 16:24:51 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1979282640-36, domain=light, service_data=entity_id=light.lightstrip1, rgb_color=[105, 255, 117]>
16-10-01 16:24:51 homeassistant.components.light.osramlightify: turn_on Attempting to turn on light: <bound method Light.name of <lightify.Light object at 0x7126bb50>>
16-10-01 16:24:51 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:51 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:51 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:51 homeassistant.components.light.osramlightify: brightness for light Lightstrip1 is: 234.6
16-10-01 16:24:51 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.lightstrip1, new_state=<state light.lightstrip1=on; friendly_name=Lightstrip1, rgb_color=(69, 220, 0), brightness=234.6, supported_features=55, color_temp=265 @ 2016-10-01T16:24:04.879094+02:00>, old_state=<state light.lightstrip1=on; friendly_name=Lightstrip1, rgb_color=(44, 255, 115), brightness=234.6, supported_features=55, color_temp=265 @ 2016-10-01T16:24:04.879094+02:00>>
16-10-01 16:24:56 lightify: Lightify Connecting…
16-10-01 16:24:56 homeassistant.components.light.osramlightify: turn_on requested transition time for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 0
16-10-01 16:24:56 homeassistant.components.light.osramlightify: turn_on requested ATTR_RGB_COLOR for light: <bound method Light.name of <lightify.Light object at 0x7126bb50>> is: 105 255 117
16-10-01 16:24:56 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1162, in job_handler
func(*args)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1025, in _execute_service
service(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 825, in call
self.func(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/init.py”, line 242, in handle_light_service
light.turn_on(**params)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/osramlightify.py”, line 153, in turn_on
self._light.set_rgb(red, green, blue, transition)
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 134, in set_rgb
super(Light, self).set_rgb(r, g, b, time)
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 81, in set_rgb
self.__conn.recv()
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 413, in recv
data = self.__sock.recv(expected)
socket.timeout: timed out
16-10-01 16:24:56 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1162, in job_handler
func(*args)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1025, in _execute_service
service(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 825, in call
self.func(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/init.py”, line 242, in handle_light_service
light.turn_on(**params)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/osramlightify.py”, line 140, in turn_on
self._light.set_onoff(1)
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 110, in set_onoff
super(Light, self).set_onoff(on)
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 66, in set_onoff
self.__conn.recv()
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 413, in recv
data = self.__sock.recv(expected)
socket.timeout: timed out
16-10-01 16:24:56 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1162, in job_handler
func(*args)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1025, in _execute_service
service(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 825, in call
self.func(call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/init.py”, line 246, in handle_light_service
light.update_ha_state(True)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 154, in update_ha_state
self.update()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/osramlightify.py”, line 194, in update
self.update_lights(no_throttle=True)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/init.py”, line 296, in wrapper
result = method(*args, **kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/init.py”, line 296, in wrapper
result = method(*args, **kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/osramlightify.py”, line 69, in update_lights
bridge.update_all_light_status()
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 443, in update_all_light_status
data = self.recv()
File “/home/homeassistant/.homeassistant/deps/lightify/init.py”, line 413, in recv
data = self.__sock.recv(expected)
socket.timeout: timed out
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: brightness for light Lightstrip1 is: 234.6
16-10-01 16:24:56 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.lightstrip1, new_state=<state light.lightstrip1=on; friendly_name=Lightstrip1, rgb_color=(105, 255, 117), brightness=234.6, supported_features=55, color_temp=265 @ 2016-10-01T16:24:04.879094+02:00>, old_state=<state light.lightstrip1=on; friendly_name=Lightstrip1, rgb_color=(69, 220, 0), brightness=234.6, supported_features=55, color_temp=265 @ 2016-10-01T16:24:04.879094+02:00>>
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: is_on light state for light: Lightstrip1 is: 1
16-10-01 16:24:56 homeassistant.components.light.osramlightify: brightness for light Lightstrip1 is: 234.6
16-10-01 16:24:56 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=1979282640-36>
16-10-01 16:24:56 homeassistant.components.http: Serving /api/services/light/turn_on to 192.168.1.107 (auth: True)
16-10-01 16:24:56 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=1979282640-37, domain=light, service_data=entity_id=light.lightstrip1, rgb_color=[192, 253, 255]>

@tfriedel Thanks for the bug report.

I’ve just updated to HA 0.29.6 this morning and ported a lot of upstream changes to my version of the code (https://github.com/MindrustUK/python-lightify/blob/master/osramlightify.py).

I’ve not been able to replicate the error so far (but I’ve only done limited testing). I did have a socket error before the upgrade but I’ll have to wait and see if that comes back any time soon (debugging was turned off). There also appears to be a known bug that if I assert colours in a scene then toggle the lights the scene comes back on (including transition) I’ll look into this when I get a chance.

I’ve also started to make the code PEP8 compliant but I’ve run out of time today to carry on.

Please let me know if you bump into any more bugs and I’ll try and address them.

1 Like

@MindrustUK, I’ve updated my custom_componenents/light/ osramlightify.py on my environment to the version above ^

I’ll let you know if I hit any problems.

Thanks

I fixed some problems in the lightify component, which fixed the bugs I saw.
See my pull request here:

The main problem was, that the lightify component is not thread-safe but home assistant is multi threaded. So I introduced locks for all the critical functions.
For the other changes see the pull request.

I also would have liked to use properties, but this could break code of other projects that depend on it.

1 Like

@tfriedel, Many thanks for your work here. It looks really good! I’ll give this a test my self when I get the chance.

@tfriedel Nice.

I’m testing your changes on my home assistant instance. I’ll post my findings in the next few days.

Thanks for the good work!

I have also tfriedel’s new version now. Updated latest hass yesterday.

No problems yet. Only ‘feature’ is when I click the light on, the second click off is somehow lost. After that it works ok. This is with every light/switch.

@tfriedel

Running your code actually I felt a better response when turning the lights on/off. It feels the colors are changing more responsibly and I had no traceback so far.

Thanks for your hard work @tfriedel and @MindrustUK

If you are interested to submit a PR there is an issue open at https://github.com/home-assistant/home-assistant/issues/3089

:slight_smile:

Ok I can’t reproduce this problem. Did you also copy the latest osramlightify.py from @MindrustUK over the file from home-assistant?
root@raspi:/home/pi/git/python-lightify# cp osramlightify.py /srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/osramlightify.py (adjust to your installation directory)

If the problem still persists, can you pleace try to list the steps to reproduce it? And maybe check the log file for some clues and post the relevant parts?

We should probably program some automatic tests. Not sure how this would work, since of course they will need to run with some real lights, but everybody’s configuration is different. I will check how the Philips Hue component is tested and hopefully there’s something we could use.

@tfriedel

Been testing the thread safe code. All appears to be working well for me so far, can’t get it to break on hammering colour changes etc. Still got the scene problem but I think that’s my code. I’ll deal with that when I get a chance. Thanks for the work!

No I didn’t copy osramlightify.py, will do that later, thanks!

Hi,

trying out Lightify with HA 0.29.6, I ran into the same issues as described above. Copying the new osramlightify.py from @MindrustUK and the _init_.py from @tfriedel’s PR, all problems seem to be fixed. Working like a charm so far. Thanks for this! Would be great to have it merged in HA & python-lightify.

1 Like

Hello guys,

@tfriedel @MindrustUK as reported by @DavidMStraub, I’ve had no issues after running the osramlightify.py and init.py code on my HA instance. No delays, very color responsive and working like a charm.

+1 to get it merged into python-lightify and HA.

1 Like