iPhone locator bridge/binding or however you like to call it

Sorry…

Missed some python stuff. apt-get install python-pip did the trick


:slight_smile:

a bit off topic, but how do I run the pyicloud commands…it’s giving me errors like:

Traceback (most recent call last):
File “cmdline.py”, line 15, in
from . import utils
ValueError: Attempted relative import in non-package

I would like to receive the device ID…but no clue on how to use the pyicloud pacakage

thanks

again…too fast with questions…
got it working.

link: how to use

Hi,
installed everything an loction will be fetched, but there is a problem writing this information to openhab, any idea, the error in the log is this.

2017-01-24 19:27:41,686 Could not post update to OpenHab: 400 Client Error: Bad Request

My OwnTracks and MQTT is working flawlessly… Just saying… :wink:

How would I update the code to return the distance away to an openhab item? Also is there a way of updating the openhab item without having to have a username/pw for openhab?

I have the python script working as it stands, but have been unsuccessful in updating the code to address the above two points.

Download the most recent version (updated today) . It provides support for posting current distance (as well as the current polling rate and next scheduled poll time) to OpenHAB. I also added functionality for dynamic/adaptive polling so you can define how often to poll for your device based on your current distance. Check out the revised README and comments in configuration.ini for more info.

1 Like

Many thanks to @peteraquino for updating it!

Hi,

Can anyone tell me where I have gone wrong when my command line gives the following output continuously every second?

No OHItem is definded not in [GeofenceHome] or [OpenHab]
No OHItem is definded not in [GeofenceWork] or [OpenHab]
No OHItem is definded not in [GeofenceHome] or [OpenHab]
No OHItem is definded not in [GeofenceWork] or [OpenHab]
No OHItem is definded not in [GeofenceHome] or [OpenHab]
No OHItem is definded not in [GeofenceWork] or [OpenHab]
No OHItem is definded not in [GeofenceHome] or [OpenHab]
No OHItem is definded not in [GeofenceWork] or [OpenHab]
No OHItem is definded not in [GeofenceHome] or [OpenHab]
No OHItem is definded not in [GeofenceWork] or [OpenHab]
No OHItem is definded not in [GeofenceHome] or [OpenHab]

I have created a geo.items file with

Switch NathanHome
Number NathanHomeDistance
Switch NathanWork
Number NathanWorkDistance
String NathanPollRate
String NathanNextPollTime

and my configuration file looks like this:

[iCloud]
#iCloud username
Username : MYUSERNAME
#iCloud Password
Password : MYPASSWORD
# start iLocator --list-devices to retrieve list of registered ID's
# you can supply multiple Devices .. just start with DeviceID
DeviceID1 : MYDEVICEID
#(Optional) a second device may be provided, to be used for additional geofences
DeviceID2 : MYDEVICEID

# you can have multiple geo fences .. just start the section with Geofence
[GeofenceHome]
Latitude : 51.679664
Longitude : -3.217737
# Enter your preferred unit of distance using m, km, ft, mi or nm
# for meters, kilometers, feet, miles or nautical miles
DistanceUnit : mi
#Radius for the geofence.
GeofenceRadius : 1
# for which device to check .. if this is not supplied the first device will be checked
Device: DeviceID1
#Dynamic polling map.  A comma-seperated key-value pair in the format dist=interval, shortest distance first.
#Ex: 100=300,1000=10,1001=60 (within 100 ft poll @ 300 sec, else within 1000ft poll @ 10 sec, else poll at 60 sec)
#Ex2: 200=300, 201=60 (If you wanted to poll at 300 seconds while inside geofence, but 60 seconds outside of fence (assuming fence is set to 200 ft)).
#Ex3  0=60 (if you always want to poll at 60 seconds)
PollingMap: 100=300,1000=10,1001=60
#OpenHAB item (usually a switch) to hold the presence value (ON = inside geofence, OFF = outside geofence...
OHItem: NathanHome
#OpenHAB item to hold the current distance from this POI
OHItem_Distance: NathanHomeDistance

