-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiphonelocation.ini.tmpl
422 lines (422 loc) · 39.8 KB
/
iphonelocation.ini.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
### This is about to be a lot of writing, that's why this is moved to another file.
logger.info('INI_CREATION - Writing header and [database] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### This is the configuration file for the ISY iCloud Proximity python script. This script uses these config items ###\n''')
f_out.write('''### to make an connection to the Apple iCloud API and read some data about your iOS device including it's ###\n''')
f_out.write('''### current GPS location, how that location was obtained and the devices current battery level. It then uses ###\n''')
f_out.write('''### this data along with the supplied GPS coordinates of your "home", calculates the distance you are from that ###\n''')
f_out.write('''### location, then reports it to various home automation platforms you might be using. Currently supported are ###\n''')
f_out.write('''### ISY series home automation controllers from Universal Devices and the open source project openHAB. ###\n''')
f_out.write('''### ###\n''')
f_out.write('''### Below are the configuration items used to control the behavior of each feature of the script. Each section will ###\n''')
f_out.write('''### be described in the best detail possible and if you have questions or can not configure a certain portion of ###\n''')
f_out.write('''### the script, please open an issue on GitHub at:https://github.com/stevenmcastano/ISY-iCloud-Proximity/issues ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### The database section: ###\n''')
f_out.write('''### This section of configuration items are use to connect to the MySQL (or MySQL compatible) database that is ###\n''')
f_out.write('''### to store application data. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[database]\n''')
f_out.write('''\n''')
f_out.write('''# The follow setting is a string which is the name of the database you'll be using to store the application data:\n''')
f_out.write('''database = {}\n'''.format(db_conf['name']))
f_out.write('''\n''')
f_out.write('''# The following setting is the IP address or hostname running your database software:\n''')
f_out.write('''host = {}\n'''.format(db_conf['host']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the port your database server is configured to list on. If you are running MySQL or MariaDB\n''')
f_out.write('''# and haven't changed the default, it's 3306:\n''')
f_out.write('''port = {}\n'''.format(db_conf['port']))
f_out.write('''\n''')
f_out.write('''# The following setting is the database connection username:\n''')
f_out.write('''user = {}\n'''.format(db_conf['user']))
f_out.write('''\n''')
f_out.write('''# The following setting is the database connection password:\n''')
f_out.write('''passwd = {}\n'''.format(db_conf['passwd']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [ISY] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### The ISY section: ###\n''')
f_out.write('''### This section of configuration items are use to connect to your Universal Devices ISY series controller. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[ISY]\n''')
f_out.write('''\n''')
f_out.write('''# The following setting is your ISY username:\n''')
f_out.write('''username = {}\n'''.format(isy_conf['username']))
f_out.write('''\n''')
f_out.write('''# The following setting is your ISY password:\n''')
f_out.write('''password = {}\n'''.format(isy_conf['password']))
f_out.write('''\n''')
f_out.write('''# The following setting is the ISY controller's hostname or IP address:\n''')
f_out.write('''hostname = {}\n'''.format(isy_conf['hostname']))
f_out.write('''\n''')
f_out.write('''# The following setting tells the script if we are making an SSL encrypted connection to the ISY. If you do use SSL\n''')
f_out.write('''# set this to "True", if you do not you can leave the default of "False". This can also be configured with valid\n''')
f_out.write('''# settings or "yes" or "no", or "1" for SSL or "0" to not use SSL:\n''')
f_out.write('''SSL = {}\n'''.format(isy_conf['SSL']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the port your ISY controller listens on. If you have not changed the defaults and you are\n''')
f_out.write('''# not using SSL, the default port of 80 should work. If you are using SSL and have not change the default ISY SSL\n''')
f_out.write('''# port, then the port setting would be 443:\n''')
f_out.write('''port = {}\n'''.format(isy_conf['port']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [openHAB] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### The openHAB section: ###\n''')
f_out.write('''### This section of configuration items are use to connect to your openHAB instance. Currently this has only ###\n''')
f_out.write('''### been tested on version 2 of the openHAB project and may not work on the version 1.7 series. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[openHAB]\n''')
f_out.write('''\n''')
f_out.write('''# The following setting is to enable or disable openHAB support. If you would like to use this with openHAB, this can\n''')
f_out.write('''# be set to "True", if you do not with to use openHAB support, the default setting here of "False" will disable\n''')
f_out.write('''# openHAB support and ingore the rest of the settings in this section:\n''')
f_out.write('''enabled = {}\n'''.format(openhab_conf['enabled']))
f_out.write('''\n''')
f_out.write('''# The following setting controls if you are using a username and password with openHAB. If this is set to "True" then\n''')
f_out.write('''# the next two settings for username and password must be set as well. If you are not using authentication you can\n''')
f_out.write('''# leave the default setting here of "False"\n''')
f_out.write('''authentication = {}\n'''.format(openhab_conf['authentication']))
f_out.write('''\n''')
f_out.write('''# The follow setting is your openHAB username if you have authentication enabled. If you do not, this setting will be\n''')
f_out.write('''# ignored.\n''')
f_out.write('''username = {}\n'''.format(openhab_conf['username']))
f_out.write('''\n''')
f_out.write('''# The follow setting is your openHAB password if you have authentication enabled. If you do not, this setting will be\n''')
f_out.write('''# ignored.\n''')
f_out.write('''password = {}\n'''.format(openhab_conf['password']))
f_out.write('''\n''')
f_out.write('''# The following setting if your openHAB instance hostname or IP address:\n''')
f_out.write('''hostname = {}\n'''.format(openhab_conf['hostname']))
f_out.write('''\n''')
f_out.write('''# The following setting tells the script if we are making an SSL encrypted connection to openHAB. If you do use SSL\n''')
f_out.write('''# set this to "True", if you do not you can leave the default of "False". This can also be configured with valid\n''')
f_out.write('''# settings or "yes" or "no", or "1" for SSL or "0" to not use SSL:\n''')
f_out.write('''SSL = {}\n'''.format(openhab_conf['SSL']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the port your openHAB listens on. If you have not changed the defaults and you are\n''')
f_out.write('''# not using SSL, the default port of 80 80should work. If you are using SSL and have put your openHAB instance\n''')
f_out.write('''# begind a reverse proxy like nginx or apache, most likely SSL is running on port 443.\n''')
f_out.write('''port = {}\n'''.format(openhab_conf['port']))
f_out.write('''\n''')
f_out.write('''# The follow setting it the name of the custom "item" you created in your openHAB configuration to store the\n''')
f_out.write('''# distance data in:\n''')
f_out.write('''item_name = {}\n'''.format(openhab_conf['item_name']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [iCloudAPI] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### The iCloudAPI section: ###\n''')
f_out.write('''### This section of configuration items is simply your iCloud username and password. It is the same username and ###\n''')
f_out.write('''### password you use to log into iTunes or the AppStore. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[iCloudAPI]\n''')
f_out.write('''\n''')
f_out.write('''# The following setting is your iCloud username:\n''')
f_out.write('''username = {}\n'''.format(icloudapi_conf['username']))
f_out.write('''\n''')
f_out.write('''# The following setting is your iCloud password:\n''')
f_out.write('''password = {}\n'''.format(icloudapi_conf['password']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [device] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### The device section: ###\n''')
f_out.write('''### This section of configuration items are all the names, identifies and script configuration items that will ###\n''')
f_out.write('''### used to read your device data, set your home location, tell the script what ISY variable to store the ###\n''')
f_out.write('''### distance data in as well as a large number of more advance options, that for basic script opertation you can ###\n''')
f_out.write('''### leave set to all of their defaults. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[device]\n''')
f_out.write('''\n''')
f_out.write('''# The following setting is the name of the persons who's device this script is used for. The name is only used for\n''')
f_out.write('''# logging purposes to make things easier to read and will be used in the future when multi-device support in a\n''')
f_out.write('''# single script is created:\n''')
f_out.write('''name = {}\n'''.format(device_conf['name']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the same as above, but it should be exactly 3 characters in order to fit into some debug log\n''')
f_out.write('''# formats:\n''')
f_out.write('''shortname = {}\n'''.format(device_conf['shortname']))
f_out.write('''\n''')
f_out.write('''# The following setting is the number of the ISY varible used to store the current distance. Currently this data\n''')
f_out.write('''# must be stored in a variable of type "state". In order to create this variable and or get it's number, you will\n''')
f_out.write('''# need to open your ISY admin interface and natication to the "Programs" tab, then the "Variables" sub tab under\n''')
f_out.write('''# that, and again the "State" table under there. The number in the "ID" column is the number of the variable that\n''')
f_out.write('''# should be set here:\n''')
f_out.write('''ISYDistanceVAR = {}\n'''.format(device_conf['ISYDistanceVAR']))
f_out.write('''\n''')
f_out.write('''# The following setting the it Apple assigned identifier or "GUID" assigned to the device you want to use to read\n''')
f_out.write('''# location data from. In order to obtain this you should follow in the installation instruction in the README.md\n''')
f_out.write('''# file, or read them from the project code site at: https://github.com/stevenmcastano/ISY-iCloud-Proximity\n''')
f_out.write('''iCloudGUID = {}\n'''.format(device_conf['iCloudGUID']))
f_out.write('''\n''')
f_out.write('''# The following setting is the lattitude of your home location. This can be obtained by searching from your home\n''')
f_out.write('''# address on https://maps.google.com and clicking on the map just over your home:\n''')
f_out.write('''location_home_lat = {}\n'''.format(device_conf['location_home_lat']))
f_out.write('''\n''')
f_out.write('''# The following setting is longitude of your home location. This can be obtained by searching from your home\n''')
f_out.write('''# address on https://maps.google.com and clicking on the map just over your home:\n''')
f_out.write('''location_home_long = {}\n'''.format(device_conf['location_home_long']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [device] ADVANCED section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Advanced Settings: ###\n''')
f_out.write('''### For basic script operation there is no need to change anything below this line the application will run fine ###\n''')
f_out.write('''### with all of these settings below left at their defaults. Should you choose to change any of these settings ###\n''')
f_out.write('''### please make sure you make a backup of your configuration file first. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Radio check settings: ###\n''')
f_out.write('''### The following sub section of settings is used to enable the "radio check" feature of the script. This tells ###\n''')
f_out.write('''### the script to check other variables on the ISY that be set by scripts or applications outside of this one ###\n''')
f_out.write('''### determine if your iOS device is within radio range via WiFi or Bluetooth. This is done to conserve device ###\n''')
f_out.write('''### battery life. If the device can be located locally via WiFi or Bluetooth the script, by default, then skips ###\n''')
f_out.write('''### doing a GPS and battery level check for 5 minutes at which time it checks to see if the device is still in ###\n''')
f_out.write('''### "radio" range according to the ISY variables. It also, by default, then does a GPS check once ever hour just ###\n''')
f_out.write('''### to make sure your radio detection scripts are still working. ###\n''')
f_out.write('''### ###\n''')
f_out.write('''### The time to wait between radio check cycles, the expected value of the variables being read, the time ###\n''')
f_out.write('''### between forced GPS checks, or whether to even do them or not are all configurable in settings also in this ###\n''')
f_out.write('''### configuration file. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''# The following setting enables the script feature that reads an ISY variable to determine if your iOS device is\n''')
f_out.write('''# present via WiFi on your local network:\n''')
f_out.write('''WiFiCheck = {}\n'''.format(device_conf['WiFiCheck']))
f_out.write('''\n''')
f_out.write('''# The following setting enables the script feature that reads an ISY variable to determine if your iOS device is\n''')
f_out.write('''# within range of a bluetooth sensor in your home:\n''')
f_out.write('''BTCheck = {}\n'''.format(device_conf['BTCheck']))
f_out.write('''\n''')
f_out.write('''# The following setting is the ISY variable ID number that stores your WiFi presence info:\n''')
f_out.write('''ISYWifiVAR = {}\n'''.format(device_conf['ISYWifiVAR']))
f_out.write('''\n''')
f_out.write('''# The following setting is the value the script expects to read from the ISY WiFi variable to indicate the device is\n''')
f_out.write('''# present via WiFi:\n''')
f_out.write('''ISYWifiVAR_Expected = {}\n'''.format(device_conf['ISYWifiVAR_Expected']))
f_out.write('''\n''')
f_out.write('''# The following setting is the ISY variable ID number that stores your Bluetooth presence info:\n''')
f_out.write('''ISYBtVAR = {}\n'''.format(device_conf['ISYBtVAR']))
f_out.write('''\n''')
f_out.write('''# The following setting is the value the script expects to read from the ISY WiFi variable to indicate the device is\n''')
f_out.write('''# present via Bluetooth:\n''')
f_out.write('''ISYBtVAR_Expected = {}\n'''.format(device_conf['ISYBtVAR_Expected']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [general] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Advanced General Settings: ###\n''')
f_out.write('''### For basic script operation there is no need to change anything below this line the application will run fine ###\n''')
f_out.write('''### with all of these settings below left at their defaults. Should you choose to change any of these settings ###\n''')
f_out.write('''### please make sure you make a backup of your configuration file first. ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Do not change the follow line with the section title!\n''')
f_out.write('''[general]\n''')
f_out.write('''\n''')
f_out.write('''# The following setting is the number of devices we're checking. For now script only supports checking one device at a\n''')
f_out.write('''# time so this setting should remain set to 1:\n''')
f_out.write('''numberofdevices = {}\n'''.format(general_conf['numberofdevices']))
f_out.write('''\n''')
f_out.write('''# The following setting is the number of seconds the script will wait before running another radio check if you have\n''')
f_out.write('''# WiFi and/or Bluetooth checking enabled.\n''')
f_out.write('''cycle_sleep_withradio = {}\n'''.format(general_conf['cycle_sleep_withradio']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the number of seconds the script will wait between attempting to read your location from the\n''')
f_out.write('''# iCloud API. This setting is used in conjunction with the next setting controlling home close too home your device\n''')
f_out.write('''# should be before "variable time" checking begins. If you are not using radio checking and you find your battery\n''')
f_out.write('''# life is beging negatively effected, that may be because the script is set to update your GPS location once every\n''')
f_out.write('''# 60 second by default. Increasing this setting will reduce the number of GPS checks the script does while you are\n''')
f_out.write('''# close to home. Be careful, however, setting this too long may mean that the script won't check frequently enough\n''')
f_out.write('''# when you are CLOSE to home, but not actually home, and the next GPS check might occur after you've already\n''')
f_out.write('''# actually arrived home.\n''')
f_out.write('''cycle_sleep_default = {}\n'''.format(general_conf['cycle_sleep_default']))
f_out.write('''\n''')
f_out.write('''# The following setting is the distance in miles you need to be away from your home location before the script starts\n''')
f_out.write('''# to vary the time between GPS checks. By default this is 5 miles. After that, the script will begin to your GPS\n''')
f_out.write('''# location less and less often the farther away from home you are. This, again, is done to conserve batter life\n''')
f_out.write('''# which is even more important when you're not home and probably don't have your device plugged in.\n''')
f_out.write('''cycle_sleep_distance = {}\n'''.format(general_conf['cycle_sleep_distance']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the minimum change in distance in miles from home for the script to consider your device as\n''')
f_out.write('''# being "in motion". This is done due to the "variable time" between GPS checks mentioned above. The script, by\n''')
f_out.write('''# default is set to begin checking your GPS location more requently if it thinks you are geting closer to your home\n''')
f_out.write('''# location. This is done so you don't arrive home "between" GPS checks. The default is .5, or 1/4 mile.\n''')
f_out.write('''cycle_sleep_variable_distance = {}\n'''.format(general_conf['cycle_sleep_variable_distance']))
f_out.write('''\n''')
f_out.write('''# The follow setting is the sleep modifier if you are not moving, or moving away from home. What this mean is that\n''')
f_out.write('''# when the script things you are not moving (less then the "cycle_sleep_variable_distance" change from one\n''')
f_out.write('''# reading to the next), the script varies it's time between GPS checks by this number. So, for instance, if you\n''')
f_out.write('''# are 100 miles away from home, the script would take the 100 miles, divide it by the number below (a default of\n''')
f_out.write('''# 2), then multiply by 60 to get the number of seconds it shold wait before checking your GPS location again.\n''')
f_out.write('''#\n''')
f_out.write('''# So it looks like this at 100 miles from home:\n''')
f_out.write('''# 100 miles / 2 = 50 miles\n''')
f_out.write('''# 50 miles * 60 seconds per mile = 3,000\n''')
f_out.write('''# So if you are 100 miles from home and either staying in one location, or moving farther away from your home\n''')
f_out.write('''# location, the script would wait 3,000 seconds (which is 50 minutes) before checking your location again.\n''')
f_out.write('''#\n''')
f_out.write('''# By increaseing the number below, you would shorten the time between GPS location checks when the script thinks\n''')
f_out.write('''# you are staying in one location or moving farther away from home. Bby decreasing this number, the script\n''')
f_out.write('''# would check even less frequently.\n''')
f_out.write('''cycle_sleep_variable_modifier_default = {}\n'''.format(general_conf['cycle_sleep_variable_modifier_default']))
f_out.write('''\n''')
f_out.write('''# The follow setting sleep modifier if you are getting closer to home which is basically the same idea as the setting\n''')
f_out.write('''# just above this, but this one is used when the script thinks you are moving closer to home. So, if you've left the\n''')
f_out.write('''# "cycle_sleep_variable_distance" setting to it's default of .5 miles and script sees you've moved farther then that\n''')
f_out.write('''# between your last 2 GPS checks, it uses the number below as the variable time modifier.\n''')
f_out.write('''#\n''')
f_out.write('''# So for another example: If you were 100 miles away from home on your last GPS check, but on this GPS check\n''')
f_out.write('''# you are are only 95 miles from home, the script thinks you are getting close to home and does the follow math:\n''')
f_out.write('''# 95 miles / 4 = 23.75 miles\n''')
f_out.write('''# 23.75 miles * 60 seconds per mile = 1,425\n''')
f_out.write('''# So if you are 95 miles from home, but the script detects you are getting closer to home, it sleeps for 1,425\n''')
f_out.write('''# seconds, or just under 24 minutes. This allows the script to check your GPS location more frequently when you're\n''')
f_out.write('''# headed toward home to ensure that it reports back to the ISY your distance with as much accurancy as possible\n''')
f_out.write('''# so you don't arrive home between GPS checks. Especially if you have your ISY configure to turn on outside drive or\n''')
f_out.write('''# front porch/door lights, maybe even open the garage door for you when you're withing 1/4 mile or something.\n''')
f_out.write('''cycle_sleep_variable_modifier_inbound = {}\n'''.format(general_conf['cycle_sleep_variable_modifier_inbound']))
f_out.write('''\n''')
f_out.write('''# Distance precision, i.e. how many decimal places of distance to report to the ISY.\n''')
f_out.write('''# **NOTE: You must be running firmware v5.0.x or above to use this option. By default\n''')
f_out.write('''# it should be left at 0.\n''')
f_out.write('''#\n''')
f_out.write('''# If you are running firmware v5.0.x or higher you set your state variables to allow up to 8 decimal places of\n''')
f_out.write('''# precision. The setting below ups the number of decimal places the script reports to the ISY to match whatever\n''')
f_out.write('''# you've set your variable to. This allows you to have much more fine rained control over when things happen. For\n''')
f_out.write('''# instance, you may want your ISY to open your garage door for you when you're within 1/5 mile (.25 miles) of home.\n''')
f_out.write('''# Without using more precision the distances would be reported to the ISY as entire miles, so you'd have either 0, 1\n''')
f_out.write('''# 2, 3.... miles. For people that want more control over when things happen closer to home inside of 1 mile,\n''')
f_out.write('''# changing your variable precision both here and in the ISY admin console will allow you to do that.\n''')
f_out.write('''isy_distance_precision = {}\n'''.format(general_conf['isy_distance_precision']))
f_out.write('''\n''')
f_out.write('''# The follow setting multiplies the distance reported to the ISY by the value below. This is done for ISY units running\n''')
f_out.write('''# firmware earlier than v5.0.x so they can have more precise distance actions as explained in the prevision setting\n''')
f_out.write('''# above. For example, if the setting below is set to 100, a distance of 23.12345678 miles, with the above precision\n''')
f_out.write('''# setting left set at 0, will report it's distance to the ISY as 2312. This basically means your distance is 2312\n''')
f_out.write('''# 100ths of a mile. So if you wanted to do something that was 1/4 of a mile, or .25 miles away, you would configure\n''')
f_out.write('''# your ISY programs to perform an action above or below "25" since 1/4 mile is actually 25 100ths of a mile.\n''')
f_out.write('''isy_distance_multiplier = {}\n'''.format(general_conf['isy_distance_multiplier']))
f_out.write('''\n''')
f_out.write('''# The follow setting controls if the app will accept GPS data obtained from a previous device lookup as a valid\n''')
f_out.write('''# location. One of the things contained in the data read from the iCloud API is a flag called "isOld" which\n''')
f_out.write('''# indicates that the GPS location reported from the API was over 3 minutes old. If you are somewhere where you\n''')
f_out.write('''# don't have a clear view of the sky, a WiFi connection, or a good strong collular connection, your phone may have\n''')
f_out.write('''# trouble determining it's location so it holds the last known valid location. With the setting below left to it's\n''')
f_out.write('''# default of "True" the script will attempt to read your GPS data from the API again if it's gotten an "old"\n''')
f_out.write('''# response which in turn triggers iCloud to contact your phone and ask it to attempt to update it's GPS location.\n''')
f_out.write('''# This setting along with the next two controls how this is done. If left all at their defaults, the script will\n''')
f_out.write('''# skip over any data that's reported as old, wait 30 seconds and check the data again, and do that a maximum of 6\n''')
f_out.write('''# time before just accepting the old data and moving on. If getting data with the "isOld" flag set is acceptable,\n''')
f_out.write('''# you can change this setting to False and the script will take any location data it gets regardless of it's age.\n''')
f_out.write('''isold_reject={}\n'''.format(general_conf['isold_reject']))
f_out.write('''\n''')
f_out.write('''# The following setting relates to the above description of how the script handles data from the iCloud API that has\n''')
f_out.write('''# the "idOld" flag set. This setting tells the app how many times retry reading data from the API to get a more\n''')
f_out.write('''# current response. By default this is set to 6 retries.\n''')
f_out.write('''isold_retries={}\n'''.format(general_conf['isold_retries']))
f_out.write('''\n''')
f_out.write('''# The following setting relates to the above description of how the script handles data from the iCloud API that has\n''')
f_out.write('''# the "idOld" flag set. This setting tells the app (if enabled) how long to sleep between retries when attemping to\n''')
f_out.write('''# to get more current data.\n''')
f_out.write('''isold_sleep={}\n'''.format(general_conf['isold_sleep']))
f_out.write('''\n''')
f_out.write('''# The following setting controls whether or not the script will except location data that is obtained through cellular\n''')
f_out.write('''# triangulation. The methods with which iOS devices can determine their location, in order of most to least\n''')
f_out.write('''# accurate is GPS, GPS-Course, WiFi, and Cell. With the "Cell" method horizontal accuracy can vary from 65 to 1000\n''')
f_out.write('''# meters which is often inaccurate enough to cause "bouncing", meaning when your location data is normally coming\n''')
f_out.write('''# from WiFi or GPS, a drop to the Cell method might be enough that you end up outside of whatever geofence or\n''')
f_out.write('''# allowable distances you have setup to perform certain actions. For instance, you may have your ISY set so a\n''')
f_out.write('''# of 1/4 of a mile (.25) is enough to consider you no longer home and it triggers a program that turns off all of\n''')
f_out.write('''# lights and changes your thermostat settings to conserve power. So, when you get a Cell based loction with a 1000\n''')
f_out.write('''# meter accuracy level, the script may set your ISY to think you're no longer home, then in the next reading 1\n''')
f_out.write('''# minute later, when it comes back to WiFi or GPS, it sets you back home again. This would cause all the lights\n''')
f_out.write('''# to come back on and your thermostat settings to be restored. In some areas indoors with weak WiFi signals and no\n''')
f_out.write('''# clear view of the sky to make GPS readings possible, this can happen from time to time causing you to "bounce"\n''')
f_out.write('''# from "home" to "away". In order to prevent this, or at least lessen it's probability the script has the option to\n''')
f_out.write('''# reject any location that comes from the Cell method. If you do experiance this "bounce" event on a regular basis\n''')
f_out.write('''# you can set the follow setting to "True" in order to have the script ignore data if it comes from cellular\n''')
f_out.write('''# triangulation.\n''')
f_out.write('''gpsfromcell_reject={}\n'''.format(general_conf['gpsfromcell_reject']))
f_out.write('''\n''')
f_out.write('''# The follow setting setting relates to the setting above to have the script ignore location data when is comes from\n''')
f_out.write('''# the "Cell" method. This setting controls how many times the script will request location data from the API in an\n''')
f_out.write('''# attempt to get data from the GPS, GPS-Course or WiFi methods before it accepts the Cell data and moves on.\n''')
f_out.write('''gpsfromcell_retries={}\n'''.format(general_conf['gpsfromcell_retries']))
f_out.write('''\n''')
f_out.write('''# The follow setting setting relates to the setting above to have the script ignore location data when is comes from\n''')
f_out.write('''# the "Cell" method. This setting controls how long between iCloud API reads the script should wait when attempting\n''')
f_out.write('''# to get data from a method other than cellular triangulation.\n''')
f_out.write('''gpsfromcell_sleep={}\n'''.format(general_conf['gpsfromcell_sleep']))
f_out.write('''\n''')
f_out.write('''# The following setting enables or disables the script from checking the iOS devices battery level. If left to it's\n''')
f_out.write('''# default setting of "True", with each read of location data, the script will also request the device status and\n''')
f_out.write('''# from that information extract the current charge level of the device. If the device falls below a certain\n''')
f_out.write('''# threshold, configurable in additional setting below, the script will sleep for a longer period of time than\n''')
f_out.write('''# normal to conserve battery power. When determining how long to sleep, the script will compare the battery sleep\n''')
f_out.write('''# time to the variable sleep time the script would normal wait based on it's current distance from home and sleep\n''')
f_out.write('''# for whichever time is greater.\n''')
f_out.write('''#\n''')
f_out.write('''# For example: If you were 200 miles from home, the script would normally sleep for 100 minutes between GPS lookups\n''')
f_out.write('''# but the default low battery sleep time is 60 minutes (3600 seconds), so in that case, the script would still\n''')
f_out.write('''# sleep the normal 100 minute. However, if you were 20 miles from home, the script would normally sleep for only 10\n''')
f_out.write('''# minutes, but once you've crossed the low battery threshold, the script would now sleep for 60 minutes instead.\n''')
f_out.write('''#\n''')
f_out.write('''# The setting below would be set to "True" to use the battery threshold, set to "False" to ignore the battery level and\n''')
f_out.write('''# always use the script calculated sleep time based on distance and/or radio check.\n''')
f_out.write('''battery_check = {}\n'''.format(general_conf['battery_check']))
f_out.write('''\n''')
f_out.write('''# The following setting related to the battery check setting above and is the battery charge percentage under which the\n''')
f_out.write('''# script will sleep for an extended period of time when needed.\n''')
f_out.write('''battery_threshold = {}\n'''.format(general_conf['battery_threshold']))
f_out.write('''\n''')
f_out.write('''# The following settings is also related to the battery check setting and is the minimum time, in seconds, of how long\n''')
f_out.write('''# the script will sleep between GPS lookups. Again, if the normal variable sleep time is longer than the time set\n''')
f_out.write('''# here, the script will still wait for the LONGER period of time between GPS lookup cycles.\n''')
f_out.write('''battery_sleep = {}\n'''.format(general_conf['battery_sleep']))
f_out.write('''\n''')
f_out.write('''# The following setting controls the number of times the script will request device status data if it does not get a\n''')
f_out.write('''# valid battery level:\n''')
f_out.write('''battery_retries = {}\n'''.format(general_conf['battery_retries']))
f_out.write('''\n''')
f_out.write('''# The following setting is the number of second between eash retry the script will sleep while attempting to get valid\n''')
f_out.write('''# device status and battery data:\n''')
f_out.write('''battery_retries_sleep = {}\n'''.format(general_conf['battery_retries_sleep']))
f_out.write('''\n''')
f_out.write('''# The following setting is to enable reporting of the current iOS device battery level to the ISY. It will be reported\n''')
f_out.write('''# to the ISY as a whole integer. For example, if your battery level is 87%, the ISY variable will be set to 87.\n''')
f_out.write('''battery_isy_reporting = {}\n'''.format(general_conf['battery_isy_reporting']))
f_out.write('''\n''')
f_out.write('''# The following setting relates to the one above. This is the ISY variable number the battery level will be stored in.\n''')
f_out.write('''battery_isy_variable = {}\n'''.format(general_conf['battery_isy_variable']))
f_out.write('''\n''')
f_out.write('''# The following setting controls if you want the script to force a GPS check even if the script see's the device via\n''')
f_out.write('''# radio (wifi or bluetooth) check. In some cases, outside scripts or sensors may crash or stop updating leaving\n''')
f_out.write('''# your ISY thinking your device is within radio range and therefore, would never do a GPS check. This setting tells\n''')
f_out.write('''# the script to do a GPS check, by default once ever hour regardless of it's "radio" status. This way, even if the\n''')
f_out.write('''# ISY still thinks the iOS device is in radio range, a GPS check will confirm it, or if you have actually left your\n''')
f_out.write('''# home location it will still send your current distance from home to the ISY.\n''')
f_out.write('''gps_recheck = {}\n'''.format(general_conf['gps_recheck']))
f_out.write('''\n''')
f_out.write('''# The following setting relates to the gps_recheck setting above. It controls how often, in seconds, you want the\n''')
f_out.write('''# script, in seconds, to check GPS location even if the device is within local radio range:\n''')
f_out.write('''gps_recheck_time = {}\n'''.format(general_conf['gps_recheck_time']))
f_out.write('''\n''')
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - Writing [ini_version] section...')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''### Configuration File Version Control Section **** DO NOT EDIT BELOW THIS LINE**** ###\n''')
f_out.write('''#######################################################################################################################\n''')
f_out.write('''[ini_version]\n''')
f_out.write('''version = {}\n'''.format(config_file_version))
logger.info('INI_CREATION - Written.')
logger.info('INI_CREATION - New .ini file creation is complete.')