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

Be able to connect multiple conditions with AND in sitemap's valuecolor #3058

Closed
dilyanpalauzov opened this issue Aug 9, 2022 · 10 comments · Fixed by #3819
Closed

Be able to connect multiple conditions with AND in sitemap's valuecolor #3058

dilyanpalauzov opened this issue Aug 9, 2022 · 10 comments · Fixed by #3819
Labels
enhancement An enhancement or new feature of the Core sitemap

Comments

@dilyanpalauzov
Copy link
Contributor

Currenlty Sitemaps’s can have dynamic valuecolor=[…]. In the brackets conditions can be written, followed by colour. When a condition is met, the following colour is used and the remaining conditions are not evaluated.

I want to be able conjunct two conditions, as in valuecolor=[A==ON AND B==ON ⇒ "green" A==ON AND B==OFF ⇒ "RED" A==OFF AND B==ON ⇒ "blue" A==OFF AND B==OFF ⇒ "white"], or the equivalent but shorter valuecolor=[A==ON AND B==ON ⇒ "green" A==ON="red" A==OFF AND B==ON ⇒ "blue" A==OFF="white"].

Rationale:

I have a Group with item=. By using the value of the item I want to encode the state of two different items in the group, so that I can conclude that states without having to open the Group by clicking on it.

@wborn wborn changed the title Be able to connect multiple connditions with AND in sitemap's valuecolor Be able to connect multiple conditions with AND in sitemap's valuecolor Aug 20, 2022
@J-N-K
Copy link
Member

J-N-K commented Apr 9, 2023

@lolodomo I would like to hear your opinion here. To me it looks very complex and a corner case. IMO it would be better to have valuecolor=[AnotherItemThatContainsTheColor] (so similar to what we have with the conditions now, just without any condition, using the state if the item as color). The problem of the OP could the be solved by using a rules that calculates the color, which is even more flexible. Would it be possible to implement something like that?

@J-N-K J-N-K added sitemap enhancement An enhancement or new feature of the Core labels Apr 9, 2023
@lolodomo
Copy link
Contributor

lolodomo commented Apr 12, 2023

I agree that the original proposal was too much complex. And in case we would add the AND operator, then why not adding other operatros like OR and NOT ? Too much complex and too much specific.

Your idea @J-N-K could even be extended to provide the ability to use an item value as color in any labelcolor/valuecolor/iconcolor condition. This is not too much difficult, even if not trivial. I have a good knowledge where is the code to be changed in core framework. Any state change of the pointed item should trigger an update of the item using it as color value.

This would require to consider the case the item is not of type String or its state is NULL or UNDEF. I would suggest to ignore the color condition in that case.

How to distinguish a color value from an item containing the color value in the syntax ? A color is a string enclosed in quotes. An item would be an ID without quotes. This would require a change of sitemap syntax to add the ability to fill an ID (item name).

WDYT ?

@J-N-K : do you imagine real use cases for that ? Or is it something that will be used only by less than 5 users all over the world ? ;)

@J-N-K
Copy link
Member

J-N-K commented Apr 12, 2023

I think a Number item would do as well, an integer value can always be interpreted as RGB, we also have conversions for that: ColorUtil.hsbTosRgb. NULL or UNDEF can always fall back to the value that would be used if *color is not set.

I think the sitemap change would be backward compatible in this case, so I don't see the risk of breaking something there.

Regarding the use-case: I really don't know. I don't even use labelcolor or iconcolor, only valuecolor. I guess @rlkoshak would say: if it's there, someone will use it. But at least I would set my priority to other things. Depends a bit on how complex it is.

@dilyanpalauzov
Copy link
Contributor Author

dilyanpalauzov commented Apr 12, 2023

NOT can be emulated for the whole expression by using operator != . valuecolor=[cond-A OR cond-B=="green"] is the same as valuecolor=[cond-A=="green", cond-B=="green"]. Both OR and NOT are available now, as far as no bracketed expressions are meant. Just AND is missing.

