Rule 4 help please triggered gps messaging

Here’s a piston that I’d like to move over to Hubitat. Anyone able to advise how to do this in hubitat?

The set up: I use Alexa to trigger a virtual switch (this I can handle). The piston then takes my phone’s current gps location, runs a goggle maps api query to find the time to home (home embedded in global variable). This comes in the form of a number of seconds, it converts it to minutes, and then calculates arrival time (now + duration + I pad 15 minutes). Finally I text to my wife both the duration (46 minutes) and the arrival time (6:15).

Help I need now:

  1. can hubitat get gps cords from phone? I believe their app does not have it, any other way?
  2. how to make the get to a url,...I have the url from my piston, just need to know how to trigger.

I’ll post the piston when in front of a laptop and can snapshot it.

Anyone able to help?

that sounds like a cool rule. And handy. The best person to address if it can be done is @bravenel. I'll be following this thread for the solution. Nice way to think outside the box for sure.

No. Our mobile app does not have the phone's GPS location. We don't track it, or send it to our cloud. All that it knows is the location of your hub (that you establish), and geofence crossings. Those crossings are sent as presence arrival/departure events.

What's a piston? If you mean that you have a cloud endpoint from a rule, the url is simply entered into a browser.

I don't know of anyway to do what you're trying to do. Perhaps someone else knows a way to send gps coordinates from a phone.

Do you have an Android phone? The Tasker app can do both of these things.

@bravenel, no emotion come through in text, so I can't tell if you are kidding. In any case, a Piston was a Rule in Webcore.

In any case, here is the piston from that platform that did all the magic.

As you can see it makes the web call to the google API using my API key variable and my home address variable. Then does the math. Finally sending the text.

For the record, I stole much of that code and re-purposed it - my specialty. I did not write that piston myself. The 'traffic light' device declaration is legacy from the original dev work. :slight_smile:

How about if we remove the phone gps part...90% of the time I am coming from work. I could hard code work address and at least get it working for ‘work to home’.

Would life360 work then?

I looked a my L360 device. It does not have gps coords in hubitat.

Right, but since you said mostly from work, could you set that up as a location of interest? I haven't played around with this myself, so my question was really legitimate and not implying it would be a solution, but it seems like something worth exploring.

If you want to try @bptworld's Life360 with States app ([RELEASE] Life360 with States - Track all attributes with app and driver. Also supports RM4 and Dashboards!), you can get GPS coordinates. It works with both free and paid accounts.

image

If you want to keep the same functionality, you can use RM to post to the WC URL using json. You'll want to set 2 local variables to latitude and longitude in RM and then pass those over to WC in a json HTTP post. All you'd need to change on the WC side would be the execute trigger as you won't need it for a switch.

This URL has more info: Piston example for http trigger for ST switch on/off - Piston: Design Help - webCoRE Community Forum

[Edit]: In looking at this further, you can even remove Alexa from the equation if you want. In @bptworld's Life360 driver, there is a boolean isDriving that you can trigger a RM4 rule on. So, using that, when you start driving, you can have the rule automatically kick off. Use a private boolean to make sure that it only triggers once when you start driving and you should be good to go!

Cheers @corerootedxb!

I have used (and like) a lot of Bryan's code, but not seen this one. Will have to check it out sometime when I am home and free. Could be the weekend before I get to it...but I will be sure to update here.

Oh to be able to edit and work on rules remotely... :slight_smile:

1 Like

If your router supports setting up an OpenVPN server (or if you can set one up somewhere on your network and then create firewall rules to pass the traffic), you can work on them remotely over VPN. :wink:

I installed @bptworld's Life 360 States app, and it does bring in Lat and Long of course. I can get those attributes into hubitat variables - though individually.

Anybody know how to pull it all together and then make the API call in hubitat?

Pull it all together means merging the various variables into the fully formed API call?
"https://maps.googleapis.com/maps/api/distancematrix/json?departure_time=now&origins={originlat,originlong}&destinations={destination_address}&key={api_key}"

Of course, then I still got to; log the response, do all the conversion of the response into duration and time from (now) and then send the message.

This is feeling like a custom app, not a rule.