So I had a little time on my hands, and finished the script for iPhone location.
The script logs in to your iCloud, get’s your iphone location, checks if you are in a set geofence, and posts an update to an openhab item. It’s suppose to be a workaround until we get a proper iOS binding. Or not.
It works just fine, with ONE exception: the library that I use to connect to iCloud has an issue, due to which iCloud emails you every time you connect (iCloud feature since the iCloud hack). Only solution for this, right now, is for you to create a rule in your email client to handle iCloud’s emails. I’ll try to change some stuff soon, maybe I’ll get to a point in which iCloud sends less email (keep the connection going or something).
If you wish to try you, and you think you won’t get annoyed by the email, feel free to try it, and provide feedback https://github.com/trusk89/iLocatorBridge.
Why did not just use IFTTT and myopenhab.
In IFTTT you trigger on location and set a switch in openhab.
This works without any hustles.
You need to have IFTTT running, location working correctly (which seldom does) and hope iOS doesn’t decide you should kill ifttt.
This is app independent, doesn’t require extra processes running on my phone and implicitly doesn’t affect phone battery life.
A number of users on this forum do not want IF running on their phones chewing up battery tracking their location, or don’t want to use my.openhab, or have experienced spotty reliability with the IFTTT openHAB channel (my experience). I don’t do location tracking on my phones, preferring instead to use more passive means to detect when I or my wife is home but I applaud @alex_bartis’s efforts.
@alex_bartis, perhaps you can compare notes with what @sipvoip’s coder did/is doing with an actual binding that does this. There might be some lessons learned that could be shared re the email problem.
I don’t imagine Sipvoip’s dev friend doing the same implementation in the official iPhone binding. What I need is a really good python developer, because the email problem is well documented (in the library that I’m using), but I just don’t have the python knowledge to fix it.
Edit: apparently I found a workaround for receiving much less emails, but I need to let it work all night in order to confirm.
Edit 2: 2 hours later, no email received. It works!
Edit 3: Someone just opened a pull request that fixes the cookie issue.
I implemented a phone location method using my DDWRT router and I couldn’t be happier - writeup here: http://tinsley.io/2015/03/openhab-presence-detection-with-dd-wrt/
It’s 100% reliable and super fast - my OpenHab rule is to unlock my front door when I am outside (using this location method) and it almost always unlocks by the time I get from my car to my front door (plus a couple seconds, occasionally).
No additional scripting necessary and it doesn’t consume any additional power on my phone.
I should buy a cheap router for ddwrt.
I implemented a phone location method using my DDWRT router
Is this a good idea? What will happen when the iPhone sleeps? I think it will disconnect from WLAN. When it awakes from slepp it connects again…
I installed the script vom alex yesterday. It works, but i have found a bug?
My german internet provider disconnects my internet once a day. My router automaticly reconnects and get a new IP. After this, the iLocator script stopped working.
At 05:57 the last succesfull update has been posted. after that, the router got a new IP and at 05:59 the scriped completly stoped with the message: Could not get device coordinates.
Can you fix this?
2016-01-08 05:57:17,550 Starting new HTTP connection (1): localhost
2016-01-08 05:57:17,577 “PUT /rest/items/AnwesenheitZuhause/state HTTP/1.1” 200 0
2016-01-08 05:57:17,587 Update posted to OpenHab
2016-01-08 05:59:17,912 Could not get device coordinates
I have done little path changes. I moved the config file to /etc/iLocator/ and the log file to /var/log
So i am able to write a script to run iLocator as a linux daemon.
Thanks for your great work on this!
and a feature request
It would be great if i could detect more than one device from a iCloud account.
@Dennis650 it’s in the todo, if you check the wiki. And for the issue, I would appreciate if you open an issue on github, so I can keep track. Thanks!
I’ve updated the script and dropped geopy usage. Now it calculates the distance locally, so there are less things that can fail
“What will happen when the iPhone sleeps? I think it will disconnect from WLAN. When it awakes from slepp it connects again…”
I’ve never had this issue. As far as I know, iPhones maintain their wifi connection during sleep. However, if my iPhone shuts off (runs out of battery) then the effect is the same as if I left the house (door will lock).
@Bill the iPhone has two levels of sleep. One light, in which it responds. One deep, in which it doesn’t respond, except to wake requests on port 5376(i think), only udp. That’s why the standard network health binding doesn’t work with iOS devices, because of deep sleep.
@alex_bartis Hmmm… That’s interesting. The script running on my DDWRT router doesn’t look at one port, which I could see being shut down during deep sleep (a very quick Google didn’t yield any info on what is being turned off during deep sleep). Instead it checks every so often (time interval defined) to see if the phone MAC address is on the network, at all. It wouldn’t surprise me if, even in deep sleep, the iPhone keeps the network binding active (but possibly not responsive).
Again, I haven’t seen any behavior from my setup that would lead me to believe that deep sleep “looks” the same to my setup as if my (or my wife’s) phone was disconnected/dead/not in the area. I’ve had this setup running for about 2 months, now.
I must say that I’ve tried @Bill’s solution and it apparently works. The iPhone remains connected continuously I think, but I need to keep testing for a few more days.
For those with asus routers, you can use Asuswrt Merlin, instead of DD-Wrt. It’s a modified firmware that gives you more options then the standard firmware (like what we need for this: ssh & scripts), but keeps all your settings on the router when you install it. So basically it’s a patch that unlocks a more powerful router, without the drawback of losing everything when flashing a new firmware.
just wanted to chime in I setup ifttt to open a customers garage door and its pretty finicky. IOS works most of the time but if he drives up and is on the phone it wont work, i believe this is carrier related(no data while on the phone). On android it was horrible, the location did not seem to update but every ten minutes or so. I need to just setup his router to always give his phone the same IP address and than setup openhab to ping that address and than open the door when theres a response and than set some type of lock so that it only triggers once until the phone disconnects and reconnects.
@sealtech I find ifttt to be more a toy then having actual utility, and not only for location. And the nh idea is not bad, it doesn’t work with most phones and especially iOS, because iOS devices enter a deep sleep phase when they don’t respond to pings. That’s why we have the two solutions here: either use iCloud for tracking, or @Bill’s script.
i noticed the last days, that the iLocatorBridge causes hi power consumtion on my devices, when i am away from home. I had to recharge it at midday. I think every time the script locates the iPhone, the GPS is activiated or something like that. I run the script every 2 minutes.
Inspired by other threads i wrote a own script based on hping3, ping and mqtt to locate the phones, when they are at home. Till now it looks very good.
Yeah @Dennis650, I agree. I need to rework the interval component, to do something like: if you are further from home, request it less, and only increase the interval while you’re closer to home.