#example of second geo fence...
[GeofenceWork]
Latitude : work latitude
Longitude : work longitude
DistanceUnit : ft
GeofenceRadius : 100
Device: DeviceID2
PollingMap: 100=300,1000=10,1001=60
OHItem: NathanWork
OHItem_Distance: NathanWorkDistance

[OpenHab]
#Server Address
OHServer : MYIP
#OH User with which to connect
OHUsername : MYUSERNAME
#OH Password
OHPassword : MYPASSWORD
#Default interval for when a retry needs to occur (i.e. iCloud was unable to return your location during a poll)
RetryInterval : 30
#(Optional) An OpenHAB item to hold the current polling rate
OHItem_PollingRate : NathanPollRate
#(Optional) An OpenHAB item to hold the time that represents when the next poll will occur
OHItem_NextPollTime : NathanNextPollTime

Thanks

Looks like you either didn’t edit the configuration.ini file to add the OpenHAB items, or the script can’t find the file.

@peteraquino

sorry, I’ve just edited the post above to show my files, if this helps?

In your configuration.ini file, change:
“OHItem: NathanHome” to “OHItem_Presence: NathanHome"
and
"OHItem: NathanWork” to “OHItem_Presence: NathanWork”

I’ll submit a pull request to correct the configuration.ini going forward.

1 Like

Works great!

Am I right in thinking that to now run this through openhab I should use the exec binding with the following settings:

Thanks

Can’t help you there. I’m still on OH 1.8.3 and I have the iLocator script running on a Raspberry Pi. I don’t think you want this kicking off on an interval tho as it runs non-stop and checks at the interval you define in the polling_map.

Ok, I have my openhab running on the RPi 3 and would be more than happy to have the script running that way in the background for now.

How did you do this?

/etc/rc.local is executed at startup. I simply edited the file to call the python script:

sleep 15
sudo python /usr/sbin/iLocator.py   <whatever your path to the script is>

Note: I had to add a sleep 15 at the top of the file else it was attempting to run the python script too early (before OpenHAB and other programs were initialized) and that created problems.

1 Like

@peteraquino

Hi Peter,

Would you be able to tell me how to add another user to this file, e.g. I’d like to add a DeviceID2 that would also be used against [GeofenceHome] where “OHItem: JessHome” and “OHItem_Distance: JessHomeDistance” would be the outputs.

Would I need to create a new [GeofenceHome] section such as [GeofenceJessHome]?

Thanks
Nathan

@Nathan_Wilcox,
In one of the posts above, someone else mentioned running separate scripts for each account. I think you’d have to go that route as the script doesn’t currently support more than one iCloud account.

I’m pretty sure I’ve achieved the aim. In case anyone wants to replicate here is what I did.

  1. Backup the files to begin
  2. Make a copy of the configuration.ini file and rename to “NEWNAME.ini”
  3. Make a copy of iLocatorLog.log file and rename to “NEWNAME.log”
  4. Make a copy of iLocator.py and rename to “NEWNAME.py”
  5. Open the new “NEWNAME.py” file and replace DEFAULT_CONFIG = ‘configuration.ini’ with
    DEFAULT_CONFIG = 'NEWNAME.ini'
  6. In the same file replace DEFAULT_LOGFILE = ‘ILocatorLog.log’ with DEFAULT_LOGFILE = 'NEWNAME.log'
  7. Save and close the file
  8. Open the new “NEWNAME.ini” and change each section as per first setup
  9. Save and close the file
  10. Run “NEWNAME.py”

Any issues or questions please ask. I will update with any further issues/improvements.

@alex_bartis,
Are you familiar with this error?

Could not get device coordinates. Retrying!: No JSON object could be decoded

I had the script running for weeks until yesterday and I kept getting this error at each poll. Restarting the script clears things up and gets it working again. I don’t know enough about pyicloud to properly diagnose it. Hoping you might be able to provide some insight.