Author Topic: Plugin - IPhone Locator  (Read 257251 times)

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Plugin - IPhone Locator
« on: October 06, 2013, 04:52:35 pm »
original thread http://forum.micasaverde.com/index.php/topic,15565.0.html

Official version can be installed from the App Store. Beta versions from here:
http://apps.mios.com/test-plugin.php?id=4686&show=versions

I summarized herebelow the information and features for this plugin.
New: You will find a step by step UI5 installation document here: http://code.mios.com/trac/mios_iphone-detector/export/147/trunk/iPhoneLocator/Install%20Doc.pdf

Cost: free, donation based on Paypal. thank you ! : https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=Z5KFCB3VH6MCQ&lc=FR&item_name=amg0&item_number=IPhoneLocator&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted.

Version Change Log
http://forum.micasaverde.com/index.php/topic,29732.msg210672.html#msg210672

Latest Version : 2.48
Features
  • Monitor the location of one or more of your apple devices in a single iCloud account. They are managed by a single root VERA device with a single polling loop updating all associated children devices for the multiple apple devices you want to monitor.  if you want to monitor only one device ( or have only one device in iCloud ), only the root VERA device is used so you will not see more than one device in that case.
  • Selectable Distance calculation mode can be either direct, driving, walking or bicycling mode. Non direct mode uses google matrix api
  • Default calculation mode is "direct" which keeps all code and all older calls to google, so behavior should be not changed for those who do not want to use the new driving, walking or bicycling mode
  • Events for Distance event (above/below) and for Present (at home or not)
  • a manual refresh mode to remove any automatic polling from VERA to iCloud and enable an external PLEG or scene to control when and to trigger refreshes
  • auto adaptive polling with an optional polling "map" which lets you set the distances and correspondant polling time you want
  • HouseMode (UI7) dynamically update UI7 HouseMode based on device presence status. See below for details
  • optional extra polling mode to get more accurate & precision from iCloud
  • Encryption of iCloud password is ready but I will enable it in a future version, just to seperate issues & concerns for testing this version
  • UI5/7 dashboard
    • useful information ( distance, speed, date, selected polling duration )
    • Exact position address display & Privacy mode to only show present status.
    • a multiple state icon which shows states: present, muted, away-stable, away-coming closer, away-going away
    • Mute and unmute buttons feature with its uPNP action as well, special Mute Icon for the muted state.
    • Refresh button for manual refresh : Immediately take into account new polling frequency parameters
  • CONTROL Tab
    • Debug and unDebug buttons feature on Control TAB to enable debug verbosity levels in log files
  • SETTINGS tab
    • facilitate entry of parameters with Regular expression checking for format of parameters. user interface with 'sub-tabs' on the top to select pages of settings and have more screen real estate for parameters...Dynamic save of changes in the Setting tabs. you just click the Save button in the TAB header bar ( top line ) at the bottom of the screen to save any changes. the button changes color: red if unsaved changes are pending, green or normal of changes were saved. Changes are not reflected in the browser until you do a Refresh tough...
    • User interface to select device names from the actual list of iCloud devices declared in the account and that you want to track. The pattern matching remains available as well so things like .* or ^name$ continue to work. in order to use the editor you just select device name in the left list, or a pattern in the upper text box and then click on the "==>" button to move it of the list on the right which is the final list of device(s) you decide to keep for tracking. NOTE changing the list of devices to track requires Save + a number of Luup engine reload to really trigger the complete device initialisation sequence + a browser refresh to remove the cash. it can be confusing so respect the sequence...
  • GOOGLE MAP tab
    • Showing base and moving device position with markers. includes all google map features, including satelite & street view !
    • Draggable base marker to set the Home location
    • Color coded markers to differentiate base from iDevices
    • Show All buttons to see all devices of a single iCloud account on the map
    • Add a Full Screen button to Map tab in order to open map in a blank window
    • Buttons to center the map on the base or on the phone
    • CheckBoxs to show the home-range and/or the polling map distances on the google map

Variables
  • Email: email address used in iCloud account
  • Password: password used in iCloud account
  • IPhoneName: it is recommended to only use the SETTINGS tab to edit this field. Technically it is a COMMA (',') separated list of Apple Device name associated to iCloud account and for which you want a device in VERA.  NOTE the names are LUA pattern matching so something like "^iPhone.*" (note the caret to mark start of name) is valid and will take ALL devices whose name is starting with "iPhone".  a name of ".*" will take ALL the devices declared in your iCloud. another example is to use the real names of several devices like device1name,device2name that will work to select only these 2 devices from iCloud.
    useful patterns:
    • "^iPhone.*" : all devices with names starting with iPhone
    • ".*": all devices in the iCloud account
    • "iPhone of mrX,iPad of msY" : the 2 specific devices named and nothing else
    • "^iPhone.*,Dog's iPad" : all devices with names starting with iPhone AND the ipad called Dog's iPad
    In case of multiple idevices managed under a same iCloud account and since V1.63, the order in the target list box ( SETTINGS screen ) or the name list ( ADVANCED tab ) matters. The FIRST name in that list will be the iDevice chosen to be the root vera device, while others will be child vera devices. In the Settings page, there are 2 buttons (Up,Down) to move up or down a particular name. The name at the top of the list is the name that will be the first in the IPhoneName parameter and will be the one chosen preferably to be the root device. Changing the order in that list will require a LUA reload action before the effect can be seen.

    Upgrade Considerations: when you upgrade, or when you change the list of the IPhoneName device names, this will actually trigger the VERA child device creation logic which will sometime result in VERA deleting and recreating new devices in a different order and with different IDs. 2 notables consequences to be aware of:  a) device ID are changed and other scene/plugin which uses devicesID may need to be reconfigured or updated. example PLEG or code in scenes. b) the first VERA reload may trigger a second vera reload when child devices are modified, so it does take quite some time before VERA is ready, just be patient and refresh your browser when the process is over
  • PollingBase: in seconds, a duration between 2 polls to iCloud.
  • PollingAuto: 0 or 1. when 1 then the polling period is adjusted dynamically in function of the monitored device distance from its base. The exact behavior depends on your polling map.
    • PollingMap is empty: The polling takes the estimated time for the device to reach its base and divide this time by the PollingDivider parameter to split it in chunks. 2 is the minimum to get accurate prediction of arrival. more will poll more and drain more battery but will give better real time tracking, so manipulate with care. when at base the PollingBase will be used.
    • PollingMap is not empty:it means you specifically want to override the default behavior and have to set your own polling / distance pairs
  • PollingMap: Enables a polling duration based on the Distance reported. The polling duration calculated is the minimal of all polling required between all devices managed from this same iCloud account based on the polling map and their respective base location. if empty, dynamic polling follows a simple algorythm: if (Distance>100) the period is 10 times the based period, if Distance>10 the period is 3 times the based period.  if it is filled in, then its format is a COMMA (',') separated list of pairs like dist:polling. Number of pairs/steps is not fixed, up to you. for instance 0:600,1:60,10:300,100:1800 which would mean, if the distance is less than 1, polling will be 600s, if it is between 1 and 10, polling will be 60s, if it is between 10 and 100, polling will be 300s, if it is above 100, polling will be 1800s
  • PollingDivider variable: used to split ETA google estimation in chunks, only used in auto mode with no Polling Map
  • PollingExtra: When enabled the plugin will poll iCloud twice ( seperated by 4 secs ) in order to force iCloud to give back an accurate & recent position.
  • ETA variable to contain last reported ETA by google, or calculated ( in direct mode )
  • Version: a plugin version variable, could be useful later for upgrades
  • HomeLat HomeLong: The home base position for that device. (dd.dddddd >0 for North, <0 for South) (dd.dddddd  >0 for East, <0 for West), not every device needs to have the same home. But, the minimum distance between device and their home, for all the devices of a given iCloud account is what is taken into account to determine the polling frequency in case of "PollingAuto" mode
  • Range: tolerance distance to declare a device present or not
  • ICloudName: name received from ICloud. Name of device can be changed by changing device attribute ( and not that variable)
  • CurLat CurLong PrevLat PrevLong: The plugin Variable CurLat CurLong are the latest detected position and PrevLat PrevLong are the position just before
  • AddrFormat:
    - it is either empty ( in which case it takes the json_obj.results[1].formatted_address from google API result and behaves like today )
    - or it is "0" in which case this is the Privacy mode, only Present or Away status is shown but no other information like distance or address

    If ( and only if ) the DistanceMode value is "direct" then the 2 next possibilities are offered:
    - it can be a comma seperated list of values from 1 up to 7 to take the individual elements of json_obj.results[1].address_components array from the google API result. for instance you can have "AddrFormat" = "3,5".  the Order does matter.
    - or if it starts with a ~ character and the rest is a template string which contains variable names between '{' '}' like this: ~{street_number} {route},{postal_code} {locality}, {country}.   The names of variable are directly documented by google here: https://developers.google.com/maps/documentation/geocoding/?hl=fr#Types
  • IconCode: internal, controls which icon is displayed
  • MsgText: internal, controls the text to be shown on the UI5 dashboard
  • Muted: 1 if device is muted, 0 otherwise
  • Present: 1 if device is present, 0 otherwise. since v1.96, it will takes into account the accuracy of the metric reported by iCloud
  • HouseModeActor 1 if device participates in HouseMode calculation, 0 otherwise
  • Location: Postal address as reported by Google map address API and formatted according to "AddrFormat" variable. controls the text to be shown on the UI5 dashboard
  • LocationExtraInfo: variable that holds extra information coming from iCloud location info. format is type:accuracy:isold where type is GPS or Wifi, accuracy is the accuracy reported in meters, isold is a boolean
  • DistanceMode: selection menu in the polling SETTING tab for direct (straight line) , driving, walking or bicycling mode. Distance calculation will be done by google instead of vera and will take into account roads. Uses google matrix api if the calculation mode is NOT "direct". it will call google api only once for a hierarchy of device. Default calculation mode is "direct" which keeps all code and all older calls to google, so behavior should be not changed for those who do not want to use the new driving, walking or bicycling mode
  • Distance: last distance computed for the device
  • PrevDistance: distance computed for the device at the previous polling period
  • RTSpeed: Observed realtime speed of the device in 'unit' per hour
  • LastUpdate: timestamp of last update
  • Unit: 'Mm' is statute miles, 'Km' is kilometers (default), 'Nm' is nautical miles
  • Debug: Debug mode or not, this affects ALL IPhoneLocator devices, not only this one and generates quite a number of log so, to be used only for troubleshooting purposes
  • MapUrl variable that holds the url to open that same google map in another window if wished
  • RootPrefix String used to prefix the name for the root device ( defaults to "(*)" )
  • GoogleMapKey Google Map Key that you can get from the google map cloud console. this is needed to allow the API calls to DistanceMatrix and Geocode API and map API from google. Please read the Google map key section in the document http://code.mios.com/svn/mios_iphone-detector/trunk/iPhoneLocator/Another%20UI7%20Install%20doc.pdf to understand and estimate the cost consequences. The first 200$ are not charged by Google

