Hi all, I have icloud installed, with 3 phones in my house, here is the items:
Group:Switch:OR(ON,OFF) iCloud_Group <iphone>
//iPhone6 Plus
String IPhone6P_BatteryStatus "6P [%s %%]" <battery> (iCloud_Group) {channel="icloud:device:id1:b2b472ce:batteryStatus"}
Number IPhone6P_BatteryLevel "6P [%.0f]" <battery> (iCloud_Group) {channel="icloud:device:id1:b2b472ce:batteryLevel"}
DateTime IPhone6P_LocationLastUpdate "6P [%1$tH:%1$tM]" <iphone> (iCloud_Group) {channel="icloud:device:id1:b2b472ce:locationLastUpdate"}
Location IPhone6P_Location "6P [%s]" <iphone> (iCloud_Group) {channel="icloud:device:id1:b2b472ce:location"}
Switch IPhone6P_Refresh "6P" <iphone> (iCloud_Group) {channel="icloud:device:id1:b2b472ce:location", autoupdate="false"}
Switch IPhone6P_Home "6P" <iphone> (iCloud_Group)
//iPhone 6S
String IPhone6S_BatteryStatus "6S [%s %%]" <battery> (iCloud_Group) {channel="icloud:device:id1:67f17221:batteryStatus"}
Number IPhone6S_BatteryLevel "6S [%.0f]" <battery> (iCloud_Group) {channel="icloud:device:id1:67f17221:batteryLevel"}
DateTime IPhone6S_LocationLastUpdate "6S [%1$tH:%1$tM]" <iphone> (iCloud_Group) {channel="icloud:device:id1:67f17221:locationLastUpdate"}
Location IPhone6S_Location "6S [%s]" <iphone> (iCloud_Group) {channel="icloud:device:id1:67f17221:location"}
Switch IPhone6S_Refresh "6S" <iphone> (iCloud_Group) {channel="icloud:device:id1:67f17221:location", autoupdate="false"}
Switch IPhone6S_Home "6S" <iphone> (iCloud_Group)
and the rules to define the distance from home:
rule "allPhone_Rules"
when
Item IPhone6P_Location changed or
Item IPhone6S_Location changed
then
// specify your home location
val PointType home_location = new PointType(new DecimalType(xx.05135920063), new DecimalType(xx.6613793811))
val PointType phone1_location = IPhone6P_Location.state as PointType
val PointType phone2_location = IPhone6S_Location.state as PointType
val int distance1 = phone1_location.distanceFrom(home_location).intValue()
val int distance2 = phone2_location.distanceFrom(home_location).intValue()
// specify your preferred radius (in meters)
if ( distance1 < 200 || distance2 < 200) {
iCloud_Group.postUpdate(ON)
logInfo("allPhone", "home!")
}
else if ( distance1 >= 200 && distance2 < 200) {
iCloud_Group.postUpdate(ON)
logInfo("allPhone", "home!")
}
else if ( distance2 >= 200 && distance1 < 200) {
iCloud_Group.postUpdate(ON)
logInfo("allPhone", "home!")
}
else {
iCloud_Group.postUpdate(OFF)
logInfo("allPhone", "away!")
}
end
The rule looks… very stupid , althrough it kind of work… I only test with 2 phones, and I need to add 3 more phones and 2 watches, ipads, so the rules will get many “else if” I think? pretty stupid but I have no idea of how to optimize them…
What I want is,
- If any of the phone’s distance < 200, make the group switch to ON, only if all 3 phones >=200(means no one near home), then change the group switch to OFF.
- Be able to add more phones without changing the rule files(which I don’t know how to).
- Be able to add different icloud account.
So sorry for the noob questions, could you guys please help me optimize the rules? Thanks…