[SOLVED] Osram Lightify with OH2

Hi,

i am trying to get this here going:

https://github.com/openhab/openhab1-addons/wiki/Osram-Lightify

but if i change one of the items, this happens:

 Rule 'Lightify Workaround Lightify1': The name '<XFeatureCallImplCustom>.state' cannot be resolved to an item or type.

Is there anybody who get this working on openhab2?

Jens

1 Like

@Jensen

I never knew there was a lightify binding!

I have 1 lightify RGB bulb and 1 lightify RGB led strip, both sitting unused as I could not get them working with Philip’s Hue.

I have alot going next few days but can give it a shot and post back this weekend if can get it work.

So what is your rule?

it is (or at least should be) exactly like it is quoted in the example:

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.eclipse.xtext.xbase.lib.*
import org.openhab.core.items.*

val Functions$Function3 updateLightifyDevice = [
    org.openhab.core.library.items.SwitchItem s,
    org.openhab.core.library.items.ColorItem c,
    String device |

        var cmd = 'python@@/root/mylightify.py@@--bridge@@192.168.178.52@@--device@@' + device
        if (s.state == OFF) {
            cmd = cmd + '@@--onoff@@0'
        } else {
            if (c.state != Uninitialized) {
                 var light = c.state as HSBType
                var red = light.red / 100 * 255
                var green = light.green / 100 * 255
                var blue = light.blue / 100 * 255
                cmd = cmd + '@@--onoff@@1@@--brightness@@' + light.brightness + '@@--red@@' + red + '@@--green@@' + green + '@@--blue@@' + blue
            } else {
                cmd = cmd + '@@--onoff@@1'
             }
        }
        executeCommandLine(cmd)
        return 1
]


rule "Lightify Workaround Lightify1"
    when
        Item Lightify1_OnOff changed or
        Item Lightify1_Colour changed
    then
        updateLightifyDevice.apply(Lightify1_OnOff, Lightify1_Colour, 'Room1')
end

actually it isn’t a binding. It uses a pearl script and the exec binding.

Jens

It must to be some problem with the functions. If i put everything in one rule it works:

rule "Lightify Workaround Lightify1"
    when
        Item Lightify1_OnOff changed or
        Item Lightify1_Colour changed
    then
        var cmd = 'python@@/root/mylightify.py@@--bridge@@192.168.178.52@@--device@@' + 'Room1'
        if (Lightify1_OnOff.state == OFF) {
            cmd = cmd + '@@--onoff@@0'
        } else {
            if (Lightify1_Colour.state != NULL) {
                var light = Lightify1_Colour.state as HSBType
                var red = light.red / 100 * 255
                var green = light.green / 100 * 255
                var blue = light.blue / 100 * 255
                cmd = cmd + '@@--onoff@@1@@--brightness@@' + light.brightness + '@@--red@@' + red + '@@--green@@' + green + '@@--blue@@' + blue
            } else {
                cmd = cmd + '@@--onoff@@1'
             }
        }
        executeCommandLine(cmd)

end

Just to be clear, this is running on OH 1.8?

If on OH 2 remove all references to org.openhab.*

The classes that were in those locations have moved and they no longer need to be imported. So org.openhab.core.library.items.SwitchItem becomes SwitchItem.

Hi Rich,

as mentioned in the heading it is running on OH2 and your information is much appreciated because it solved this issue :slight_smile:

Thank you very much.

Jens

I’m trying to get this setup now as well, but can’t get past the first steps in running the python script.

I created a file called lightify.py on my Ubuntu with the following:

lightify = Lightify("192.168.xx.xxx")
lightify.update_all_light_status()
lights = lightify.lights()
print ("lights")

And when I run the script I this error?

ptmuldoon@OpenHab2:~$ python3 lightify.py
Traceback (most recent call last):
  File "lightify.py", line 1, in <module>
    lightify = Lightify("192.168.xx.xxx")
NameError: name 'Lightify' is not defined

I tried with both python and python3 and get the same error. And did install the Lightify package.

ptmuldoon@OpenHab2:~$ pip3 install Lightify
Requirement already satisfied: Lightify in ./.local/lib/python3.5/site-packages

Hi Paul,

you need to import it first:

import lightify

Jens

@Jensen

This is probably super easy and i’m just a tard sometimes at this stuff. I’ve installed the Lightify via pip. Think I have imported correctly, just still get stuck.

ptmuldoon@OpenHab2:~$ pip install Lightify
Collecting Lightify
Installing collected packages: Lightify
Successfully installed Lightify-1.0.3
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
ptmuldoon@OpenHab2:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lightify
>>>
ptmuldoon@OpenHab2:~$ python mylightify.py
Traceback (most recent call last):
  File "mylightify.py", line 1, in <module>
    lightify = Lightify("192.168.11.152")
NameError: name 'Lightify' is not defined
ptmuldoon@OpenHab2:~$

my script looks like this:

import lightify
lightify = lightify.Lightify("192.168.178.52")
lightify.update_all_light_status()
lights = lightify.lights()
print lights

how does yous look?

Jens

Yeah, I may have just figured it out, not realizing you need to place that at the top of your file.

But import lightify did not work for me. But from lightify import Lightify did.

So my script looks like

from lightify import Lightify
lightify = Lightify("192.168.11.152")
lightify.update_all_light_status()
lights = lightify.lights()
print lights

So Now I get this when running it

ptmuldoon@OpenHab2:~$ python mylightify.py
{8984750156481036605: <lightify.Light object at 0x7ffb90e6a5d0>, 9518399593889720855L: <lightify.Light object at 0x7ffb90e6a610>}

I only have 1 light hooked up to the hub, so believe this is correct light ID number

9518399593889720855L

So, I think I have this all setup here remotely from my office, and will see if it works when I get home later tonight.

For the lightify.rules and with OH2. I think forget what is shown on github and use the simpler rule created by @Jensen above?

Well,

I got home tonight and tried to control the Lightify bulb but can’t seem to get it work.

I place the mylightify.py script in my home/ptmuldoon location, and enabled the Exec 2.0 binding in OH2 as well.

The rule fires when I attempt to control it and I see it trying in the log, but the bulb is not responding.

