Some Item Groups not correctly populated

  • Platform information:
    • Hardware:
      Raspberry Pi 3B, 64 GB micro SD
    • OS:
      Raspbian GNU/Linux 9 (stretch)
      Linux rpi3 4.14.70-v7+ #1144 SMP Tue Sep 18 17:34:46 BST 2018 armv7l
    • Java Runtime Environment:
      zulu-embedded-8/azulsystems,now 8.25.0.76 armhf [installed]
    • openHAB version:
      openHAB 2.4.0~20181012154014-1 (Build #1389)
  • Issue of the topic:

I have DSL rules in which I use item groups to monitor and control groups of lights comprising switch and dimmer items. I have determined that some item groups are not fully populated.

As an example of a group item that is not properly populated, I have the following item definitions:

//  Groups
Group                   gOFLts          "Office Lights"                 <office>
Group:Switch:OR(ON,OFF) gOFLtsOn        "Office Lights [%s]"            <office>

// Office
Dimmer  OfficeFanLts            "Office Fan Lights"             (gOF,gOFLts,gOFLtsOn,gUpstairsLts,gLTs,G_PresenceSimulation)            ["Lighting"]
Dimmer  OfcTblLamp              "Office Table Lamp"             (gOF,gOFLts,gOFLtsOn,gUpstairsLts,gSSLts,gLTs,G_PresenceSimulation)     ["Lighting"]
Dimmer  TstLamp1                "Test Lamp 1"                   (gOF,gOFLts,gOFLtsOn,gUpstairsLts,gSSLts,gLTs,G_PresenceSimulation)     ["Lighting"]

If I inspect the group membership of each of my items using the REST API, it shows only two members of group gOFLts:

  {
    "link": "http://rpi3.karnsfamily.org/rest/items/OfcTblLamp",
    "state": "0",
    "editable": false,
    "type": "Dimmer",
    "name": "OfcTblLamp",
    "label": "Office Table Lamp",
    "tags": [
      "Lighting"
    ],
    "groupNames": [
      "gOF",
      "gOFLts",
      "gOFLtsOn",
      "gUpstairsLts",
      "gSSLts",
      "gLTs",
      "G_PresenceSimulation"
    ]
  },

  {
    "link": "http://rpi3.karnsfamily.org/rest/items/TstLamp1",
    "state": "0",
    "editable": false,
    "type": "Dimmer",
    "name": "TstLamp1",
    "label": "Test Lamp 1",
    "tags": [
      "Lighting"
    ],
    "groupNames": [
      "gOF",
      "gOFLts",
      "gOFLtsOn",
      "gUpstairsLts",
      "gSSLts",
      "gLTs",
      "G_PresenceSimulation"
    ]
  },

I don’t think my rules are a factor in this bug, but, for completeness of this problem report, my rules that act on gOFLts events are:

//------------------
// Global Variables
//------------------
val SEAR = "sun-elevation-azimuth.rules"

//------------------
// Rules
//------------------
rule "Manage Office *All Off* LED"
when
    Item gOFLtsOn changed
then
    val logID = SEAR + ".ofc-all-off-led"
    val OnOffType newState = gOFLtsOn.state
    logInfo(logID, "gOFLtsOn changed to {}", newState.toString())

    try {
        if (newState == ON) {           // at least one Office light is ON
            OF_KpLED_5.sendCommand(ON)
        } else {                        // no Office lights are ON
            OF_KpLED_5.sendCommand(OFF)
        }
    } catch (Throwable t) {
        logError(logID, "'Manage Office *All Off* LED' rule: {}", t.toString())
    }
end


rule "Handle Office Scene Button Press"
when
    Item Desk_Pico_1 changed to ON
then
    val logID = SEAR + ".ofc-scene-btn"
    logInfo(logID, "Desk_Pico_1 button pressed")

    try {
        gOFLts.getAllMembers.forEach[ light |
            logInfo(logID, "processing gOFLts member: {}", light.getName)

            var osOnCmd = if (officeSceneSettings.containsKey(light.getName)) officeSceneSettings.get(light.getName) else DEFAULT_OS_ON_LEVEL

            if (light instanceof SwitchItem) {
                // light is either a SwitchItem or a DimmerItem as
                // DimmerItem inherits from SwitchItem
                if (light.getStateAs(OnOffType) == OFF) {
                    if (! (light instanceof DimmerItem)) {
                        osOnCmd = "ON"
                    }
                    logInfo(logID, "sendCommand({}, {})", light.getName, osOnCmd)
                    doSendCmd.apply(logID, light.getName, osOnCmd)
                } else {
                    logInfo(logID, "light: {} is already ON", light.getName)
                }
            } else {
                logError(logID, "item: {} is neither a Switch nor a Dimmer", light.getName)
            }
        ]
    } catch (Throwable t) {
        logError(logID, "'Handle Office Scene Button Press' rule: {}", t.toString())
    }
end


rule "Handle Office Lamp Button Press"
when
       Item Desk_Pico_2 changed to ON
    or Item Desk_Pico_3 changed to ON
then
    val logID = SEAR + ".ofc-lamp-btn"
    logInfo(logID, "Desk_Pico button 2 or 3 pressed")

    val light = if (triggeringItem.name == "Desk_Pico_2" ) TstLamp1 else OfcTblLamp
    val lightName = light.getName
    var dp2Cmd = if (officeSceneSettings.containsKey(lightName)) officeSceneSettings.get(lightName) else DEFAULT_OS_ON_LEVEL

    try {
        if (light.getStateAs(OnOffType) == ON) {
            dp2Cmd = "OFF"
        }
        logInfo(logID, "sendCommand({}, {})", lightName, dp2Cmd)
        doSendCmd.apply(logID, lightName, dp2Cmd)
    } catch (Throwable t) {
        logError(logID, "'Handle Office Test Lamp Button Press' rule: {}", t.toString())
    }
end


rule "Handle Office *All Off* Button Press"
when
       Item OF_Keypad_5 changed to ON
    or Item Desk_Pico_4 changed to ON
then
    val logID = SEAR + ".ofc-all-off-btn"
    val OnOffType ofcLtsState = gOFLtsOn.state
    logInfo(logID, "OF_Keypad_5 button pressed, gOFLtsOn: {}", ofcLtsState.toString)

    try {
        if (ofcLtsState == ON)   {      // at least one Office light is ON
            gOFLts.sendCommand(OFF)
        }
    } catch (Throwable t) {
        logError(logID, "'Handle Office *All Off* Button Press' rule: {}", t.toString())
    }
end

It is worth noting that when openhab2 starts, it goes through several “false” starts with various rules error reports that I attribute to a lack of any startup ordering, i.e., global variables (vals) that are declared and initialized in my rules are detected as having NULL values when the rules (prematurely) begin running.

Is this a known issue that is being debugged, or should I file an issue report?

[Update:]

I restarted OH2 for the third time since updating to release #1389 and the gOFLts group item is now correctly populated.

      {
        "link": "http://rpi3.karnsfamily.org/rest/items/OfficeFanLts",
        "state": "96",
        "editable": false,
        "type": "Dimmer",
        "name": "OfficeFanLts",
        "label": "Office Fan Lights",
        "tags": [
          "Lighting"
        ],
        "groupNames": [
          "gOF",
          "gOFLts",
          "gOFLtsOn",
          "gUpstairsLts",
          "gLTs",
          "G_PresenceSimulation"
        ]
      },
      {
        "link": "http://rpi3.karnsfamily.org/rest/items/OfcTblLamp",
        "state": "33",
        "editable": false,
        "type": "Dimmer",
        "name": "OfcTblLamp",
        "label": "Office Table Lamp",
        "tags": [
          "Lighting"
        ],
        "groupNames": [
          "gOF",
          "gOFLts",
          "gOFLtsOn",
          "gUpstairsLts",
          "gSSLts",
          "gLTs",
          "G_PresenceSimulation"
        ]
      },
      {
        "link": "http://rpi3.karnsfamily.org/rest/items/TstLamp1",
        "state": "33",
        "editable": false,
        "type": "Dimmer",
        "name": "TstLamp1",
        "label": "Test Lamp 1",
        "tags": [
          "Lighting"
        ],
        "groupNames": [
          "gOF",
          "gOFLts",
          "gOFLtsOn",
          "gUpstairsLts",
          "gSSLts",
          "gLTs",
          "G_PresenceSimulation"
        ]
      },

That’s good news as this has been a known issue with OH 2.3.:smiley: Hopefully the next update wont require three restarts.:crossed_fingers:

1 Like