Group:Number:COUNT("ON") group_house_switch_light "[%d] of 4 lights on"
to get the number of items that is currently on. Note that you have to hard-code the total number of items, so if you add another light to the group you have to change that manually.
Not sure if I got it completely correct, but see here for more info.
In fact, the dynamic part of the label is not that flexible.
Group:Switch:OR(ON,OFF) group_house_switch_light "Number of Lights on [%d]"
would suffice to get the correct answer, but the total number of members can’t be displayed this way.
You could build a rule like this:
rule "count members"
when
Member of gGroup changed
then
var Integer ctOff = gGroup.members.filter[m|m.state == OFF].size
var Integer ctOn = gGroup.members.filter[m|m.state == ON].size // maybe var Int instead of var Integer?
var Integer ctSum = gGroup.members.size
var lOn = ctOn.toString + " out of " + ctSum.toString + " are switched ON"
var lOff = ctOff.toString + " out of " + ctSum.toString + " are switched OFF"
end
Afaik there are commands to change the label through a rule, but I never used them, so I don’t know if this will work as ecpected. Of course you could use a String Item to store the label and to display it.
rule "count members"
when
member of group_house_switch_light changed
then
var Integer ctOff = group_house_switch_light.members.filter[m|m.state == OFF].size
var Integer ctOn = group_house_switch_light.members.filter[m|m.state == ON].size // maybe var Int instead of var Integer?
var Integer ctSum = group_house_switch_light.members.filter[m|true].size
var lOn = ctOn.toString + " out of " + ctSum.toString + " are switched ON"
var lOff = ctOff.toString + " out of " + ctSum.toString + " are switched OFF"
end
Udo: do you remember if 2.3.0 Stable has this included?
the post that I linked is from Feb/18 and OH2.3.0 Stable was released on May/18 so it should include this
2018-11-30 08:14:36.990 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'default.rul$
The value of the local variable lOn is not used
The value of the local variable lOff is not used
because it is not set to the group how do I do this???
it only displays me a number not the whole text right now
You will need to display that text that is built in the two variables.
This is not an error. Just info from the rule parsing engine that the variables are not used.
Create 2 new items:
String NumberOfLightsON
String NumberOfLightsOFF
Change your rule:
rule "count members"
when
Member of group_house_switch_light changed
then
var Integer ctOff = group_house_switch_light.members.filter[m|m.state == OFF].size
var Integer ctOn = group_house_switch_light.members.filter[m|m.state == ON].size // maybe var Int instead of var Integer?
var Integer ctSum = group_house_switch_light.members.filter[m|true].size
var lOn = ctOn.toString + " out of " + ctSum.toString + " are switched ON"
var lOff = ctOff.toString + " out of " + ctSum.toString + " are switched OFF"
NumberOfLightsON.postUpdate(lOn)
NumberOfLightsOFF.postUpdate(lOff)
end
Sitemap:
Text item=NumberOfLightsON
Text item=NumberOfLightsOFF
Which label?
Add some logInfo in the rule to see if it runs at all:
rule "count members"
when
Member of group_house_switch_light changed
then
var Integer ctOff = group_house_switch_light.members.filter[m|m.state == OFF].size
var Integer ctOn = group_house_switch_light.members.filter[m|m.state == ON].size // maybe var Int instead of var Integer?
var Integer ctSum = group_house_switch_light.members.filter[m|true].size
var lOn = ctOn.toString + " out of " + ctSum.toString + " are switched ON"
var lOff = ctOff.toString + " out of " + ctSum.toString + " are switched OFF"
logInfo("lOn", lOn)
logInfo("lOff", lOff)
NumberOfLightsON.postUpdate(lOn)
NumberOfLightsOFF.postUpdate(lOff)
end