Group/(Sub)Group/items in persistence and rules

i’d like to reorganize my groups/items like this:

Group gLights
Group gLights1 (gLights)
Group gLights2 (gLights)

Switch Light1 (gLights1) 
Switch Light2 (gLights1) 
Switch Light3 (gLights2)
Switch Light4 (gLights2)

Group gSensors
Group gTemp (gSensors)
Group gHumid (gSensors)

Number Temp1 (gTemp)
Number Temp2 (gTemp)
Number Humid1 (gHumid)
Number Humid2 (gHumid)

would i be able to switch all 4 lights like this?

gLights.members.forEach(i | i.sendCommand(OFF))

and would openhab persist all 4 items with

   gSensors*               :   strategy = everyMinute


Or is this not how groups should be used? :slight_smile:

If you must. Or just -

The principle is simple. Sending a command to a Group just distributes it to all member Items.
If a member Item happens to be a Group … sending a command to that Group just distributes it to all member Items.


These are not difficult things to try out, just remembering that persistence is essentially version 1.x and usually requires a restart to pick up config changes.

1 Like

huh… okay thank you, that’s what i hoped!
on there other side this means something is wrong with my persistence settings :neutral_face:
(because i really was trying it out before, but didn’t work as intended).

again: thank you!

Actually, because the lights are in a subgroup, you would need to use

gLights.getAllMembers.forEach[ i | i.sendCommand(OFF) ]

I believe that members only returns non-group Items that are direct members to gLights. Or even if does return the Group Items, it will then just return the gLights1 and gLight2 Groups and not the actual Light switches.

But when you send a command, as rossko57 indicated, the command gets forwarded from the Group to the sub-Groups and finally to the Items.

So in fact, your original would work, but the for loop wouldn’t be commanding the Items directly, its commanding the gLights1 and gLights2 Groups which forwards them to the Items.

It’s a good idea to give your Groups a Type. This will help make sure the commands are received and interpreted correctly.

Group:Switch gLights

If you add an aggregation function, you can then put the Group on your sitemap and see if any light happens to be ON.

Group:Switch:OR(ON,OFF) gLights

Sadly no. The problem is you have nested Groups. gSensors will only save to persistence direct non-Group Items that are members of gSensors. With the Items above, there are no non-Group type Items that are a direct member of gSensors. You need to add each subgroup individually.

gTemp*,gHumid* : strategy = everyMinute

This is one reason why I wrote Design Pattern: Group Based Persistence and frankly why I think developing some big hierarchy of Groups is kind of a waste of time. It’s useful when you want to aggregate a bunch of sensors into one value or command a bunch of stuff of the same type with one command (as above), or if you have a bunch of Items that need to have their events processed by the same Rule (Member of Rule). It’s less useful for sitemaps and completely useless for persistence. Instead of a hierarchy, I find it much more useful to think about Groups more like a tag. Instead of a tree, it’s more useful to think of a Venn Diagram.

1 Like

Nested Group membership does work with persistence (I think this was fixed within living memory, maybe OH2.1 or 2.2)

demo Items

Group gTop
Group gMiddle (gTop)
Group gBottom (gMiddle)
Number test1 "test one" (gTop)
Number test2 "test two" (gMiddle)
Number test3 "test three" (gBottom)
Number test4 "test four" (gBottom)

rrd4j.persist entry

    gTop* : strategy = everyMinute

REST API persistence query results

  "name": "test1",
  "datapoints": "2",
  "data": [
      "time": 1594669200000,
      "state": "1.0"
    },   // etc

  "name": "test2",
  "datapoints": "3",
  "data": [
      "time": 1594669200000,
      "state": "2.0"
    },   // etc

  "name": "test3",
  "datapoints": "3",
  "data": [
      "time": 1594669200000,
      "state": "3.0"
    },   // etc

It didn’t used to. That’s good to know that it works as expected now.

just be sure to name persistence file “rrd4j.persist” and not to put a space before the dot > “rrd4j .persist”
took me long enough to find that litte ***

thank you, bot of you!