Hue Lights discussion

Posted on
Tue Apr 02, 2013 11:58 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Version 0.9.10 Posted

See original topic for download link.

Changes since version 0.9.9
  • Updated plugin to recognize (and not crash when) non-Hue bulbs and dimmers are found registered on the Hue hub. The Hue Lights plugin should still work for on/off/brightness on those devices (such as the LivingWhites bulbs), but attempts to change the color or saturation will fail if the attached devices have no "hue" attribute.

Posted on
Wed Apr 03, 2013 12:27 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Hue Lights discussion

Thanks Nathan didn't see you already updated the plugin.
But.....
I'm still getting errors though.

3 apr. 2013 17:26:19
Disabling plugin "Hue Lights 0.9.10"
Stopping plugin "Hue Lights 0.9.10" (pid 5547)
Plugin "Hue Lights" disconnected
Enabling plugin "Hue Lights 0.9.10"
Starting plugin "Hue Lights 0.9.10" (pid 5601)
Plugin "Hue Lights" connected
Plugin "Hue Lights 0.9.10" started
Hue Lights Loaded 17 bulb(s)
Hue Lights Error exception in deviceStartComm(Woonkamer Kastlamp): 'hue'
Hue Lights Error exception in deviceStartComm(Woonkamer Leeslamp): 'hue'
Hue Lights "Woonkamer Tafellamp" updated to on at 52
Hue Lights Error exception in deviceStartComm(Woonkamer Tafellamp): global name 'exceptions' is not defined
Hue Lights "Woonkamer TV lamp" updated to off
Hue Lights Error exception in deviceStartComm(Woonkamer TV lamp): 'hue'
Hue Lights Error Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
File "plugin.py", line 261, in runConcurrentThread
File "plugin.py", line 835, in getBulbStatus
<type 'exceptions.KeyError'>: 'hue'

Hue Lights Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)


Now I did some hacking of my own, and I think with a simple conditional it should work.

Code: Select all
         # Update device states based on bulb object data.
         #   On/Off State (True/False).
         #   (It's not necessary to update the onOffState since, if brightness
         #     is greater than 0, onOffState is automatically set to On and if
         #     brightness is 0, onOffState is Off).
         #   Brightness Level (convert from 0-255 to 0-100).
         if bulb['state']['on'] == True:
            # Only update the brightness level if the bulb is actually on.
            if device.states['brightnessLevel'] != int(ceil(bulb['state']['bri']/255.0*100.0)):
               self.debugLog(u"Data from Hue hub:\n" + str(bulb))
               # Log the update.
               indigo.server.log(u"\"" + device.name + "\" updated to on at " + str(int(ceil(bulb['state']['bri']/255.0*100.0))))
               # Only update the brightness level if it's different.
               self.updateDeviceState(device, 'brightnessLevel', int(ceil(bulb['state']['bri']/255.0*100.0)))
######################################################### added
            if bulb.get('modelid', "") == "LCT001":
######################################################### added
               #   Hue Degrees (convert from 0-65535 to 0-360).
               self.updateDeviceState(device, 'hue', int(round(bulb['state']['hue']/182.0)))
               #   Saturation (convert from 0-255 to 0-100).
               self.updateDeviceState(device, 'saturation', int(ceil(bulb['state']['sat']/255.0*100)))
               #   CIE XY Cromaticity.
               self.updateDeviceState(device, 'colorX', bulb['state']['xy'][0])
               self.updateDeviceState(device, 'colorY', bulb['state']['xy'][1])
               #   Red, Green, and Blue Color.
               #     Convert from XY to RGB.
               if bulb['state']['xy'][1] == 0:
                  # If the y component is zero, there's a bug in colormath that throws a
                  #   ZeroDivisionError.  Work around this by setting the y component to
                  #   something close to, but not quite zero.
                  bulb['state']['xy'][1] = 0.00001
               xyy = xyYColor(bulb['state']['xy'][0], bulb['state']['xy'][1], bulb['state']['bri']/255.0, illuminant='e')
               rgb = xyy.convert_to('rgb', target_illuminant='a')
               #     Assign the 3 RGB values to device states. We multiply each RGB value
               #     by the brightness percentage because the above xyY conversion returns
               #     normalized RGB values (ignoring luminance in the conversion).
               self.updateDeviceState(device, 'colorRed', int(round(rgb.rgb_r * bulb['state']['bri'] / 255.0)))
               self.updateDeviceState(device, 'colorGreen', int(round(rgb.rgb_g * bulb['state']['bri'] / 255.0)))
               self.updateDeviceState(device, 'colorBlue', int(round(rgb.rgb_b * bulb['state']['bri'] / 255.0)))
               #   Color Temperature (convert from 154-500 mireds to 6494-2000 K).
               if bulb['state']['ct'] > 0:
                  self.updateDeviceState(device, 'colorTemp', int(floor(1000000.0/bulb['state']['ct'])))
               else:
                  self.updateDeviceState(device, 'colorTemp', 0)
               #   Color Mode.
               self.updateDeviceState(device, 'colorMode', bulb['state']['colormode'])
