I would like to create a widget that list all the items in a group with their default controls (i.e. a switch represented by a switch, or dimmer represented by a slider). This would look similar to the list that pops up when the Action is “Group” on an item, however I want this to be included directly on a UI page.
First, I don’t believe any of the standard widgets which support this, correct?
Second, if I use oh-repeater - how would I select the appropriate oh--item to display? Is there a “smart” oh--item which can be used to display the appropriate controls based on the item?
I fail to use numerical comparisons for Number:Dimensionless items in the oh-repeater filter.
The items I want to look at, represent the battery-charge of sensors and are set up as Number:Dimensionless.
From Jython, I can check for low battery using the floatValue():
for item in battery_group.getMembers():
if item.type == "Number:Dimensionless":
# Battery modelled as fill-percentage
if item.state.floatValue() < battery_low_warning_at_percent:
In my widget , I just cannot get hold of the numerical value for the item state.
prints out the state as e.g. 25 % and I can do string-machtes for that:
filter: items[loop.item.name].state == "25 %"
But how can I get to the numerical value and do, e.g.:
filter: items[loop.item.name].state <= 10
I tried things like loop.item.state.floatValue() (and other methods I knew of) but to no avail.
I was unable to find any documentation on what functions are supported by the filter-expression.
Is this documented somewhere? If not - wouldn’t that be a helpful addition?
In the widget editor the items object returns strings no matter what the item type because that’s how the information is returned from an api call. So if you want a numerical comparison, you have to convert the string using Number(). In your case you have to strip away the % but, because there’s a space, that’s easy with the split() method.
parseInt and parseFloat are certainly useful alternatives. I can’t tell you if there’s a performance difference but if there is I suspect it’s minuscule. I prefer Number() in the widgets whenever possible because I like its null handling better for display (personal pet peeve seeing NaN’s in the UI), although as the filter expression is not a displayed value that’s less relevant in this case.
The split(" ") will also intelligently handle “76” vs “76 %” so no worries there.
As it might be interesting for someone else who’s looking for a widget, which will display battery warnings which are modelled as switches as well as battery levels which are modelled as percentages, here is my code.
To the best of my knowledge, the expression parser the widgets use is missing a few key pieces to do this easily by staying with the JSON (regex in string.replace(), and array.keys() method off the top of my head). I’d just resort to some simple string manipulation. For the repeater’s array strip the outer braces and use a simple string split:
I really like the OH3 UI and the standard UI rendering from the semantic model is really great. Especially with the possibility to assign custom widgets to the model items. Works fantastic for the standard page with tabs.
But all that just stops when developing pages and widgets. Is there a way to use the features from the semantic model? Something like.
In some cases you may want to add some points to the location group directly, in addition to the equipment. For instance adding a temperature measurement to a room location, because it represents the temperature in the room.