Notifications
  • "Device is present" : When the device is present or absent, in no repeat mode
  • "Distance is above" "Distance is above" : When the distance crosses a certain threshold, in no repeat mode


uPNP Actions
  • action "ForceRefresh" : for forcing a refresh. it will return a PresentStatus output variable (1:if device is at home). this should be testable/visible by using http://<veraip>:3480/data_request?id=lu_invoke&DeviceNum=<devicenumber>
  • action "setMute" : for forcing a Mute so the device is not refreshing position. note that this applies to the iCloud account so in effect it will mute ALL the devices which are associated to this iCloud account
  • action "setPresent" : for forcing a present/away state (mostly for debug)
  • action "setDebug" : for enabling debug mode in the logs(use only for troubleshooting)
  • action "GetMapUrl" UPNP action which returns the url to open in a browse to see a map centered on the phone position

More information about auto polling mode
ModeDistanceSpeedEtaPolling
Directcalculated from gps coordinate from the last and previous positionscalculated from ratio distance/polling. if speed is less than MIN_SPEED it is considered null.calculated from distance/speed. if speed is null, it assumes a default speed (NOMOVE_SPEED) to make sure polling does not get too infrequentWith polling map: it uses the polling map, based on device distance.
Without polling map, it takes the ETA, remove from it a default LATENCY parameter to compensate for lateness of iCloud compared to reality, divide the eta by the PollingDivider set by the user.  Then the result is normalized to allways be between a MIN_PERIOD and MAX_PERIOD.
Driving, Bicycling, WalkingReceived from Google Matrix APIsame as above.ETA is not calculated, it is simply received from the google matrix API and therefore is subject to google calculation and estimation what your speed is based on the mode you selected.same as above.

Code: [Select]
local MIN_PERIOD = 10        -- poll cannot be less than this in sec
local MAX_PERIOD = 3600   -- poll cannot be more than this in sec
local ETA_LATENCY = 30      -- ETA Latency, removes this from ETA to compensate for iCloud latency
local MIN_SPEED = 5/3600   -- 5km/h (in km/s)
local NOMOVE_SPEED = 60/3600  - in km/s, when speed is null or <Min

