Hi all,
I’ve been using the brilliant icloud binding to detect presence for my wife and I, which has been and still is running flawlessly to date. I’ve ‘borrowed’ a number of different scripts from here and it does what I want it to…
The presence detection is mainly based on @rlkoshak’s very useful Generic Presence Detection rule in that it updates a dummy item variable to ON for when we are home and OFF when we, yes you guessed it, are away.
I then have a number of other rules running from this item changing, (think lights, cameras, thermostat routines all changing depending on if we are home or not).
Now the whole presence detection is run by the icloud binding, thus:
My_iPhone_Home is part of the presence group which when it’s value changes turns on vPresent ON/OFF accordingly, (as per rlkoshak link above for more info).
//icloud My iPhone rule
rule "My iPhone Home"
when
Item My_iPhone_Location changed
then
// specify your home location - my home long / lat
val PointType home_location = new PointType(new DecimalType(my home latitude value), new DecimalType(my home longitude value))
val PointType phone_location = My_iPhone_Location.state as PointType
val int distance = phone_location.distanceFrom(home_location).intValue()
// home radius geofence to determine home/away (in meters)
if ( distance < 500)
{
My_iPhone_Home.postUpdate(ON)
logInfo(logName, "I am at home.")
}
else
{
My_iPhone_Home.postUpdate(OFF)
logInfo(logName, "I am away.")
}
end
Simple stuff, and as I said it works fine…now I want to take this one step further and have an additional option of ‘close to home’ rather than just home so I can have a few things set up ready for when I’m home, (ie thermostat warming up, driveway lights already on etc), so I added in a secondary if like so:
//icloud My iPhone rule
rule "My iPhone Home"
when
Item My_iPhone_Location changed
then
// specify your home location - my home long / lat
val PointType home_location = new PointType(new DecimalType(my home latitude value), new DecimalType(my home longitude value))
val PointType phone_location = My_iPhone_Location.state as PointType
val int distance = phone_location.distanceFrom(home_location).intValue()
// home radius geofence to determine home/away (in meters)
if ( distance < 500)
{
My_iPhone_Home.postUpdate(ON)
logInfo(logName, "I am at home.")
}
else
{
My_iPhone_Home.postUpdate(OFF)
logInfo(logName, "I am away.")
// Radius of around 3 miles / 5 minutes for extended geofence / close to home
if ( distance > 500 && distance < 5000 )
{
// Publish the current distance for reference
logInfo(logName, "My distance from home -" + distance + "m")
sendBroadcastNotification("My distance from home - " + distance + "m")
vMy_iPhone_Close.postUpdate(ON)
}
}
end
So, this extra bit basically increases the radius around the home to be greater than 500m and less than 5000m as I’ve worked out once I get into the 5000m zone its around 5 mins to drive home so time for things to get warming etc, I’ve also got it publishing the distance while I test it all.
The item vMy_iPhone_Close is a simple dummy variable item that I will run other rules off on it’s change…ie if changed to ON then set thermostat to 20degrees and turn on lights if dark for example.
Now, here’s the long winded question part, at the moment, while the rule works and produces the expected logfile / notifications, the logic isn’t quite there as I have a few foibles:
-
My local supermarket is less than 5000m away so while I’m doing a big shop I get a message every 5 minutes, (the icloud refresh rate), telling me my distance from home and so will be triggering whatever I run off this rule every 5 minutes. If I set the geofence to less than 5000m I run the risk of getting through the zone within 5 minutes, and possibly before the icloud refresh, ie getting no positive result.
-
The rule currently can’t decide if I’m actually coming or going, just if I’m in the ‘zone’ or not so even when I’m leaving, vMy_iPhone_Close will be ON and then thermostat will warm up etc, I only really want it to run if I’m coming back towards home.
-
At the moment the 5000m radius gives me definitely one, possibly 2 if it refreshes at the right time, icloud refreshes so I can’t determine if distance from home is reducing or increasing to fix part 2…and if I increase the radius by much more I start including a lot more of my local activities, (ie more than just supermarket), thereby making the rule less useful as I want to, for example, save money and make sure the thermostat isn’t heating an empty house for too long.
So, I’m after any thoughts to help frame what I’m trying to achieve…I’m sure there is a way it might just need some other input to get me thinking in a different way…
Can I possibly capture the one instance within the extended radius and store it in a variable to ignore repeat instances? Can I maybe extend the radius but have only the first 2 stored and then if second < first I’m moving closer to home etc???