######################################################### moved
            #   Alert Status.
            self.updateDeviceState(device, 'alertMode', bulb['state']['alert'])
            #   Effect Status.
            self.updateDeviceState(device, 'effect', bulb['state']['effect'])
######################################################### moved
         elif bulb['state']['on'] == False:
            # Bulb is off. Set brightness to zero.
            if device.states['brightnessLevel'] != 0:
               self.debugLog(u"Data from Hue hub:\n" + str(bulb))
               # Log the update.
               indigo.server.log(u"\"" + device.name + "\" updated to off")
               # Only if current brightness is not zero.
               self.updateDeviceState(device, 'brightnessLevel', 0)
######################################################### added
            if bulb.get('modelid', "") == "LCT001":
######################################################### added
               #   Hue Degrees (convert from 0-65535 to 0-360).
               self.updateDeviceState(device, 'hue', int(round(bulb['state']['hue']/182.0)))
               #   Saturation (convert from 0-255 to 0-100).
               self.updateDeviceState(device, 'saturation', int(ceil(bulb['state']['sat']/255.0*100)))
               #   CIE XY Cromaticity.
               self.updateDeviceState(device, 'colorX', bulb['state']['xy'][0])
               self.updateDeviceState(device, 'colorY', bulb['state']['xy'][1])
               #   Red, Green, and Blue Color.
               #     If the bulb is off, all RGB values should be 0.
               self.updateDeviceState(device, 'colorRed', 0)
               self.updateDeviceState(device, 'colorGreen', 0)
               self.updateDeviceState(device, 'colorBlue', 0)
               #   Color Temperature (convert from 154-500 mireds to 6494-2000 K).
               if bulb['state']['ct'] > 0:
                  # This is to prevent divide by zero errors if the data returned is incomplete.
                  self.updateDeviceState(device, 'colorTemp', int(floor(1000000.0/bulb['state']['ct'])))
               else:
                  # Set the state to 0 if the value returned is 0.
                  self.updateDeviceState(device, 'colorTemp', 0)
               #   Color Mode.
               self.updateDeviceState(device, 'colorMode', bulb['state']['colormode'])
######################################################### moved
            #   Alert Status.
            self.updateDeviceState(device, 'alertMode', bulb['state']['alert'])
            #   Effect Status.
            self.updateDeviceState(device, 'effect', bulb['state']['effect'])
######################################################### moved
         else:
            # Unrecognized on state, but not important enough to mention in regular log.
            self.debugLog(u"Hue bulb unrecognized on state given by hub: " + str(bulb['state']['on']))


It's not elegant but for now it works.
Better would be to build a dictionary of parameters per device and update only the ones that the device and the plugin supports. That way if philips adds new devices it will only try to update the states the plugin and the device supports.
But my programming skills are limited and I don't know how much impact this will have on the code.

By the way I've also edited the Devices.xml and added a LivingWhites model. This will prevent me to try and poll for states that LivingWhites do not support.
I'm testing at the moment with a modified 0.9.9 version. And it seems to hold for now.

Posted on
Wed Apr 03, 2013 12:50 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Ugh. Yea. Clearly a bug in the 0.9.10 modification. I'll see what I can do to fix that.

Your modifications to the 0.9.9 code look very functional. Agreed, a dictionary with the supported parameters for each light model would be the better way to go, though that would require quite a bit of code modification I think. I don't know if I want to put that much work into modifying code that I can't even test with the hardware for which it's intended (since I can't get LivingWhites here in the US). Perhaps if Philips releases non-Hue devices that work with the Hue hub and that I can get here in the US, I'll undertake a major code update.

I'll try to get that 0.9.10 bug fixed, but it sounds like your 0.9.9 modified version will still work better for your purposes. Once the 0.9.10 (or later version) of the code is fixed, I'll update the GetHub repository and, if you like, you can apply your modifications to that.

Posted on
Wed Apr 03, 2013 2:22 pm
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Hue Lights discussion