Considerations for multiple devices in a single iCloud account
  • Child devices:  one device holds the iCloud relation and polling activity for all the apple devices. So there is a parent device in VERA and child devices. Since most users have only one device, the parent device is also used for the first iCloud device. if you have more than one device in your iCloud account and if the iPhoneName pattern selects more than one, additional child devices will be created as needed. the Child device do not have all the properties of the parent device because they do not need things email/pwd etc as they do not connect to iCloud themselves. To give a user hint to which device is the master device, its name is preceeded by a (*) sign in its Name blue bar
  • IPhoneName: chose which of your iCloud devices you want location reporting. using comma seperated list of names, and LUA pattern matching. in fact it is a comma seperated list of lua pattern matching because lua does not seem to support "OR" between patterns so the comma effectively enables to perform an "OR"
  • Mute: a Mute command is reflected back to the parent device managing the iCloud account. so Muting a device, mutes all devices for a given iCloud account
  • Refresh: a Refresh command is reflected back to the parent device managing the iCloud account. so Muting a device, mutes all devices for a given iCloud account
  • Dynamic Polling: enables to chose a polling duration based on the distance of the device, but the Polling considered is the minimal of all required polling between all devices managed from this same iCloud account

Considerations for UI7 HouseModes
  • Only devices with the HouseModeActor variable set to 1 will participate in the HouseMode status determination. by default a device DOES NOT participate.
  • if all participating devices are away, and mode is home or night then HouseMode is set to away  ( meaning vacation is ignored & unchanged )
  • if 1 participating device is present, and mode is away then  HouseMode is set to home ( meaning vacation or night is ignored & left unchanged )
Enjoy...
« Last Edit: Today at 03:31:27 pm by amg0 »

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: Plugin - IPhone Locator
« Reply #1 on: October 06, 2013, 05:03:48 pm »
If you are looking for beta
« Last Edit: October 06, 2013, 05:19:15 pm by Crismaison »
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Re: Plugin - IPhone Locator
« Reply #2 on: October 06, 2013, 05:21:13 pm »
Privacy mode is by setting "0" to AddrFormat. I could think of a helper in the Settings tab for sure
Quote
AddrFormat:
- it is either empty ( in which case it takes the json_obj.results[1].formatted_address from google API result and behaves like today )
- or it is "0" in which case this is the Privacy mode, only Present or Away status is shown but no other information like distance or address
- or it is a comma seperated list of values from 1 up to 7 to take the individual elements of json_obj.results[1].address_components array from the google API result. for instance you can have "AddrFormat" = "3,5".  the Order does matter.

Child devices are only installed if there is more than one device to report on in the iCloud account *AND* if the IPhoneName parameter enables selection of more than one. For instance putting ".*" in IPhoneName will report ALL your iCloud account devices
Quote
IPhoneName: a COMMA (',') separated list of Apple Device name associated to iCloud account and for which you want a device in VERA. NOTE the names are LUA pattern matching so something like "iPhone.*" is valid and will take ALL devices whose name is starting with "iPhone".  a name of ".*" will take ALL the devices declared in your iCloud. another example is to use the real names of several devices like device1name,device2name that will work to select only these 2 devices from iCloud

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: Plugin - IPhone Locator
« Reply #3 on: October 06, 2013, 05:32:35 pm »
Works really well the childs!
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Re: Plugin - IPhone Locator
« Reply #4 on: October 06, 2013, 05:34:29 pm »
Works really well the childs!
good ! have fun, try the mute button on a child to see what happens

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: Plugin - IPhone Locator
« Reply #5 on: October 06, 2013, 05:39:21 pm »
One remark, the child does not inherit the home long and lat. Location from the parent.
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline nutcracker

  • Sr. Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
Re: Plugin - IPhone Locator
« Reply #6 on: October 06, 2013, 05:48:58 pm »
Thanks amg0!  ;)

Offline doon386

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Plugin - IPhone Locator
« Reply #7 on: October 06, 2013, 05:54:21 pm »
Just installed the plugin for tracking my daughters iPhone. Seems to work just fine.

One nit, however. Being in the US we use miles (mi) rather than kilometers (km) for distance. Would it be possible to select/change the units between km & mi?

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Re: Plugin - IPhone Locator
« Reply #8 on: October 06, 2013, 06:34:37 pm »
Just installed the plugin for tracking my daughters iPhone. Seems to work just fine.

