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.