2017-01-25 18:49:45.844 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1]'
2017-01-25 18:49:47.638 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 0]'
2017-01-25 18:49:51.792 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1]'
2017-01-25 18:49:58.388 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1, --brightness, 96.07843, --red, 244.99999650, --green, 244.99999650, --blue, 244.99999650]'
2017-01-25 18:49:58.408 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1, --brightness, 96.07843, --red, 244.99999650, --green, 244.99999650, --blue, 244.99999650]'
2017-01-25 18:49:58.424 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1, --brightness, 96.07843, --red, 244.99999650, --green, 244.99999650, --blue, 244.99999650]'
2017-01-25 18:50:00.232 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1, --brightness, 96.07843, --red, 244.99999650, --green, 54.00000870, --blue, 99.00004995]'
2017-01-25 18:50:02.030 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[python, /home/ptmuldoon/mylightify.py, --bridge, 192.168.11.152, --device, Room1, --onoff, 1, --brightness, 96.07843, --red, 244.99999650, --green, 127.00000110, --blue, 50.00000475]'
2017-01-25 18:50:04.800 [WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 393435 failed: null
ptmuldoon@OpenHab2:~$ python mylightify_hub.py
{8984750156481036605: <lightify.Light object at 0x7f72442c85d0>, 9518399593889720855L: <lightify.Light object at 0x7f72442c8610>}

From what I can tell, I think the first ID ending in 6605 is the light and the second one ending 0855L may be the light strip.

But I can’t seem to control either one via OH2 yet.

unfortunately i can’t help further because i never proceed beyond the testing. I was trying to run this simultaneously with a Hue system but i looks like they are disturbing each other. So i am using only the Hue now.

Does it seem strange that this would be disturbing the Hue System? I also run Hue here and have about 16 lights hooked up to it, as well the separate Lightify hub. I can control both systems with their apps with out disturbing each other, but have yet to get the Lightify bulbs to pair with the Hue.

I will be away the next several days but will continue to experiment while I can. I was able to get the Lightify bulbs to turn ON and OFF with this script here. But still haven’t gotten OH2 to control them yet with a script. Perhaps its a permissions, file path, or some other type of issue but I think the 2 systems should work side by side without disruptions?

from lightify import Lightify
lightify = Lightify("192.168.11.152")
lightify.update_all_light_status()
lights = lightify.lights()
for light in lights.keys():
  lights[light].set_onoff(True)

I’ve also read there is a REST api for the Lightify but think that may require a need to connect to the internet to control them?

If anyone has a lightify hub and is able to test, I would love to know if you got any control of a lightify bulb. In trying to ignore OH2 for now, I have imported the Lightify and tried controlling it via various command lines to no effect.

None of the below here seems to control the bulb.

ptmuldoon@OpenHab2:~$ sudo nano mylightify_hub.py
ptmuldoon@OpenHab2:~$ python  mylightify_hub.py
{9518399593889720855L: <lightify.Light object at 0x7f19a25db5d0>}
ptmuldoon@OpenHab2:~$ python mylightify.py --bridge 192.168.11.152 --device 9518399593889720855L --onoff 0
ptmuldoon@OpenHab2:~$ python mylightify.py --bridge 192.168.11.152 --device 9518399593889720855L --onoff 1
ptmuldoon@OpenHab2:~$ python mylightify.py --bridge 192.168.11.152 --device 9518399593889720855 --onoff 0
ptmuldoon@OpenHab2:~$ python mylightify.py --bridge 192.168.11.152 --device 9518399593889720855 --onoff 1

Yet, this code will turn off the light

from lightify import Lightify
lightify = Lightify("192.168.11.152")
lightify.update_all_light_status()
lights = lightify.lights()
for light in lights.keys():
  lights[light].set_onoff(False)

I m using lightify … but im new to OH2 and dont have a clue how to help :smiley:
i was playing around with the sys , but i miss the binding.

Wanted to report SUCCESS!!!

First, I believe my issue originally in trying to get the Exec binding to work was more of a python issue. I’m only guessing here, but believe their was some type of user permission issue with the OpenHab user not having access to the Lightify module installed via PIP.

PIP installed the Module to the hidden directory of: /home/username/.local/lib/pythonX.X/…

And it appears the OpenHab user can’t access that module/directory. Once I copied the 2 Lightify folders to the /usr/lib/python2.7/dist-packages then all of sudden it worked in OH2.

I was then also then able to get this Lightify LED strip working in conjunction with my other HUE lights in my main family room. So now when I control the color, both the Hue bulbs and Lightify LED lightstrip work together.

This is the main rule I’m using to control them. Note, I have never been able to get a Color Group to work, so I do send commands to each bulb separately. But it works fine.

import java.awt.Color

rule "Set RGBW Value of Family Room"
 when
   Item FF_Light_FamilyColorGroup changed
 then
   var hsbValue = FF_Light_FamilyColorGroup.state as HSBType
   var Color color = Color::getHSBColor(hsbValue.hue.floatValue / 360, hsbValue.saturation.floatValue / 100, hsbValue.brightness.floatValue / 100)
		
   var red = (color.red.floatValue / 2.55).intValue
   var green = (color.green.floatValue / 2.55).intValue
   var blue = (color.blue.floatValue / 2.55).intValue
      
   //Control Lightify
   var cmd = 'python@@/etc/openhab2/scripts/mylightify.py@@--bridge@@192.168.11.152@@--device@@' + 'Room1'
   if (FF_Light_FamilyColorGroup.state == OFF) {
            cmd = cmd + '@@--onoff@@0'
        } else {
            cmd = cmd + '@@--onoff@@1@@--brightness@@' + hsbValue.brightness + '@@--red@@' + red + '@@--green@@' + green + '@@--blue@@' + blue
        }
   executeCommandLine(cmd)
   
   sendCommand(FF_Light_FamilyLeft,hsbValue)
   sendCommand(FF_Light_FamilyRight,hsbValue)
   sendCommand(FF_Light_FamilyCF_1,hsbValue)
   sendCommand(FF_Light_FamilyCF_2,hsbValue)
   sendCommand(FF_Light_FamilyCF_3,hsbValue)
   sendCommand(FF_Light_FamilyCF_4,hsbValue)
end