openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
930 stars 428 forks source link

[ColorUtil] New methods kelvinToXY and xyToKelvin #4367

Closed andrewfg closed 2 months ago

andrewfg commented 2 months ago

Resolves #4369

This PR provides two new methods in the ColorUtils class as follows:

  1. New method kelvinToXY() to convert a colour temperature in Kelvin to a point on the colour temperature locus in the CIE XY colour space, as described here
  2. New method xyToKelvin() to convert a point on the colour temperature locus in the CIE XY colour space to a colour temperature in Kelvin, as described here

image

Note: the PR is created in ColorUtils in OH Core in case these conversions might be needed in other bindings.

Signed-off-by: AndrewFG software@whitebear.ch

openhab-bot commented 2 months ago

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/dimmer-and-color-item-to-same-channel/157241/27

holgerfriedrich commented 2 months ago

Maybe some more background information, in case the sources given above are no longer available.... https://en.wikipedia.org/wiki/Correlated_color_temperature#Approximation

Unfortunately, the original publication is hidden behind a paywall...

andrewfg commented 2 months ago

See https://github.com/openhab/org.openhab.binding.zigbee/pull/855

holgerfriedrich commented 2 months ago

@andrewfg is this still a draft or shall I have a look?

andrewfg commented 2 months ago

is this still a draft or shall I have a look?

I was keeping it as draft while writing the respective (first) addon PR .. in case there may be learnings from it. ..

andrewfg commented 2 months ago

do not like that huge lookup table

Honestly me neither. But as you say the function is difficult to invert.

andrewfg commented 2 months ago

Many thanks @holgerfriedrich :)

holgerfriedrich commented 1 month ago

Do you think we should expose this to DSL rules (core repo org.openhab.core.model.script/src/org/openhab/core/model/script/actions/CoreUtil.java; docs repo, addons/actions.md) and to javascript?

andrewfg commented 1 month ago

@holgerfriedrich are any of the other public static methods of the ColorUtils class exposed? If so then I suggest to be simply consistent across all such methods.