Skip to content

Commit

Permalink
[sitemap] Combined conditions with AND (#2152)
Browse files Browse the repository at this point in the history
* [sitemap] Combined conditions with AND

Related to openhab/openhab-core#3819

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

* Consider review comments

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

---------

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Nov 19, 2023
1 parent b283dbe commit 35c79ee
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions ui/sitemaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,30 +591,39 @@ 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 `!=`
- less than or equal to `<=`, greater than or equal to`>=`
- 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:**

```java
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

Expand All @@ -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 `==`.
Expand All @@ -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:
Expand Down

0 comments on commit 35c79ee

Please sign in to comment.