Fighting with rules

Hi there

Im fighting with multiple Rules. I hope i can use only 1 Rule.

Im activating the Motion Sensor as an alarm sensor when every mobile disconnected from the WLAN.

Same for the Lichts. They will automaticly turn all off, when noone is in the WLAN, the system turn off all lights.

Now there is the problem. I got 4 Mobiles and i have to create 4 rules, because the first “when” is checking if a mobile is present.

Now i have to put everytime a new mobile after the “when” because otherwise it wont trigger when another mobile leaves the house as last.

rule "Licht Aus1"

when
Item RetoMobile changed from CLOSED to OPEN        
            
then
if ((PapiMobile.state==OPEN) && (MamiMobile.state==OPEN) && (ChantalMobile.state==OPEN)) 
{
//sendNotification("xyz@xyz.com","Licht Aus")
//sendMail("xyz@xyz.comt", "Bewegung Erkannt", "ALARM")
Reto_Office_Licht.sendCommand(OFF)
Reto_Flur_Licht.sendCommand(OFF)
Treppe_Licht.sendCommand(OFF)
Wohnzimmer_Licht.sendCommand(OFF)
Esszimmer_Licht.sendCommand(OFF)
Papi_Office_Licht.sendCommand(OFF)
}

end

Here you see. In the Second rule, after when “PapiMobile” will go first and switched with RetoMobile.

The same Problem im Facing with the “alarm” rule.

rule "ALARM"

when Item HueTrigger changed from OFF to ON            
            
then
if ((RetoMobile.state==OPEN) && (HueTrigger.state == ON) && (PapiMobile.state==OPEN) && (MamiMobile.state==OPEN) && (ChantalMobile.state==OPEN)) 
{
sendNotification("xyz@xyz.com","ALARM")
//sendMail("xyz@xyz.com", "Bewegung Erkannt", "ALARM")
Reto_Office_Alarm.sendCommand("LSELECT")
Treppe_Alarm.sendCommand("LSELECT")
Reto_Flur_Alarm.sendCommand("LSELECT")
Wohnzimmer_Alarm.sendCommand("LSELECT")
Esszimmer_Alarm.sendCommand("LSELECT")
Papi_Office_Alarm.sendCommand("LSELECT")
}

end

Does anyone got a solution for this?

Have your mobile items as switches
Put them in a group called gPresence

Group:Switch:OR(ON, OFF) gPresence

Now all you need to monitor is the state of gPresence
If one of the mobiles is ON, gPresence = ON
If all the mobile are OFF, gPresence is OFF

Does that help?

Hi Vincent

Many thanks!

Can you make an example with the Items and how to put them into a Group?

Does it Matter, that my Mobile are having the states “Closed and Open” and not On and Off?

Something like this?

Switch  RetoMobileS     "Reto Presence"     (gmpresence)        { channel="unifi:client:home:retomobile1:online" }
Switch  PapiMobileS      "Papi Presence" (gmpresence)            { channel="unifi:client:home:papimobile:online" }
Switch  MamiMobileS      "Mami Presence" (gmpresence)             { channel="unifi:client:home:mamimobile:online" }
Switch  ChantalMobileS   "Chantal Presence" (gmpresence)            { channel="unifi:client:home:chantalmobile:online" }

Group:Switch:OR(Closed, Open) gmpresence

Group:Switch:OR(ON, OFF) gmpresence

If your mobile items as switches then will have two states ON or OFF
The rest is fine

I just tested it. And did the Switch as “default” on the sitemap.
Sadly the Switch does not turn “on” automaticly when the device comes online with the state “Closed”.

The Switch stays Off. So this solution will not work. Any Idea how i can tell the Switch, that On == CLOSED and not ON == ON?

Think they wont understand each other.

On your log what happens to the mobile item when it goes online/offline?
Or create a sitemap switch for one mobile, what happens to the switch when the mobile goes online/offline?

2018-04-02 23:21:35.133 [vent.ItemStateChangedEvent] - RetoMobile changed from CLOSED to OPEN

they just work with Open and closed.

I already created a sitemap switch for Mobile. Nothing happens

Ok not a problem

Group:Switch:OR(CLOSED, OPEN) gmpresence

And change your mobile items back to Contact

OK perfect. How do i Monitor a State of a Group?

Now i have to change the “Item=xymobile” whats now the proper Syntax for checking gmpresence?

oh and how can i show the State in a sitemap to check?

Only one rule needed now!

rule "Licht Aus"

when
    Item gmpresence changed from ON to OFF
