Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deconz] Adjust color-temperature handling, Extend bulb support #7900

Merged
merged 17 commits into from
Jun 18, 2020

Conversation

HahnBenjamin
Copy link

Add scaling of upper\lower level for ct values
Add IKEA CWS bulb support

Signed-off-by: Benjamin Hahn [email protected]

@TravisBuddy
Copy link

Travis tests were successful

Hey @HahnBenjamin,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

1 similar comment
@TravisBuddy
Copy link

Travis tests were successful

Hey @HahnBenjamin,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Comment on lines 86 to 87
private final int CT_MAX;
private final int CT_MIN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make these variable names camelcase.

properties.put(Thing.PROPERTY_VENDOR, light.manufacturername);
properties.put(Thing.PROPERTY_MODEL_ID, light.modelid);

if (light.ctmax != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard openhab coding format requires that all if statements should have brackets.

Comment on lines 163 to 164
.withProperty("id", lightID)
.withProperty(UNIQUE_ID, light.uniqueid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put these in the properties map to begin with? It would make things consistent.

@@ -129,6 +138,9 @@ private void addLight(String lightID, LightMessage light) {
case COLOR_DIMMABLE_LIGHT:
thingTypeUID = THING_TYPE_COLOR_LIGHT;
break;
case COLOR_LIGHT:
thingTypeUID = (light.ctmin != null) ?THING_TYPE_EXTENDED_COLOR_LIGHT :THING_TYPE_COLOR_LIGHT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply formatting here

@J-N-K
Copy link
Member

J-N-K commented Jun 12, 2020

Please do not merge this one. I have no time this morning but this will break functionality for some users. I‘ll comment later today.

@HahnBenjamin
Copy link
Author

Please do not merge this one. I have no time this morning but this will break functionality for some users. I‘ll comment later today.

I assume I must make the new properties known to the existing things. Any pointer or reference on how to do this correcly would be much appreciated

@J-N-K
Copy link
Member

J-N-K commented Jun 12, 2020

That would be easy. You can check in initialize if all needed properties are present (or after the initial state was received) and then call a method like updateProperties to set the properties.

Unfortunately the situation is more complex. Your implementations is similar to what I originally implemented. I later deleted that code and set fixed limits for the color temperature.

But there is either a bug in the deconz software or in some Ikea bulbs, where minct is reported as 0 and maxct as 65535. However, if you send a vaöue outside of the defined range (like I have implemented it now), the colormode of the bulb switches to xy and no further ct commands are possible. The only way to recover is to use the deconz gui and do some "read/set property" calls (not sure what exactly un-bricked the bulb).

So you would have to at least check if the reported values for ctmin and ctmax are within the allowed range and use the default range if they are not. Another problem is that for different bulbs a value of say 50 does not represent the same color. IMO the better solution would be to use a custom state description provider and set the min/max values according to the reported (or assumed) range.

I do not understand the change for the extended color light. It should work withput that. Can you show what is reported by the light (response of REST API call for all lights, you can delete all information that does not belong to the light).

@cpmeister cpmeister added the enhancement An enhancement or new feature for an existing add-on label Jun 16, 2020
@TravisBuddy
Copy link

Travis tests were successful

Hey @HahnBenjamin,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see my comment regarding the wrong reporting of ctmax and ctmin? This needs to be taken care of. My suggestion would be: if the reported values are outside of 153-500, set them to 153 or 500 respectively. This should always be ok, since deconz does not accept values outside of that range.

Another idea: If we scale it properly, we could report the color temperature value in K. The conversion can be found here: https://en.wikipedia.org/wiki/Mired

@HahnBenjamin
Copy link
Author

@J-N-K I was actually looking more deeply into the Ikea CWS light issue and figured out that it actually does not support setting ct value. The ct value is converted into xy-values in deconz as a workaround. I will try to adjust the add-on code accordingly. I will further need to dig a bit deeper into the openhab architecture to find out the internals. I had tested the mired conversion already locally but did not know how to incorporate this. The "custom state description provider" is something i will look for.

For my setup there are only correct ct ranges reported, but incorrect reporting should be considered.
The ct values accepted are actually defined by the ctmin and ctmax values itself.

The adjustments in the extended color light are taking into account the colormode the bulb is currently operating in. During the update the color channel was changing to a value different to what was set. i assume only the state variables of the current colormode are valid for certain bulbs.

properties.put(Thing.PROPERTY_MODEL_ID, light.modelid);

if (light.ctmax != null && light.ctmin != null) {
properties.put(PROPERTY_CT_MAX, Integer.toString(light.ctmax));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define private static final int CT_MAX = 500; in this class

Suggested change
properties.put(PROPERTY_CT_MAX, Integer.toString(light.ctmax));
int ctmax = light.ctmax > 500 ? 500 : light.ctmax;
properties.put(PROPERTY_CT_MAX, Integer.toString(ctmax));

and the same for min

private int unscaleColorTemperature(double ct) {
return (int) (ct / 100.0 * (500 - 153) + 153);
private int unscaleColorTemperature(final double ct) {
return (int) (ct / 100.0 * (ct_max - ct_min) + ct_min);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (int) (ct / 100.0 * (ct_max - ct_min) + ct_min);
int ctMired =(int) (100000.0 / ct);
if (ctMired > ctmax) {
return ctmax;
} else if (ctMired < ctmin) {
return ctmin;
} else {
return ctMired;
}

and the conversion in the other direction below. We can add teh dynamic state description later. You haver to adjust the documentation accordingly (color temperature is not 0->100 but xxx K -> xxx K. If you change that today, we can merge it before the 2.5.6 release and it is not a breaking change since 2.5.5 did not contain light support for deconz.

@TravisBuddy
Copy link

Travis tests were successful

Hey @HahnBenjamin,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
See ZigBee Cluster Library Specification Page 5-5 - 327

Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Benajmin Hahn <[email protected]>
@TravisBuddy
Copy link

Travis tests were successful

Hey @HahnBenjamin,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@HahnBenjamin
Copy link
Author

@J-N-K i tested this version with my local setup and it worked well for various bulbs of different vendors

@HahnBenjamin HahnBenjamin requested review from cpmeister and J-N-K June 18, 2020 10:26
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM. Many thanks for your fast Action.

@J-N-K
Copy link
Member

J-N-K commented Jun 18, 2020

@cpmeister Are your concerns already adressed by the last changes?

Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from @J-N-K requested changes, LGTM

Signed-off-by: Benajmin Hahn <[email protected]>
@J-N-K J-N-K merged commit 86ad836 into openhab:2.5.x Jun 18, 2020
@J-N-K
Copy link
Member

J-N-K commented Jun 18, 2020

Many thanks. Do you want to investigate the state description provider or should I do that?

@HahnBenjamin
Copy link
Author

Can I find information about it in openHAB Developer Guide?

@HahnBenjamin HahnBenjamin deleted the deconz branch June 18, 2020 22:00
@cpmeister cpmeister added this to the 2.5.6 milestone Jun 19, 2020
@J-N-K
Copy link
Member

J-N-K commented Jun 19, 2020

Basically you need to implement a DynamicStateDescriptionProvider (like https://github.com/openhab/openhab-addons/blob/2.5.x/bundles/org.openhab.binding.onewire/src/main/java/org/openhab/binding/onewire/internal/OwDynamicStateDescriptionProvider.java), add that as reference to the handler factory, pass it to the thing handler and create a StateDescription (like

if (dynamicStateDescriptionProvider != null) {
StateDescription stateDescription = StateDescriptionFragmentBuilder.create()
.withReadOnly(ioConfig.get(i).isInput()).build().toStateDescription();
if (stateDescription != null) {
dynamicStateDescriptionProvider.setDescription(ioConfig.get(i).getChannelUID(),
stateDescription);
). Make sure to remove it on disposal of the handler.

knikhilwiz pushed a commit to knikhilwiz/openhab2-addons that referenced this pull request Jul 12, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Sep 19, 2020
…hab#7900)

* Add property for ct colormode upper and lower limit

Signed-off-by: Benajmin Hahn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants