Helps with location rules and sitemap

Hi,
I want to set check who is at home by triple checking

  1. ping to phone
  2. with region trigger from own tracks
  3. location from iCloud

if any of the three is ON then the person is in the house, if all of the above is OFF then the person is not in the house
and I want that on the sitemap I will able to see who is in the house and send notification one that person arrive or leave the house

I have copy from the community here some items and rules file that seems to me that can help
I need help to modify it to my need and is possible to clarify the logic behind the rule

thanks a lot for your help

items:

Group:Switch:OR(ON, OFF)      Presence          (Persist)
Group                         gPresence         (Persist)
Group:Switch:OR(OFF, ON)      gPresence_Barak   (gPresence)
Group:Switch:OR(OFF, ON)      gPresence_Almog   (gPresence)

Switch Presence_Barak                  "Barak [MAP(presence.map):%s]"   <parents> (Presence)
Switch Presence_Almog                  "Almog [MAP(presence.map):%s]"   <parents> (Presence)

//Pings
Switch Presence_Barak_PhoneWifiHome   (gPresence_Barak) { channel="network:pingdevice:4d7798cd:online" }
Switch Presence_Almog_PhoneWifiHome	  (gPresence_Almog) { channel="network:pingdevice:192_168_0_6:online" }

//iCloud 
Location Presence_Barak_iCloud         (gPresence_Barak){channel="icloud:device:8389ea07:d7b5aab3:location"}

//Owntracks
Switch Presence_Barak_Owntracks       (gPresence_Barak) { channel="gpstracker:tracker:3983d18f:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Home"] } 
Switch Presence_Almog_Owntracks       (gPresence_Almog) { channel="gpstracker:tracker:??:regionTrigger"       [profile="gpstracker:trigger-geofence", regionName="Home"] } 

rules

rule "gPresence Item updated"
when
    Member of gPresence changed
then
    sendNotification("michaelibarak@gmail.com", "Member of gPresence changed")
    val state = triggeringItem.state.toString // to force item update
    val name = triggeringItem.name.split("_").get(1)
    var timerString = "Presence_" + name + "_Timer"
    val SwitchItem presenceItem = Presence.members.filter[ i | i.name.contains(name) ].head as SwitchItem
    if (state == "ON") {
        postUpdate(timerString, "OFF") // cancel the timer if necessary
        if (presenceItem.state != ON) {
            sendCommand(presenceItem.name, "ON")
        }
    }

    // Not at home
    if (state == "OFF" && presenceItem.state != OFF) {
        sendCommand(timerString, "ON") // start the timer
    }
end

rule "Presence Timer expired"
when
    Item Presence_Barak_Timer received command OFF or
    Item Presence_Almog_Timer received command OFF
then
    var String itemName = triggeringItem.name.split("_").get(0) + "_" + triggeringItem.name.split("_").get(1)
    postUpdate(itemName, "OFF")
    //Presence_Barak.postUpdate(OFF)
end

sitemap:

sitemap default label="Home" {
	Frame {
        	Text item=gGF label="Ground Floor" icon="groundfloor"{
			Text item=GF_Living label="Living Room" icon="sofa" {
				Frame label="Reciver"{
					Switch item=VSX923_Zone1Power
					Switch item=VSX923_Zone1SetInputSource mappings=[06="Yes", 15="AppleTV", 22="PlayStation"] visibility=[ VSX923_Zone1Power==ON]
					Slider item=VSX923_Zone1VolumeDimmer visibility=[ VSX923_Zone1Power==ON] 
					Setpoint item=VSX923_Zone1VolumeDb minValue=-80 maxValue=0 step=1 visibility=[ VSX923_Zone1Power==ON]
					Switch item=VSX923_Zone1Mute mappings=[ON="Mute", OFF="Un-Mute"] visibility=[ VSX923_Zone1Power==ON]
					}
				}
       		}
		Text item=gFF label="First Floor" icon="firstfloor"	
		Text item=Garden icon="garden"
	}
	Frame label="Weather" {
		Text item=CurrentCondition
		Text item=Weather_Temperature
		Text item=CurrentHumidity
		Text item=CurrentWindSpeed
		Text item=CurrentRain
		Text item=Sunrise_Time 
		Text item=Sunset_Time
	}
	Frame label="Who Is At Home ?" {   
		?????
	}
}

any help guys?

The question is bit broad. What doesn’t work the way you want?

I’ll guess at this part

Frame label="Who Is At Home ?" {   
		?????
	}

Use visibility=[] to hide Items

Hi thanks,
the issue is that while in putting “Switch Presence_Barak” i cant see anything in the UI
second i want to understand to logic behind the location rule, i cant track it to understand how its working and how the timer is related

Okay, it’s not in the sample sitemap you showed us. If you put it in your sitemap, you should at least see the label?

Your Item definition includes a MAP, perhaps that’s not working. Maybe you didn’t create file presence.map, maybe you have not installed MAP service in PaperUI or Habmin?

Annotated version of your rule

rule "gPresence Item updated"
    // unique rule name
when
    Member of gPresence changed
  // this rule will run whenever a member Item of group gPresence changes
  // note that your gPresence has two members, which are themselves groups
then
    sendNotification("michaelibarak@gmail.com", "Member of gPresence changed")
// *IF* you've set up a cloud myOpenhab
// you'll get a message every time the rule runs

    val state = triggeringItem.state.toString // to force item update
// get the state of the member Item that changed
// we're expecting ON or OFF from the member group 

    val name = triggeringItem.name.split("_").get(1)
// get part of the Item name, from gPresence_Barak we'll get "Barak"

    var timerString = "Presence_" + name + "_Timer"
// use that to make up a new name like "Presence_Barak_Timer"

    val SwitchItem presenceItem = Presence.members.filter[ i | i.name.contains(name) ].head as SwitchItem
// look in a group called Presence
// for any Items with name including "Barak"
// and use the first one you find

// that should give us a switch Item Presence_Barak

    if (state == "ON") {
// that's the state of gPresence_Barak remember

        postUpdate(timerString, "OFF") // cancel the timer if necessary
// we try to send a string to Item Presence_Barak_Timer
// I think that'll fail because you don't have that Item

        if (presenceItem.state != ON) {
// thats the state of Presence_Barak 

            sendCommand(presenceItem.name, "ON")
// if its not ON, make it ON

        }
    }

    // Not at home
    if (state == "OFF" && presenceItem.state != OFF) {
// that's the state of group gPresence_Barak remember
//  and also ordinary item Presence_Barak 

        sendCommand(timerString, "ON") // start the timer
// but you don't have any Item Presence_Barak_Timer

    }
end

I expect you are supposed to have a couple of String Items e.g. Item Presence_Barak_Timer with an expire binding of some minutes. Better have another look at wherever you got the rule from.