Checking Group Status in rules

Hi all,

I’ve been messing around with rules and struggling to work out how I can test for the state of a group (ON or OFF). i.e. if .state == ‘OFF’

What I am trying to create is a presence check using mobile phones and overcome the issue where phones go into a WIFI off state for a few mins every so often, by using a timer. The theory is sound and I have managed to get it work in a trial. I know that if I use the ‘received update OFF’ test it works fine, but I really would like to avoid the timer and the presence update from being triggered multiple times when only one device has activated the ‘ON’ state. I don’t want to test for individual phones here, I just care if one phone in the group is active or not.

The Presence detected rule works fine for what I need, it is just the ‘Not Detected’ rule that does not work as I want. I just get an error.

I don’t want to use GPS tracking either. WiFi states work fine using Network Health.

Can anyone offer any advice ?

I have the following set-up in my items and rules (can provide more details if needed):

Group:Switch:OR(ON, OFF) gDevices

/* Presence */

String Presence “House Occupation [%s]”

/* Mobiles */

Switch Mobile1 “name [%s]” (gDevices) { nh=“ip.address” }

Switch Mobile2 “name [%s]” (gDevices) { nh=“ip.address” }

Switch Mobile3 “name [%s]” (gDevices) { nh=“ip.address” }


import org.openhab.core.library.types.*

import org.openhab.core.library.items.SwitchItem

var Timer timer

rule “Start-Up”


    System started


    postUpdate(Presence, "Determining")


rule “Presence Not Detected”


    Item gDevices changed


    if (gDevices.state == "OFF") {

            if (Presence.state != "Away") {

                    timer = createTimer(now.plusSeconds(180)) [|

                            postUpdate(Presence, "Away")





rule “Presence Detected”


    Item gDevices received update ON


    if (Presence.state != "Home") {

            postUpdate(Presence, "Home")



Remove the quotes around the OFF. Otherwise you compare a OnOffType against a String and this can never be equal.
So instead of

if (gDevices.state == "OFF") {


if (gDevices.state == OFF) {

As long as just Switches are assigned to your group you should be fine.

That works a treat, thank you