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:
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?
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.
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.
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?