One nit, however. Being in the US we use miles (mi) rather than kilometers (km) for distance. Would it be possible to select/change the units between km & mi?

ok, added it in next version roll out.

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Re: Plugin - IPhone Locator
« Reply #9 on: October 06, 2013, 06:36:26 pm »
One remark, the child does not inherit the home long and lat. Location from the parent.

Added it too in future v1.30, also inheriting the "unit" now

Offline doon386

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: Plugin - IPhone Locator
« Reply #10 on: October 06, 2013, 07:42:49 pm »
Wow! You're quick. Thanks!

Offline emtschei

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Re: Plugin - IPhone Locator
« Reply #11 on: October 06, 2013, 09:06:33 pm »
This is so fantastic work. Thank you, @amg0 ... especially for 'my' Mute/Unmute buttons  ::).

V1.30Beta could be installed without any problems from the link mentioned. The previously entered parameters were adopted.
I have only one iPhone configured and cannot report on child features.

A few remarks though:
- the privacy mode cannot be set in the settings tab. Entering a 0 is not possible !!!
- Privacy mode works though when entering the 0 directly in the Advanced Tab.

- the description fix for
Quote
fix of the East/West text that was wrong
seems to have gotten lost.

- the PollingMap cannot be set through the Settings Tab as there is no field and has to be entered in the Advanced Tab. Maybe this was your intention in the first place. Would be nice though to have this field in the Settings Tab with everything else.

- what does the (*) in front of my iPhone name in the device title represent (I have only a single iPhone defined)?


Thank you
MJ
« Last Edit: October 06, 2013, 09:32:22 pm by emtschei »

Offline amg0

  • Moderator
  • Sr. Hero Member
  • *****
  • Posts: 2990
  • Karma: +203/-8
Re: Plugin - IPhone Locator
« Reply #12 on: October 07, 2013, 03:28:25 am »
This is so fantastic work. Thank you, @amg0 ... especially for 'my' Mute/Unmute buttons  ::).

V1.30Beta could be installed without any problems from the link mentioned. The previously entered parameters were adopted.
I have only one iPhone configured and cannot report on child features.

A few remarks though:
- the privacy mode cannot be set in the settings tab. Entering a 0 is not possible !!!
- Privacy mode works though when entering the 0 directly in the Advanced Tab.

- the description fix for
Quote
fix of the East/West text that was wrong
seems to have gotten lost.

- the PollingMap cannot be set through the Settings Tab as there is no field and has to be entered in the Advanced Tab. Maybe this was your intention in the first place. Would be nice though to have this field in the Settings Tab with everything else.

- what does the (*) in front of my iPhone name in the device title represent (I have only a single iPhone defined)?


Thank you
MJ

@emtschei,  have you done/forced  a browser cache refresh ( ctrl F5 or Shift F5 ) ?

It is needed sometime after upgrading a plugin files before the new *.JS pages ( like settings tab) and dashboard Json files are taken into account. It seems several problem you report should not be there and are not on my system. Specifically, I verified I can enter "0" in addrFormat from the Settings tab with out any problem. the text for longitude is also correct, it is >0 for East location.

The dynamic polling map is available in the Settings tab too. just in the line with Dynamic Polling, you should see a checkbox followed by a text field which is the dynamic polling map

the (*) in front of title, means this device is the parent device , the one who owns the iCloud crendential and doing the polling loop. if you had child devices, you would see that these do not have a (*) in their title

Offline Crismaison

  • Sr. Member
  • ****
  • Posts: 451
  • Karma: +2/-0
Re: Plugin - IPhone Locator
« Reply #13 on: October 07, 2013, 03:36:58 am »
I can also enter the 0 and also very smart to hide the KM away in the text  ;D
Vera lite - Everspring smoke & flood detectors - Fibaro doorsensors - 2 Foscams - Greenwave 6 node smartplug - Several Switches -Netatmo - PLEG - Twilio - DropBoxuploader - FindmyIphone user

Offline mikee123

  • Hero Member
  • *****
  • Posts: 1521
  • Karma: +18/-11
Re: Plugin - IPhone Locator
« Reply #14 on: October 07, 2013, 06:27:09 am »
I am trying to install the latest beta, but when i try to install from the app store i get an error message unable to check installation status. And on vera the mute und unmute buttons have disappeared, and in advanced settings i have version 1.24. Is this the way i should upgrade to 1.30 ?