jvmahon / Homebridge-HomeSeer4

Homebridge Plugin for HomeSeer 3 and 4
28 stars 8 forks source link

Add Color temperature as optional parameter? #96

Closed wwhite74 closed 4 years ago

wwhite74 commented 4 years ago

In my kitchen I have 2 pieces of under cabinet LED tape. It's variable white. I use fibero RGBW controllers to actually control the tape. (these aren't exposed to homebridge/homekit)

I have set up 3 dummy "bulbs" in homeseer / homebridge. 1 for level on each piece of tape, and 1 for color temperature. I then use scripting in homeseer to actually change the tape.
Color temp is 0% - full warm, 50% - full warm and cool, 100% - full cool. Those levels are adjusted down based on the level channel for each piece of tape.

Especially with the new "auto color temp" coming in iOS 14, I'd love to combine the level and color temp to a single homekit device, Plus having the color channel not respond to "turn on/off all the lights" would be nice.

I can make the color temp use any range. It's currently 0-100 because that's what works as a bulb, but I can easily make it either kelvin or mired, depending on how homekit wants to send it. And, I am aware I will have to either make a second color device, or combine both pieces of tape into one dummy level device.

jvmahon commented 4 years ago

Here's a quick thought ...

  1. There's a HomeKit characteristic called "Color Temperature" which allows you to specify a value of 50-400 on the Mirek scale (which is related to the mired scale. https://en.wikipedia.org/wiki/Mired

  2. If you could set up a HomeSeer virtual device with the proper mired scale value (50-400), I could set it so that HomeKit reads that device and sets the color temperature.

  3. So, for example, if brightness (0-100) was set by device reference 123 and color temperature was the mirek value 50-400 represented in device 456, you'd set up that bulb using something like

    {"type":"lightbulb", "ref":123, "colorTemperature":456}

Changing the color temperature on your iOS device would then change the associated device (456) at HomeSeer. You'd have to handle all the code to then drive the light itself.

Would this work for you?

wwhite74 commented 4 years ago

that would be perfect, and exactly they way I was thinking it would work.

I can make the scale whatever it needs to be. The adjustments to my script would be trivial.
I'm sure it won't be "color accurate" but it's close enough for me.

thank you both for this, and the plug-in in general, it's been very nice to have. I'm an "advanced beginner" in scripting, and this has let me add a bunch of stuff to homekit that I probably would not have been able to otherwise.

jvmahon commented 4 years ago

OK - I'll try adding that feature. It may be a week or two before I can get to it.

jvmahon commented 4 years ago

Update to 1.0.4 Set colorTemperatureRef to the reference of your HomeSeer color temperature control device as per example:

                {"type": "Lightbulb", "ref": 213, "colorTemperatureRef":1314},

Please confirm that this works.

wwhite74 commented 4 years ago

it is working.

I have to play around with the levels sent by my script, as apple's color wheel doesn't seem to be very linear. The adjustment in the Eve app seems a bit better

when adjusting the color temperature using apple's "wheel" noon to 3:00 is 350 steps (values 500 to 150) or (2000k to 6600k) but 3:00 to 6:00 is only 10 (values 150 to 140) os (6600k to 7000k)

in looking at it more, on a Hue bulb, the "cool side" (bottom) of the wheel is much bluer than the one that was added for this I've been digging around in the homekit specs, but can't seem to find a min/max value for color temp,

Screen Shot 2020-07-28 at 10 23 38 AMScreen Shot 2020-07-28 at 10 23 59 AM

Homeseer color temp test “Clock position” - Mired value - (color temp) 6:00 - 140 - (7000k) 3:00 - 150 - (6600k) 12:00 - 500 (2000k)

Hue (using homekit to control) 6:00 - 90 - (11,200k) 3:00 - 150 - (6600k) 12:00 - 562 - (1800k)

When controlled from the hue app, the hue bulb only goes 150 to 500, which is what the bulb says it supports. I think apple actually is actually sending an “XY” color value to hue instead of a color temp value. The Eve app also seems to use "XY" in ct mode. So it must be the way Hue sets it up.

(I’m getting the hue values by polling status from the hue hub with my own script. When changed from homekit or eve app, the color mode is “XY” but when using the hue app it’s “CT”)

If you can find a way to adjust the range for CT, and add a pair of parameters to set those, that would be awesome. Otherwise I can use it as-is.

jvmahon commented 4 years ago

From the HomeKit spec, the range is 50-400 mirek:

image

image

wwhite74 commented 4 years ago

got it, that makes sense, the hue bulbs I have are color + white, so apple must handle the 2 differently. That's probably why they work the way they do, and I don't have any native homekit white only bulbs to try out.

although it is odd that the values it sends seem to be 140 to 500.

I'm still trying to figure out my way around the apple dev pages, sometimes I find what I want easily, sometimes I can't find it at all, I've seen pages like what you posted, just couldn't find them this time. They've made the developer pages pretty, but hard to find stuff.

apparently apple is using the "proper" mirek, which no-one else uses, Most use mired. https://en.wikipedia.org/wiki/Mired

Thanks again for the quick add of this, I should be able to get it working from my end now. I think we're done, feel free to close if you've got nothing else.

jvmahon commented 4 years ago

Yes, color is handled differently than colorTemperature and they are mutually exclusive

In Homekit, a bulb can be . . . 1) A simple binary (on / off) light 2) A simple light with dimming 3) A light with dimming and color Temperature, or 4) A light controlled with HSV values (Hue, Saturation, Brightness).

There is no direct RGB - but there is a mathematical mapping between RGB and HSV which could be implemented.

I've just ordered a RGB Zwave bulb from Amazon and plan to add RGB support - maybe over the weekend.

wwhite74 commented 4 years ago

I didn't realize that even though a bulb has a CT option, if it's a color bulb, it's sending a color value, not temperature. As opposed to a color temp only bulb, which sends mired/mirek

I was able to add a range to the color temp. I used what my tape is capable of and just hardcoded the range. and it seems to work better

Theres no rush, and I don't need a special version, but could you add colortemp min/max options

around line 1320 - lib/HomeKitDeviceSetup.js

thisService.colorTemperatureControl
   .updateUsingHSReference(that.config.colorTemperatureRef)
   .setConfigValues(that.config)
   .setProps({minValue:153, maxValue: 400})
   .on('set', function(value, callback, context)

Thanks again