Help with rule logic

Hi,
I need help to do something.
I’m trying to monitor the presence of my kid.
He has 2 devices, sometimes leaves the house with only one, sometimes with two. So what I want is - if either one device is missing from wifi, set the group(or proxy item) to OFF. But only if both devices are ON set the group to ON.
Is that even possible? Maybe I dont need a rule, can some groups behave like that by definition?

I found a nice rule for replacement of follow profile, maybe something similar…

rule "Kitchen Strip Button Update"
when
    Member of gKitchenStrip changed
then
    if(bLock)
        return;
    bLock = true
    gKitchenStrip.members.filter[j|j.name != triggeringItem.name].forEach[i|i.sendCommand(triggeringItem.state.toString)]
    Thread::sleep(800)
    bLock = false
end

Sounds like you need a Group with AND function.

You can achieve this quite easily with a Group using the AND function. In the UI, you can select this aggregation method visually, which makes it very intuitive.

In an .items file, it would look something like this:

Group:Switch:AND(ON, OFF) group_kid_presence "Kid Presence"

Switch kid_device1_online "Device 1" (group_kid_presence) { channel="" }
Switch kid_device2_online "Device 2" (group_kid_presence) { channel="" }

With this setup, the group will only turn ON when both devices are ON. If either device goes offline, the group automatically turns OFF.

For a detailed overview of aggregation functions, you can check the documentation.

1 Like

perfect, thank you both! Now I’m embarrassed that I asked for some simple built in function, I guess it sounded more complicated in my head :slight_smile: First it took me a while to mentally design the system that would even work for this particular situation, and turns out poof, openhab has me covered.
Fantastic piece of software :slight_smile: