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

Recognize color mode of color bulb #336

Merged

Conversation

TomTravaglino
Copy link
Contributor

Resolves #326

This is an approach to recognize if the color has been set via color scheme or via color temperature scheme. It corresponds to the solution realized in eclipse-archived/smarthome#5762 which sets the color temperature to UnDefType.NULL when the color mode is not "color temperature".

Your feedback is welcome.

@cdjackson cdjackson self-requested a review December 15, 2018 12:23
Copy link
Contributor

@cdjackson cdjackson left a comment

Choose a reason for hiding this comment

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

One question. This PR sets the color temperature channel to UNDEF if the color mode is not in color temp. Why doesn't it set the color channel to undef if the mode IS color temp? If we're saying they are exclusive, then shouldn't both channels be consistent?

@TomTravaglino
Copy link
Contributor Author

One question. This PR sets the color temperature channel to UNDEF if the color mode is not in color temp. Why doesn't it set the color channel to undef if the mode IS color temp? If we're saying they are exclusive, then shouldn't both channels be consistent?

I've implemented it to behave like the Hue binding. Here you can see that there only the color temperature is set to UNDEF but never the color.

@cdjackson
Copy link
Contributor

cdjackson commented Dec 16, 2018 via email

@TomTravaglino
Copy link
Contributor Author

@kaikreuzer and @triller-telekom did the review of the Hue PR. Maybe they know why in the Hue binding the color temperature is set to UNDEF when the color mode is not in color temp but not the other way around.

@triller-telekom
Copy link
Contributor

Maybe it’s considered that color is still valid even when in color temp mode?

That's exactly the reason behind it: See eclipse-archived/smarthome#5762 (comment) where Kai says:

I don't think that this [setting the color_channel to NULL] makes sense, because the color channel can always have a valid state and you always want to be able to display it in a color picker (e.g. if the user switches from slider to color picker).

So the way @TomTravaglino implemented it is correct.

Does that make sense to you @cdjackson ?

@cdjackson
Copy link
Contributor

cdjackson commented Jan 2, 2019 via email

@triller-telekom
Copy link
Contributor

I had to read your answer quite a few times, so let me sum up what I understand from it:

You are saying that if you set a colourtemperature and keep the colour (i.e. HSB or x/y) value, then the zigbee bulb that you have reports two colours: One in a colourtemperature (the newly set one) and the colour one (old value which was previously set).

Then you have the problem that you have to update the OH channel and don't know which value to pick. Is that correct?

In this case I would agree with you that in the zigbee binding we should set the colour value to NULL once we set a colourtemperature, in addition to setting the temperature NULL while setting a colour value.

@cdjackson
Copy link
Contributor

Sorry for the bad explanation.

Yes - basically you're right with your understanding. The color temperature is not handled as a color - it's a different mode. The color and colortemperature are independent (at least in this bulb - I've not tried others yet) - and the mode is what differentiates them.

It's the same (or similar) with the way that Level control works (at least in some devices) - a device can report OFF, but report the Level to be 50% - that doesn't mean it is on - just that if you change the On/Off mode to On, it will come on at 50%.

I hope that makes sense?

I also had a look through the ZCL docs, and there is nothing in there to link color and color-temperature. The two seem to be treated as separate modes. The docs talk about switching modes when a color temperature command is received, but it doesn't say that is should update the current X/Y or Hue attributes, so I would assume they should remain set as they were.

@TomTravaglino
Copy link
Contributor Author

I changed ZigBeeConverterColorColor to set the channel state to UNDEF when the color mode turns to color temp.
At the first glance it worked but then I observed that attribute changes are periodically reported to the converters which then overwrite the state. This happens although the values of the attributes don't change.

Is this an expected behavior?

I tested with a Osram Smart+ Classic E27 Multicolor and a Osram Lightify CLA60 RGBW.
I attached a log file which contains the item events and the log entries produced by the converters.

colormode-attribute-changes.txt

@cdjackson
Copy link
Contributor

I've not looked at the log, but I suspect what you are seeing is what I eluded to above? That is that attribute reports will be sent to report color, even when the bulb is in the CT mode, and unless you use the state you will update the color when the device is in CT mode?

Is that what you see? I will take a look at the log later, but if I understand your question, then yes, this is expected.

@TomTravaglino
Copy link
Contributor Author

That is that attribute reports will be sent to report color, even when the bulb is in the CT mode

And report happens although nothing changed.

and unless you use the state you will update the color when the device is in CT mode

I update the state of the color channel although the device is in CT mode.

@cdjackson
Copy link
Contributor

And report happens although nothing changed.

Yes, that is correct. In the reporting, we have to set a minimum and maximum report time. So if there are changes, the reports will come in at the minimum report time, and if there is no change the reports will come in at the maximum report time.

I update the state of the color channel although the device is in CT mode.

I would suggest that you need to not update color if it is in CT mode - ie you need to remember the color mode, and only update color if CM is in color mode, and only update CT if CM is in CT mode. Otherwise the system is going to propagate incorrect state to the user.

- Enable reporting of color mode attribute in color temperature converter
- Handle update of color mode attribute and set color temperature to UnDefType.NULL
  when color mode is not 'color temperature'

Signed-off-by: Tommaso Travaglino <[email protected]>
from beeing updated by periodical attribute reporting

Signed-off-by: Tommaso Travaglino <[email protected]>
@TomTravaglino TomTravaglino force-pushed the 326-Recognize-color-mode-of-color-bulb branch from b614e1d to ba41e65 Compare January 7, 2019 08:44
TomTravaglino and others added 2 commits January 7, 2019 15:35
@TomTravaglino
Copy link
Contributor Author

@cdjackson I updated the PR and had to merge master into my branch. Unfortunately the checks fail with this message

14:45:12 [ERROR] Failed to execute goal org.openhab.tools.sat:sat-plugin:0.5.0:checkstyle (default) on project org.openhab.binding.zigbee: Unable to execute mojo: Execution null of goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle failed: Plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.17 or one of its dependencies could not be resolved: Could not find artifact org.eclipse.platform:org.eclipse.equinox.p2.touchpoint.eclipse:jar:2.2.200 -> [Help 1]

Maybe a temporary problem. Is there a way to restart the checks?
Btw, on my local machine the build completes without any issues

@TomTravaglino
Copy link
Contributor Author

The checks have passed now. Apparently it was a temporary problem.

@TomTravaglino
Copy link
Contributor Author

Gentle reminder 😉

@cdjackson
Copy link
Contributor

Sorry - I will look at this once CI is working again.

@AfromD
Copy link

AfromD commented Jan 13, 2019

I am watching this with interest, as I had a similar request some time ago.
#39

I have solved this privately by programming a dummy CT channel as a rule, and using that to convert CT commands to HSB commands, thus always keeping my bulbs in HSB mode whilst being able to give color temperature commands. I kind of made the same conclusions as you all did above, that the color channel is always valid and useful, that is why I am translating CT into HSB. This way the state of the bulb is always refelected correctly in the HSB channel.
Now when actually using the CT for control, it would be useful to have a mechanism to reflect that back into the HSB channel. (saves you from checking CT for !NULL and then applying custom logic). I had a look at Tom's commits above, and didn't find it there. The Philips Hue bulbs do not do this by themselves, they do not update their HSB state when in CT mode, so this will need to be done in the binding.
In my rule I use the following HSB values for any CT, which seem right for philips lights: Hue fixed at 45, saturation= CT as PercentType * 0,6, and brightness as is.
Just as an idea, what to update the HSB channel with whenever CT is commanded.

Copy link
Contributor

@cdjackson cdjackson left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @TomTravaglino

@cdjackson cdjackson merged commit 59104a6 into openhab:master Jan 14, 2019
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/philips-hue-color-temperature-not-updated-when-switching-light-on/53181/10

1 similar comment
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/philips-hue-color-temperature-not-updated-when-switching-light-on/53181/10

@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/zigbee-binding/15763/1942

@baku104788
Copy link

Joining the conversation here vs the one on community.openhab - Anyway Chris your last post mentioned you guys might implement a dimmer channel back again so we have CT/Dimmer/Color?? That does seem to make a lot of sense to me as that would then allow us to always see a brightness state. One other thing I just thought of regarding this current UNDEF is that if we are in CT mode and want to go back to color mode keeping the previous state we currently have no way to do that as the color state would have been switch to UNDEF. It would almost be best to have a switch that shows color mode on/off and then leave the CT and Color items alone... that way you can send the command to the color mode to switch it. All in that would then leave us with Color HSB , Brightness Dimmer, CT Dimmer and a color mode switch. I know the brightness is redundant when using HSB but obviously we want to keep color as an HSB type. I think that channel layout would allow for the most robust management and operation of the bulbs. What do you guys think?

@SuperSchelli
Copy link

I got loads of 0210 Bulbs from Philips and i am using the deconz bridge. Using the latest Snapshot build.

Atm, you can read the Brightness value by just assigning a Dimmer to the color channel, but as stated you have the problem, that if you just change one channel, the others are not updated. If you then touch another channel there can be a huge jump in bulb visibility, since this channel has some random old value...
I saw ways to derive an approximate ColorTemperature Value from the color Value and vice versa posted by CWeitkamp some place.

I was about to program my OH2 functionality with rules as following :
As jfrank1845 posted above. 4 Channels.

1 Switch between ColorTemperature and Color Mode (so i know which mode is active)
2 Dimmer Brightness
3 Dimmer CT
4 Color Channel HSB

When you adjust any of the 3 Channels 2-4, the other 2 Channels are updated with the respective values or the ones that are closest to the changed Channel.
If you move 2 - the mode remains whatever it is, just brightness changes
If you move 3 - you switch to CT mode but adjust the color channel along with it
if you move 4 - you switch to color mode but adjust the CT channel and brightness with it

@cdjackson
Copy link
Contributor

i am using the deconz bridge

This binding doesn't support the deconz bridge so I suspect you're using the deconz binding?

@SuperSchelli
Copy link

SuperSchelli commented Feb 27, 2019

Yep, true, but i am having the exact same trouble with the hue binding emulated by deconz atm. have to take a look there what this is doing, but it seems to me the functionality is approx the same
sorry for the screwup, but the discussion is interesting nonetheless
The hue binding atm has only 2 channels for those bulbs 0210 color and ct and you use color for switching on off, adjusting brightness and color... which i find confusing... maybe i am doing something wrong...
i have ordered a cc2531 USB Stick and wanted to try around with this one as well, that should use this binding then if i am not mistaken.

@cdjackson
Copy link
Contributor

cdjackson commented Feb 27, 2019 via email

@SuperSchelli
Copy link

Well. I wanted to add, that there are also bulbs, that can only handle a color channel and no CT channel.

Now I have rooms which have a mixture of bulbs in them, but now I just want it darker, I don't want to adjust all bulbs on their own. so u want 1 brightness slider for the whole room, but depending on which bulb I control this command needs To be translated into the right channel for each bulb, depending on its capabilities.
Now next imagine I want to change colors with only one slider, but some bulbs don't have a color channel. still if that color is a lot darker, it would be cool for the other bulbs to at least dim down a bit, or go to a warmer CT mode to blend in more with the selected color. this "problem" is indeed not a binding related thing (or you could also say, faces every binding)., so it could be more like a feature for Openhab, since I guess more people want this feature sooner or later... maybe a function to translate values or just have the ability to stick all the bulbs in one group and use one slider...

@TomTravaglino TomTravaglino deleted the 326-Recognize-color-mode-of-color-bulb branch March 7, 2019 12:56
@cdjackson cdjackson added this to the 2.5 milestone Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recognize color mode of color bulb
7 participants