[SOLVED] Nesting groups and group functions

I’m to create a rule that turns on a wall switch when the humidity reaches a threshold and the window is open. I was trying to use the AND function in Groups for it. Eventually I want to also add the condition that the door must be open as well when I leave the bathroom.

To start, I created a group with the humidity sensor as the only member. I have a rule that toggles the state of the group based on humidity.

rule "is the bathroom humid"
when
 Item bathroomWeatherHumidity changed
then
     if(bathroomWeatherHumidity.state >=71) {
     Thread::sleep(100)
     bthrmhumid.sendCommand(ON)
     logInfo("bthrm_humid", "bthrm_humid sent command ON")
      }
 else {
       Thread::sleep(100)
       bthrmhumid.sendCommand(OFF)
       logInfo("bthrm_humid", "bthrm_humid sent command OFF")
       }
end

I created a similar rule for opening the window.

rule "bathroom window status"
when
 Item bathroomWindowStatus changed
then
 if(bathroomWindowStatus.state == OPEN) {
    Thread::sleep(100)
    gBathroomWindow.sendCommand(ON)
     }
  else {
    Thread::sleep(100)
    gBathroomWindow.sendCommand(OFF)
      }
end

The Thread::sleep are there because I thought it might be that the series of changes is causing the problem. I then created 3 groups to use an AND function.

Group:Switch:OR(OFF,ON) bthrmhumid (gBathroomcooldown)

Group:Switch:AND(OFF, ON) gBathroomcooldown

Group:Switch:OR(OFF,ON) gBathroomWindow (gBathroomcooldown)

Items:

Number bathroomWeatherHumidity "humidity [ %.1f ]" <humidity> (humidity, gBathroom, bthrmhumid) {channel="mihome:sensor_weather_v1:158d00023cf40a:humidity" }
Contact bathroomWindowStatus "Open Status" <door> (door, gBathroom, gBathroomWindow) { channel="mihome:sensor_magnet:158d000276dc88:isOpen" }

Both of the groups, bhtrmhumidity and gBathroomWindow are both changing correctly. My problem is with gBathroomcooldown. When the value starts as null, I can change gBathroomcooldown with the humidity or window. But then subsequent changes in bthrmhumidity and gBathroomWindow aren’t changing gBathroomcooldown. Is there something I am overlooking in the way I’m using AND in the group function?

It’s not clear what you expect to happen when you command ON to gBathroomWindow. It’s a group, and will pass along such commands to members without directly affecting it’s own state.
The member bathroomWindowStatus is a Contact type, so it won’t know what to do with ON and will ignore it.

Thanks. That helps a lot in understanding what’s going on. I was trying to use the Groups to convert the status OPEN into ON so both the humidity and window are formatted the same. Is this even possible or am I trying to misunderstanding how to use groups altogether?

Just change bthrmhumid and gBathroomWindow to regular Switch items and I believe it should work as intended. Or is there other items that are members of these groups as well?

In this case it’d be simpler to make dummy Items that are controlled by rules similar to those you posted already.

I don’t think you can rely very well on the group’s aggregation function (that calculates its apparent state) when the group type and member type are not similar.

I changed both to regular switches and now either bthrmhumid OR bathroomWindowStatus toggles the group between ON / OFF. I also found that in my troubleshooting, I had duplicate items that all were part of the gBathroomcooldown group. Deleting those duplicates fixed some of my issues. I’m making progress but now the issue is that either item will change the state of gBathroomcooldown. I’m trying to make it so that when both bthrmhumid AND bathroomWindowStatus are ON, gBathroomcooldown then turns on. It seems like my AND statement is being treated as an OR statement.

Rules ---------------------------------------------------------

rule "bathroom window status"
when
     Item bathroomWindowStatus changed
then
     logInfo("bathroomWindowStatus", "bathroom window status changed")
     if(bathroomWindowStatus.state == OPEN) {
        Thread::sleep(100)
        BathroomWindow.sendCommand(ON)
     logInfo("bathroomWindowStatus", "bathroom window is {}", bathroomWindowStatus.state)
         }
      else {
        Thread::sleep(100)
        BathroomWindow.sendCommand(OFF)
     logInfo("bathroomWindowStatus", "bathroom window is {}", bathroomWindowStatus.state)
          }
end

rule "cool down bathroom (maintenance rules)"
when Item gBathroomcooldown changed //or
//     Time cron "0/15 * * ? * * *"
then
         logInfo("gBathroomcooldown", " gBathroomcooldown is {}, bthrmhumid is {}, BathroomWindow is {}", gBathroomcooldown.state, bthrmhumid.state, BathroomWindow.state )
     if(gBathroomcooldown.state == ON) {
         logInfo("gBathroomcooldown", " gBathroomcooldown is on" )
        Bathroom_Fan.sendCommand(ON)
         }
     else {
         logInfo("gBathroomcooldown", "gBathroomcooldown is not on" )
         Bathroom_Fan.sendCommand(OFF)
          }
end

rule "is the bathroom humid"
when
     Item bathroomWeatherHumidity changed or
     Time cron "0/17 * * ? * * *"
then
     if(bathroomWeatherHumidity.state >=80) {
       Thread::sleep(100)
       bthrmhumid.sendCommand(ON)
       logInfo("bthrm_humid", "bthrm_humid sent command ON")
       }
     else {
           Thread::sleep(100)
           bthrmhumid.sendCommand(OFF)
           logInfo("bthrm_humid", "bthrm_humid sent command OFF")
           }
end

Items ------------------------------------------------------

Group:Switch:AND(OFF,ON) gBathroomcooldown
Switch bthrmhumid (gBathroomcooldown, humidity)
Switch BathroomWindow (gContact, gBathroomcooldown)
Switch   bathroomWindow        "Open ON/OFF"             (gBathroom, gContact)

I know it’s bad form to have two separate items called bathroomwindow distinguished by capitalization but I plan to change that later when I finish troubleshooting.

Change to:

Group:Switch:AND(ON,OFF) gBathroomcooldown

I.e switch places for ON and OFF. The first one is what gets AND- checked for, and the second one is used when the comparison is false.

2 Likes

That was it. Switching ON <-> OFF got it working. Thank you @pacive.