A couple of simple oh-repeater examples

Ouch. :wink:
… but clever …

Thanks for the hint!

I suppose you could always recreate the list widget using the raw f7 widgets and omit the part that displays the Item’s state after the badge.

Thanks to Philipp,
who made me aware of the UI components documention:

Can’t believe, that I haven’t noticed that before…

According to it, in contrast to the oh-label-item there is also a oh-list-item without the item state on the right already:

This eases the above task “replace state by badge” even more:

       - component: oh-repeater
            config:
              for: i
              sourceType: itemsWithTags
              itemTags: =props.semTag
              fetchMetadata: semantics,widgetOrder,uiSemantics
              filter: 'vars.detailsOn ? true : loop.i.state != "OFF"'
            slots:
              default:
                - component: oh-list-item
                  config:
                    icon: =props.listIcon
                    iconColor: '=loop.i.state != "OFF" ? "red" : "green"'
                    footer: =loop.i.metadata.uiSemantics.config.preposition + loop.i.metadata.uiSemantics.config.location
                    title: =loop.i.metadata.uiSemantics.config.equipment
                    item: =loop.i.name
                    badge: '=loop.i.state != "OFF" ? "wechseln" : " ok "'
                    badgeColor: '=loop.i.state != "OFF" ? "red" : "green"'

This gives:

Quite happy with that :wink:

3 Likes

I’ll change the OP above to use oh-list. I should have been using it from the start but because I already went through changing all the state descriptions on my items it didn’t occur to me. Good find!

Not realy related to the widget, but how do you monitor this? With the network binding? Do you have a small example?

It depends on the device. If it’s reporting stuff as MQTT I watch the LWT topic and set a Switch Item to OFF when the LWT message is received. For services or machines I use the Network Binding. For devices that might fail silently that can’t be pinged (e.g. battery powered Zwave devices) I use Design Patterns: Generic Is Alive. It’s all really straight forward really. When the device or service is offline, the Switch Item is OFF. When it’s online the Switch Item is ON.

Thanks for your examples, I’m using your “All lights” Widget to show all lights which are “ON”. But the list is long in the evening … so I just thought if it’s possible to limit the repeater that he only shows the last 6 lights which switch to on? Any idea if that is possible? :slight_smile:

Thank you for this example. This widget populates with my tagged items just fine. I can move the toggle to “on” and turn on a light. However, the widget does not indicate the on status with the icon color change. Also, I cannot turn the light off once it is turned on. If I add a widget from the semantic model to toggle on/off a light, that works just fine.

There must be something missing in my config somewhere. Any ideas would be very much appreciated.

All I know is the code I posted works for me. Since I have no view into the code you have. :man_shrugging:

Hi Rich. I was using your code without any modification. I was able to answer my own question, however, just by poking around. “Member Base Type” in the Item definition has to be set to “Switch”. All my lights have this as “none” by default, so that was the problem. Thanks again for your code example.

Hey

Found you a way to order the oh-repeater results?

I’ve never looked. I don’t know if there is a way. I’d guess not.

That’s a shame, but thank you

Hi all,

these oh-repeaters make live much easier. I’m wondering, if there can be also some kind of dependencies to other items can be created.

Example:
1.) I have a list of items, containing temperatures for each room. All items tagged with ‘temperature’
2.) For each of the temperature items, I have a delta item, containing the delta temperature compared to the temperature 24 h ago. Value is either positive or negative.

Would it be possible to use oh-repeater to create a list of temperatures with a red icon color if temperature is going up (compared to 24 h ago) or green icon color if temperature is going down (according to relevant delta item value)? With manual assignment of the items, that is possible, but what about the oh-repeater?

Matthias

There are several different ways to achieve this. The easiest is just to make sure that your naming scheme is consistent. For every temperature item that has some name: temp_item_name then the corresponding delta item could be something like temp_item_name_delta. Then it is very simple to get the state of the delta item in the repeater from the temperature item with an expression like:

items[loop.repeaterVariable.name + "_delta"].state

A more complicated method, if your naming scheme is incompatible with such a usage, might be to use metadata for the temperature item to store the name of the delta item. Then you could utilize the fetchMetadata repeater property to collect that information along with the temperature item.

1 Like

According to @ysc:
When you’re iterating over items, then the widgetOrder metadata is considered:

fetchMetadata: semantics,widgetOrder

… should sort the results accordingly…

1 Like

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?

Thanks
Jeff

Hi all,
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:
                    battery_low_warning.append(u"{} ({})".format(
                                                        battery_group.label,
                                                        item.state))
[...]

In my widget , I just cannot get hold of the numerical value for the item state.

title: =loop.item.label + " " + loop.item.type + " " + loop.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.

filter: Number(items[loop.item.name].state.split(" ")[0]) <= 10
2 Likes

@JustinG - thank you!
Is the filter expression evaluated by JavaScript in the end?
So I can use all the possibilities which are there in JS?