I agree. I haven't read the whole code but that change would be a big one. And at the moment there's not a big advantage. The shortcut way could be to just test if the status is in the json object and if not set a dummy value in the plugin status. I think you did something similar in the 0.9.10 version for the hue value. But I see the same problem there as with my solution, there is a 'modelid' in there. If Philips decides to update the 'LCT001' to 'LCT002' the plugin will sees to function properly.
I have no understanding of json objects. But I'm thinking along the lines of this:
Code: Select all
if bulb.get('hue', "") != "":
   #   Hue Degrees (convert from 0-65535 to 0-360).
   self.updateDeviceState(device, 'hue', int(round(bulb['state']['hue']/182.0)))
else:
   self.updateDeviceState(device, 'hue', -1)

And this of course for every status of the device.
The above code will certainly error out I think, but I don't know how to test jet I'll have to look into that.

Posted on
Thu Apr 04, 2013 10:37 am
BeNoOne offline
Posts: 30
Joined: Oct 11, 2006
Location: Netherlands

Re: Hue Lights discussion

Nathan,
Just to keep U posted. The adapted plugin(0.9.9a as I call it) is fully functional.
It can distinguish what type of device you are trying to add and only save if it's the correct one.
Also the device list is filtered against the actions list. That way you only see the devices that support the actions U want.
At the moment I believe the demand for this addition is not overwhelming.
But for those who are interested, the 0.9.9a plugin can work with LivingWhites.

I'm not sure what GetHub is, maybe typo of GitHub? If it's there i'll try to add the code.

Posted on
Thu Apr 04, 2013 10:49 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Great! Hahaha. Yea, I misspelled GitHub. ;-) That's what I meant. I haven't updated the code there in a while, but will get to that shortly.

Posted on
Wed Apr 10, 2013 12:42 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Version 0.9.11 Posted

See original topic for download link.

Changes since version 0.9.10
  • Modified code to more elegantly handle non-Hue devices attached to the Hue hub. Hue Lights should not recognize non-Hue devices and update the brightness and on-state appropriately (assigning generic color values to the color states in the Indigo device). This update does not include support for non-Hue bulbs (so there aren't separate devices defined for LivingWhites and other models).

Also, the GitHub repository has been updated with this update.

Posted on
Wed Apr 10, 2013 4:26 pm
dcornish offline
Posts: 1
Joined: Mar 27, 2013

Re: Hue Lights - Free Philips Hue Plugin

For some reason I can not get the plugin to work. I have an Apple TimeMachine hub, most recent version. I have triple checked everything. Can you please provide some trouble shooting ideas?

Posted on
Wed Apr 10, 2013 4:56 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights - Free Philips Hue Plugin

dcornish wrote:
For some reason I can not get the plugin to work. I have an Apple TimeMachine hub, most recent version. I have triple checked everything. Can you please provide some trouble shooting ideas?

Could you be more specific? What does the Indigo log show? What version of Indigo are you using?

Posted on
Sat Apr 27, 2013 6:42 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Hue Lights discussion

Hey Nathan,

Been getting prompted when opening the Hue app to upgrade the software, I assume
they mean for the hub. Any idea if that may break anything with the plugin?

Thanks,

Carl

edit: Went ahead and tried the upgrade and all works fine.

Posted on
Sun Apr 28, 2013 11:53 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Hi Carl.

Thanks for the info. I didn't realize there was an update. I just did the update to my hub and haven't noticed any problems with the Hue Lights plugin either.

Posted on
Sun Apr 28, 2013 5:31 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Hue Lights discussion

Thanks again for a great plugin!!

Carl

Posted on
Tue May 21, 2013 11:39 pm
oliverochs offline
Posts: 6
Joined: Jul 28, 2012

Re: Hue Lights discussion

Hi
I've been using the plugin for some time with great success, so thanks for that!
After the recent upgrade, I'm not able to get indigo to turn off the lights (setting color to 60, saturation to 0, brightness to 0 and ramp rate of 0.4. Any thoughts? The Hue app works fine..
Oliver

Posted on
Tue May 21, 2013 11:53 pm
oliverochs offline
Posts: 6
Joined: Jul 28, 2012

Re: Hue Lights discussion

Ah, it works fine if I set RGB to 0 or use the brightness control.

Posted on
Wed May 22, 2013 12:47 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Hue Lights discussion

Hi Oliver. Are you still having trouble when setting the hue to 60, saturation to 0 and brightness to 0? If so, try reloading the Hue Lights plugin and let me know if you're still having trouble so I can try to reproduce it.

Page 5 of 103 1, 2, 3, 4, 5, 6, 7, 8 ... 103

Who is online

Users browsing this forum: No registered users and 0 guests