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):
Items
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” }
Rules
import org.openhab.core.library.types.*
import org.openhab.core.library.items.SwitchItem
var Timer timer
rule “Start-Up”
when
System started
then
postUpdate(Presence, "Determining")
end
rule “Presence Not Detected”
when
Item gDevices changed
then
if (gDevices.state == "OFF") {
if (Presence.state != "Away") {
timer = createTimer(now.plusSeconds(180)) [|
postUpdate(Presence, "Away")
]
}
}
end
rule “Presence Detected”
when
Item gDevices received update ON
then
if (Presence.state != "Home") {
postUpdate(Presence, "Home")
}
end