Convert Latitude/Longitude to Geofence for Presence

Oooh very interesting -- I'm a rookie here, so forgive the stupid question. Are you proposing that I throw that formula in as a global (or maybe local?) variable and then use the result in my triggers (say, when distance < some threshold)?

No, you will have to calculate each time you get a new car location sample, the location of your home will probably not change. Will give the distance between the two. The formula above gives result in km, you would just set a desired radius. Changing the constants would give you miles, etc. See the link for details. You will need to code it in Groovy, let an app or driver (however you get Tesla to pass lat/long) do the Calc, & create a trigger value. Essentially, your “driver” will be a number generator (like a voltage meter) that outputs a distance, to use as a trigger.

Got it. That sounds very doable. Will try it and report back - thanks for your help!

Glad to do it. Welcome to the community!

There is a Tesla driver floating around here. Does it provide presence?

I've thought about doing something similar with my car and others have mentioned getting a separate presence sensor, and just leaving it in the car. This way when the car enters the mesh, it'll open the garage

1 Like

It does, but the presence is just an indication as to whether the key (i.e. my phone) is in the car.

Considered this as well. Hoping to avoid it since I've got a car that provides lat/long data, but I think it's a pretty good fallback if I can't get @672southmain's idea turned into a solution.

OK, I think I got it working, after tinkering with syntax in both the driver and the app for a while. I'm successfully returning a distanceFromHome value based on the formula above and a user-entered home latitude and home longitude value upon instantiating the car via the app.

My only remaining question is - the driver is set to automatically refresh every 15 minutes (and the distanceFromHome calc is embedded in the code that runs on refresh). Even if I reduce that to every minute, I'm still thinking that's not frequently enough to actually open the garage door on approach. Will a subscription from rule manager monitor the distanceFromHome on more of a "push" basis, or is there something else I am missing?

You are going to have to ask a Rule Manager expert about that. It’s over my level of Hubitat experience. Congratulations on getting it working.

Drive slowly, circle the block, or increase the radius.

Perhaps, as the distance gets closer and you begin approaching, you could sample faster.

That seems like a weird thing to me. A car that expensive without it? Even my plain-Jane 2003 Minivan has it. :laughing:

They do seem to make a Homelink retrofit for some of these cars. If it were me, I would want it even if it were just a backup to your Hubitat, it is nice to have a manual override at times. Says it is $300. https://www.tesla.com/support/homelink-faq

Yeah, but where's the fun in that? I have a manual garage door opener as my fallback :smiley:

1 Like

Thanks again for your help!

EDIT: Deleted my post as it was OT and not constructive for this conversation.

1 Like

Is there a function you can call from within the device to check for the distance from home? You could maybe make a rule that triggers when the car is away from home, and to poll it maybe every minute and stop once the car is back within the radius.

The only iffy thing with this is if you drive within your circle but aren't going back home, it'll open your garage door

If you can’t get that to work with your Tesla, you could try Life360 with states. It has a distance from home attribute. I don’t know how often it polls but perhaps it would give you another option if needed.

I wonder whether there is an outdoor camera that you could set up to monitor the driveway and that would trigger a switch upon motion detection? Might work to trigger the garage to open when motion is detected in the driveway, you’re in the car, and the distance to home is within a radius gauaranteed to be met within your update interval. And maybe also specify that the motion has to have been detected within a certain time interval from when the geofence was crossed. That way, if you happen to, say, stop at a neighbors house instead, someone walking by your driveway 10 minutes later wouldn’t open the garage. Just some ideas. Don’t know if it would work in practice.

Yes, this is basically what I'm going to try and do. The Tesla API has a "stream" flag that opens up a WebSocket, and it sounds like Hubitat has the capabilities needed to read data that's fed in that way. I am going to try and figure out how to make those things work together.

Thanks for the suggestions! I had considered a few options like that - but none of them quite fit my situation. We live in the city and the approach to the garage is in an alley (no camera there, and even if we had a camera we'd see tons of other cars all the time).

I did something like this when I was using the Network Presence Sensor. Default was like 10 or 15 minute pings. On one of my devices, I had it pinging every 30 seconds. The change was more or less instant in the presence.

It does take resources as the rule will constantly repeat while running though, so need to take that into account if you do go that route

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.