then
    //sendNotification("xyz@xyz.com","Licht Aus")
    //sendMail("xyz@xyz.comt", "Bewegung Erkannt", "ALARM")
    Reto_Office_Licht.sendCommand(OFF)
    Reto_Flur_Licht.sendCommand(OFF)
    Treppe_Licht.sendCommand(OFF)
    Wohnzimmer_Licht.sendCommand(OFF)
    Esszimmer_Licht.sendCommand(OFF)
    Papi_Office_Licht.sendCommand(OFF)
end
rule "ALARM"

when Item HueTrigger changed from OFF to ON            

then
    if (gmpresence == OFF) {
        sendNotification("xyz@xyz.com","ALARM")
        //sendMail("xyz@xyz.com", "Bewegung Erkannt", "ALARM")
        Reto_Office_Alarm.sendCommand("LSELECT")
        Treppe_Alarm.sendCommand("LSELECT")
        Reto_Flur_Alarm.sendCommand("LSELECT")
        Wohnzimmer_Alarm.sendCommand("LSELECT")
        Esszimmer_Alarm.sendCommand("LSELECT")
        Papi_Office_Alarm.sendCommand("LSELECT")
    }
end

Thank you Very much!

Now i check the Stats with Off and On? right? Not Closed and Open?

The Group is a switch therefore ON and OFF

Ok thank you!

One last. Whats the proper Syntax to check the Group Status on a Sitemap?
Text item=gmpresence
is not working.

Sadly the Rules aren’t working aswell anymore :\

item:

Group:Switch:OR(CLOSED, OPEN) gmpresence "Presence [%s]"

sitemap:

Text item=gmpresence

So the gmpresence status is “-” at the moment.

1 Mobile Online

Ill turn it of and check if something is changing.

Im not sure if this is something you need to know. But i got a MAP binding for the Clients:

OPEN=Away
CLOSED=Home
NULL=Unknown
UNDEF=Fehler
-=Fehler

Thats how my Items look like:

Contact  RetoMobile  "Reto's Mobile: [MAP(unifi.map):%s]"  (gmpresence)           { channel="unifi:client:home:retomobile1:online" }
Contact  PapiMobile    "Papi's Mobile: [MAP(unifi.map):%s]"   (gmpresence)            { channel="unifi:client:home:papimobile:online" }
Contact  MamiMobile     "Mami's Mobile: [MAP(unifi.map):%s]"   (gmpresence)           { channel="unifi:client:home:mamimobile:online" }
Contact  ChantalMobile  "Chantal's Mobile: [MAP(unifi.map):%s]" (gmpresence)             { channel="unifi:client:home:chantalmobile:online" }

Check the state of all 4 mobile
They MUST be either CLOSED or OPEN
if ONE of them if neither then your group will be undefined

The Status is one of these. On the Sitemap ill see:
(Due to Mapping Transformation)

Reto’s Mobile:
Home

Papi’s Mobile:
Away

Mami’s Mobile:
Away

Chantal’s Mobile:
Away

edit
Now my Phone is disconnected. The Group is still on “-”.

My apologies,
The group needs to be a Contact too!! Sorry

Group:Contact:OR(CLOSED, OPEN) gmpresence "Presence [%s]"

Rules:

rule "Licht Aus"

when
    Item gmpresence changed from OPEN to CLOSED
then
    //sendNotification("xyz@xyz.com","Licht Aus")
    //sendMail("xyz@xyz.comt", "Bewegung Erkannt", "ALARM")
    Reto_Office_Licht.sendCommand(OFF)
    Reto_Flur_Licht.sendCommand(OFF)
    Treppe_Licht.sendCommand(OFF)
    Wohnzimmer_Licht.sendCommand(OFF)
    Esszimmer_Licht.sendCommand(OFF)
    Papi_Office_Licht.sendCommand(OFF)
end

And

rule "ALARM"

when Item HueTrigger changed from OFF to ON            

then
    if (gmpresence == CLOSED) {
        sendNotification("xyz@xyz.com","ALARM")
        //sendMail("xyz@xyz.com", "Bewegung Erkannt", "ALARM")
        Reto_Office_Alarm.sendCommand("LSELECT")
        Treppe_Alarm.sendCommand("LSELECT")
        Reto_Flur_Alarm.sendCommand("LSELECT")
        Wohnzimmer_Alarm.sendCommand("LSELECT")
        Esszimmer_Alarm.sendCommand("LSELECT")
        Papi_Office_Alarm.sendCommand("LSELECT")
    }
end

Once you an Vincent get this Group working look at Generic Presence Detection.