Use case: I have a group with several items. I want to have the valuecolor of the group present the ON-OFF states of two items of the group. Then I see the on the main-sitemap-level just the group identifier and by the color I understand the values of that two items. Currently I have an extra item, which can store four values and based on the four values set the valuecolor of the group.

@lolodomo
Copy link
Contributor

@dilyanpalauzov : is our proposal OK for your use case ? You would still need an extra item and a rule that would set the expected color in that item.

@dilyanpalauzov
Copy link
Contributor Author

My current template is: valuecolor=[A=="green"="green", A=="red"="red" and so on]. So being able to specify just the item will simplify the chain.

@dilyanpalauzov
Copy link
Contributor Author

I have one more use case. When a pump works and moves water it consumes 700W. When there is no water to move, the pump turns off and consumes 0W. However sometimes the pump does not turn off, when it should, and then consumes between 400W and 440W, without moving any water (but air). So when the pump consumes between 400 and 440W I want to render the valuecolor as red, otherwise keep the default valuecolor. With AND syntax `valuecolor=[item>=400 AND item<=440="red"] would be very useful.

@dilyanpalauzov
Copy link
Contributor Author

For the last use-case I have now labelcolor=[rd_power<300="", rd_power>550="", "red"]. If the power consumption is below 300, or is above 500 do not set the color, otherwise set the color to red. So this works without explicit AND.

@lolodomo
Copy link
Contributor

I will try to add the AND operator in color conditions.

lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 27, 2023
Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 27, 2023
Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 28, 2023
…rules

Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>

Fix
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 28, 2023
…rules

Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 30, 2023
…ditional rules for icon

Allow multiple conditions with AND operator in visibility/color/icon rules

Closes openhab#3058

Also allow dynamic icon based on other item states.
Allow dynamic icon even with non OH icon sources.

Example: icon=[item1>0=temperature,==0=material:settings,f7:house]

Related to openhab/openhab-webui#1938

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 30, 2023
…ditional rules for icon

Allow multiple conditions with AND operator in visibility/color/icon rules

Closes openhab#3058

Also allow dynamic icon based on other item states.
Allow dynamic icon even with non OH icon sources.

Example: icon=[item1>0=temperature,==0=material:settings,f7:house]

Related to openhab/openhab-webui#1938

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Sep 30, 2023
…ditional rules for icon

Allow multiple conditions with AND operator in visibility/color/icon rules

Closes openhab#3058

Also allow dynamic icon based on other item states.
Allow dynamic icon even with non OH icon sources.

Example: icon=[item1>0=temperature,==0=material:settings,f7:house]

Related to openhab/openhab-webui#1938

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Oct 1, 2023
…ditional rules for icon

Allow multiple conditions with AND operator in visibility/color/icon rules

Closes openhab#3058

Also allow dynamic icon based on other item states.
Allow dynamic icon even with non OH icon sources.

Example: icon=[item1>0=temperature,==0=material:settings,f7:house]

Related to openhab/openhab-webui#1938

Unit tests added or extended to cover the new features.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Oct 1, 2023
…ditional rules for icon

Allow multiple conditions with AND operator in visibility/color/icon rules

Closes openhab#3058

Also allow dynamic icon based on other item states.
Allow dynamic icon even with non OH icon sources.

Example: icon=[item1>0=temperature,==0=material:settings,f7:house]

Related to openhab/openhab-webui#1938

Unit tests added or extended to cover the new features.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor

lolodomo commented Oct 1, 2023

The usage of (multiple) AND conditions is now possible with the PR I proposed. No change in sitemap UIs is required. We just have to wait for the review and merge.

lolodomo added a commit to lolodomo/openhab-core that referenced this issue Oct 2, 2023
Concerns labelcolor, valuecolor and visibility

Also fix wrong positions of ")" in Sitemap.xtext

Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Oct 2, 2023
Concerns labelcolor, valuecolor and visibility

Also fix wrong positions of ")" in Sitemap.xtext

Closes openhab#3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
kaikreuzer pushed a commit that referenced this issue Oct 8, 2023
Concerns labelcolor, valuecolor and visibility

Also fix wrong positions of ")" in Sitemap.xtext

Closes #3058

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
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 of the Core sitemap
Projects
None yet
3 participants