Display the number of filtered groups items in a widget

Hi all,

I am looking for a way to display a summary of devices that are low on battery in a widget. Presently, I’m using a group, and when one or more devices are low on battery that group aggregate goes “ON” and changes the icon and color of the widget:

batterylow_widget

So far so good.

I wanted to provide the number of devices that are low on battery in the widget, and I can’t figure out how to use a filter and/or reduce it as a formula in the subtitle or footer property.

Do I need to use an item to hold the number of “battery low” devices or is there a way to create the formula directly in the widget?

Thanks,
Bjarne

There is a group aggregation function COUNT

Good pointe, I know there is, but as far as I know you can’t use that with a group of Switch items (battery low is ON or OFF). Futhermore in OH3, I can’t assign the COUNT aggregation on anything.

Please check this

Counting switches is exactly the intended use of COUNT. You’d need a Number subtype Group to hold the count in its state, and it might seem alarming to have a Number type Group with Switch type members, but it is quite legitimate.

In the OH3 UI I can’t select the COUNT aggregation function on a group with a members basetype of numbers. In fact, none of the members basetypes allow me to select the COUNT aggregation function.

What am I doing wrong: I created a group with the member basetype of numbers and I see AVG, MAX, MIN and SUM, but no COUNT.

You’re not doing anything wrong, apart from not doing it by text. It’s a UI limitation at the moment.

Ahhhh… Thanks!

Are there other ways of achiving a COUNT like function and or script…

umm, you have to look at the link @hmerk gave you. Click on it.

1 Like

Ahhh… I didn’t see his comments, sorry!

Cool solution. How did you build the formular that displays the number of empties vs. fully-charged?

Thanks!
Bjarne

It is not my solution but it is all in the link. OP is using three groups, one for OFF and one for ON, the third is a sum of both :

This essentially adds two groups where one counts for empty and another count for good batteries.

A third group simply sums up the both which provides me the total number of batteries:

NumOfEmptyBatts + NumOfGoodBatts = TotalNumOfBatts

All BatteryLow-items belong to both count-groups - that’s it

I get the point about the groups and in the UI I can see the correct counts, but how do I get that reflected in a label cell in the Subtitle or Footer properties with the combined count? I see how I can use the state on the group to display the number of empties, but how do I combine the total with the empties in one of the above properties?

You can define the text like

footer: =gLowBat.state + „off“  + gBattetiesTotal.state + „batteries need to be changed“

Funny, I was expecting the formula to be much more complicated… Thanks a lot!

1 Like

Hi Hans, I cant seem to get this to print the members of the group :frowning:

footer: =gMiners.state + „OFF“  + gMiners.state + ' „Some text'“

I’m trying to print the state of the items in the group and their item name…

Thanks!

My fault, coy and paste error, should be

footer: ' =gMiners.state + "OFF"  + gMiners.state + "Some text" '

But why would you print the same state twice ???

That doesnt work either :frowning: Is there any clear documentation on how this is supposed to work?

What do you see and what do you expect to see ?

Dumb me, sorry, my fault again, needs to be

footer: =items.gMiners.state + "OFF"  + items.gMiners.state + "Some text"

You can always check expressions with the developer tools