tl;dr
- You can’t mix Contacts and Numbers in the same group and have a meaningful summary state for the group
- The icon for an Item or a Group is based on its state, you must have a separate icon_state.png file for every possible state so having a different Icon for an Item (or Group) that can be a floating point number is impossible
- Rule triggers are based on events, not states
- To achieve what you want you need to have a separate Item (not Group) to represent BATTERY that has two or three different possible states, create an icon for each potential state, and a rule that calculates BATTERY’s state based on the state of your Contacts and Number Items. You can use a Frame with the BATTERY Item to make it behave on the sitemap like the Group, but you will have to list each Item individually on your sitemap instead of using the Group.
First of all, review the sitemap wiki page for how dynamic icons work. In short the icon that gets displayed is based on the state of the Group Item.
I notice that you do not have a Group Item named BATTERY in your list of Items defined. You must define the Group and in your case you need to set the way it rolls up and summarizes the values of all its members (see the Group section on the Items wiki page).
But one problem I see already is you have a mix of Item types that are a member of BATTERY. That likely won’t work as expected because openHAB needs all the members of the Group to be of a consistent type in order to roll it up. For example, you have a mixture of Contact and Number Items, so what sort of Item should the Group behave as, a Contact or a Number? I don’t think it can be both.
Finally, you have two conditions under which you want the state to change and they are somewhat incompatible as stated. You can have one Icon for when the Group’s state is 1 and another for when it is 2.80, (see the Items wiki page for how icons work). The first problem with this is there really isn’t a good way to summarize the Item’s states in such a way that the Group’s state will tell you this information. MAX, MIN, AND, OR, and AVG are your options.
In looking at your rule I see more problems/misconceptions.
The when clause is based on events, not states. This is why it makes no sense to have an AND in a when clause, because no two events will take place at the same time. This is also why it makes no sense to have a < or > in a when clause. The rule can trigger when an Item changes, receives a commands, or even when an Item changes to a certain value but that is it. This when clause is based on state, not events so all this logic needs to move into the rule itself.
Another problem is that when you send a command or post an update to a Group it passes that value on to all of the members of the Group. So if you send a postUpdate(“high”) to BATTERY you will get all sorts of errors because “high” is an invalid state for both Numbers and Contacts. Ans since the Group’s state is based on the states of its members it is not independently commandable or updateable.
Unfortunately you can’t get there from here using a Groups. To get the behavior you are after you will have to abandon the Group on your sitemap entirely and instead duplicate the behavior using a Frame. But this means you will have to list each Item individually on the sitemap.
Instead you can put the Number Items and Contact Items into separate Groups and create a String Item to represent the “high”, “low” state.
#Items
String BATTERY "Current Battery Levels are [%s]" <battery>
Group gBatteryContacts:AND(CLOSED, OPEN) // will be OPEN if one or more Contacts are OPEN
Group gBatteryVolts:MIN // will be the minimum of all the Numbers
Contact itmTuer_Flur_BAT "Batterie Tür Flur [MAP(LOWBAT.map):%s]" <battery > (Flur, gBatteryContacts) {homematic="address=XXX, channel=1, parameter=LOWBAT"}
Contact itmFenster_Schlafzimmer_BAT "Batterie Fenster Schlafzimmer [MAP(LOWBAT.map):%s]" <battery> (Schlafzimmer, gBatteryContacts) {homematic="address=XXX, channel=1, parameter=LOWBAT"}
Contact itmFenster_Badezimmer_BAT "Batterie Fenster Badezimmer [MAP(LOWBAT.map):%s]" <battery> (Badezimmer, gBatteryContacts) {homematic="address=XXX, channel=1, parameter=LOWBAT"}
Contact itmFenster_Kueche_BAT "Batterie Fenster Küche [MAP(LOWBAT.map):%s]" <battery> (Kueche, gBatteryContacts) {homematic="address=XXX, channel=1, parameter=LOWBAT"}
Number itmHeizung_Schlafzimmer_BAT "Batterie Heizung Schlafzimmer [%.2f V]" <battery> (Schlafzimmer, gBatteryVolts) {homematic="address=XXX, channel=4, parameter=BATTERY_STATE"}
Number itmHeizung_Badezimmer_BAT "Batterie Heizung Badezimmer [%.2f V]" <battery> (Badezimmer, gBatteryVolts) {homematic="address=XXX, channel=4, parameter=BATTERY_STATE"}
Number itmHeizung_Kueche_BAT "Batterie Heizung Küche [%.2f V]" <battery> (Kueche, gBatteryVolts) {homematic="address=XXX, channel=4, parameter=BATTERY_STATE"}
#Rule
The rule will trigger on any updates to either Group and calculate the value for BATTERY
import org.openhab.core.library.types.*
rule "Calculate Battery Level"
when
Item gBatteryContacts received update or
Item gBatteryVolts received update
then
// Since gBatteryContacts will be OPEN if any one of the members are 1 we only need check its state
// Similarly gBatteryVolts will be the minimum value of all of its members so we only need check its state
if(gBatteryContacts.state == OPEN || (gBatteryVolts.state as DecimalType) <= 2.0) {
BATTERY.sendCommand("low")
}
else {
BATTERY.sendCommand("high")
}
end
NOTE: I use the long form if statement so you can add logging statements more easily if the logic isn’t quite right
#Sitemap
You can’t use the Groups on your sitemap. Groups on the sitemap only allow you to have default behavior, no customization or special cases are allowed. But you can get the same subframe behavior of a Group.
Test item=BATTERY {
Text item=itmTuer_Flur_BAT
Text item=itmFenster_Schlafzimmer_BAT
...
}
#Icons
Finally, you must have two icons in the webaps/images folder. One named “battery_high.png” and the other “battery_low.png”.