From 35c79eead4b4de12f674295b96e010416ec4a5ca Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sun, 19 Nov 2023 14:20:14 +0100 Subject: [PATCH] [sitemap] Combined conditions with AND (#2152) * [sitemap] Combined conditions with AND Related to openhab/openhab-core#3819 Signed-off-by: Laurent Garnier * Consider review comments Signed-off-by: Laurent Garnier --------- Signed-off-by: Laurent Garnier --- ui/sitemaps.md | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/ui/sitemaps.md b/ui/sitemaps.md index 5d922c86a4..37d4b1af39 100644 --- a/ui/sitemaps.md +++ b/ui/sitemaps.md @@ -591,9 +591,19 @@ If the parameter is not provided, the default is to display the Item. Visibility syntax: ```java -visibility=[item_name operator value, item_name operator value, ... ] +visibility=[item_name operator value, item_name operator value AND item_name operator value, ... ] ``` +You can set as many conditions as you want. + +A condition can be a single comparison or a combination of several comparisons all separated by the AND operator. +A condition including the AND operator will be considered as true if all individual comparisons are considered as true. +Of course, it is possible to reference a different item in each comparison. + +Note that `item_name` and `operator` are both optional. +If `item_name` is not provided, the Item name will default to the current Item. +If an operator is not specified, the operator will default to `==`. + Valid comparison operators are: - equal to `==`, unequal to `!=` @@ -601,7 +611,7 @@ Valid comparison operators are: - less than `<`, greater than `>` Expressions are evaluated from left to right. -The Item will be visible if any one of the comparisons is evaluated as `true`, otherwise it will be hidden. +The Item will be visible if any one of the conditions is evaluated as `true`, otherwise it will be hidden. **Examples:** @@ -609,12 +619,11 @@ The Item will be visible if any one of the comparisons is evaluated as `true`, o Text item=BatteryWarning visibility=[Battery_Level<30] Switch item=CinemaLight label="Cinema light" visibility=[TV_Power==ON] Switch item=LawnSprinkler visibility=[Day_Time=="Morning", Day_Time=="Afternoon", Temperature>19] +Switch item=LawnSprinkler visibility=[Day_Time=="Morning" AND Temperature>19] ``` In the third example above, a control for a lawn sprinkler will be visible if it is Morning, _OR_ if it is Afternoon, _OR_ if the temperature is above 19 °C. -Combining multiple conditions, for example Morning _AND_ above 19 °C is not supported. -To control visibility based upon combining multiple Items, or on more complex conditions, consider defining and using an additional intermediate Item that is set by a Rule. -Rules have a rich set of features that can support more involved scenarios. +In the fourth example above, multiple conditions are combined, a control for a lawn sprinkler will be visible if it is Morning _AND_ if the temperature is above 19 °C. ### Label, Value and Icon Colors @@ -625,11 +634,17 @@ The icon may be tinted depending on the state as well. **Label and Value Color Syntax:** ```java -labelcolor=[item_name operator value = "color", ... ] -valuecolor=[item_name operator value = "color", ... ] -iconcolor=[item_name operator value = "color", ... ] +labelcolor=[item_name operator value = "color", item_name operator value AND item_name operator value = "color", ... ] +valuecolor=[item_name operator value = "color", item_name operator value AND item_name operator value = "color", ... ] +iconcolor=[item_name operator value = "color", item_name operator value AND item_name operator value = "color",... ] ``` +You can set as many conditions as you want, along with a color for each condition. + +A condition can be a single comparison or a combination of several comparisons all separated by the AND operator. +A condition including the AND operator will be considered as true if all individual comparisons are considered as true. +Of course, it is possible to reference a different item in each comparison. + Note that `item_name` and `operator` are both optional. If `item_name` is not provided, the Item name will default to the current Item. If an operator is not specified, the operator will default to `==`. @@ -645,9 +660,14 @@ The following three lines are equivalent. ```java Text item=Temperature labelcolor=[>0="blue"] valuecolor=[22="green"] iconcolor=[22="green"] -Text item=Temperature labelcolor=[>0="blue"] valuecolor=[==22="green"] -Text item=Temperature labelcolor=[>0="blue"] valuecolor=[Temperature==22="green"] -Text item=Temperature labelcolor=[>0="blue", "gray"] valuecolor=[22="green", "gray"] +Text item=Temperature labelcolor=[>0="blue"] valuecolor=[==22="green"] iconcolor=[==22="green"] +Text item=Temperature labelcolor=[Temperature>0="blue"] valuecolor=[Temperature==22="green"] iconcolor=[Temperature==22="green"] +``` + +The line below illustrates setting a default color (gray) and how to combine multiple comparisons with an AND operator: + +```java +Text item=NumberItem labelcolor=[>0 AND <50="yellow", >=50="green", "gray"] valuecolor=[>0 AND <50="yellow", >=50="green", "gray"] iconcolor=[>0 AND <50="yellow", >=50="green", "gray"] ``` The line below illustrates the importance of operator order: