Using google maps API to pull down route duration and store to trigger scene

I’m starting to get fed up with leaving the house and finding an accident half way to work which I could have avoided if i had simply checked the google maps before i left. My idea is pretty simple. By using the google maps API it can return the following in either XML or JSON using the following https://maps.googleapis.com/maps/api/directions/json?origin=brighton&destination=staines&key=“my personal API key”

{ "routes" : [ { "bounds" : { "northeast" : { "lat" : 51.4449348, "lng" : -0.1157587 }, "southwest" : { "lat" : 50.8225194, "lng" : -0.5410982999999999 } }, "copyrights" : "Map data ?2015 Google", "legs" : [ { "distance" : { "text" : "99.7 km", "value" : 99705 }, "duration" : { "text" : "1 hour 12 mins", "value" : 4307

so you either have the text version of duration or the amount of seconds. I’m just wondering how I may go about creating a device where both of these values are stored and then refreshed on a regular basis so that i can show on my dashboard (which in turn will also show on authomationHD as a saved app and then i can also trigger scenes using pleg based on these values

I’ve done quite a bit of simple LUA scripting but this is beyond me… and yes I know this wont help if something happens after i hit the road…

Stu

That’s a great idea. The basic plugin you’re describing would poll a URL for JSON data, decode the JSON into Lua tables, and then reference the member(s) from the table and copy them into device variables. The device and service types would be very simple (compared to a thermostat or most other device/service types). Your main device would implement a service type that holds the polling frequency and targeted URL in device variables, and the device would have a loop to poll the URL, parse the JSON, and update device variables with the results. There are probably good examples out there to follow. You could look at my Ecobee or Nest thermostat plugin sources for examples that generally just does this (but are probably not the best examples since there is so much thermostat-specific in them).

[url=https://github.com/watou/vera-ecobee]https://github.com/watou/vera-ecobee[/url]
[url=https://github.com/watou/vera-nest]https://github.com/watou/vera-nest[/url]

watou

P.S. In openHAB, there are pre-provided mechanisms (http binding, JSONpath transformation) for just editing a text file to supply the URL, polling frequency and values to extract for display and automation. There may be a Vera plugin that does essentially the same thing.

[quote=“trouty00, post:1, topic:185316”]I’m starting to get fed up with leaving the house and finding an accident half way to work which I could have avoided if i had simply checked the google maps before i left.
Stu[/quote]

Why not just use waze?

are you suggesting there is a waze app for mios or why not just use my phone before leaving? the whole point is to automate, ie, if the traffic looks “not normal” then maybe flash the lights as i leave the house or set the led’s in the kicthen to raise an alert?

otherwise what does waze do? googling…

I believe I tried this a while ago and realized that Google was not exposing traffic issues. In other words, the adjustment wasn’t occurring to time of travel. So if you know an accident has occurred, check the Google website travel time and then use the API in contrast. I found no matter what (at least when I attempted to code this), the travel time was always the same via the API.

Now if I recall, I read on another forum that perhaps Yahoo or another map provider does provide this service… I haven’t pursued it as I’m buried in work projects.

Good luck and let us know what you find…

[quote=“mvader, post:3, topic:185316”][quote=“trouty00, post:1, topic:185316”]I’m starting to get fed up with leaving the house and finding an accident half way to work which I could have avoided if i had simply checked the google maps before i left.
Stu[/quote]

Why not just use waze?[/quote]

Agree here. I get in my car, plug my phone into the charger, place my phone on the dash mount and open Waze app. The Waze app learns your schedule and asks me “Are you going to work?” I don’t even have to key in the address. Will give me three route choices to choose from based on accidents and traffic conditions.

[quote=“trouty00, post:4, topic:185316”]are you suggesting there is a waze app for mios or why not just use my phone before leaving? the whole point is to automate, ie, if the traffic looks “not normal” then maybe flash the lights as i leave the house or set the led’s in the kicthen to raise an alert?

otherwise what does waze do? googling…[/quote]

Waze will tell you to the minute what time you arrive at your destination.
where the cops are, traffic jams, best route to take, accidents… etc etc.
best travel app there is.
you can automate if you’d like, but no need to re-invent the wheel in my opinion.
waze does a great job in helping you travel. no need to do anything but install the app and run it.

[quote=“mvader, post:7, topic:185316”][quote=“trouty00, post:4, topic:185316”]are you suggesting there is a waze app for mios or why not just use my phone before leaving? the whole point is to automate, ie, if the traffic looks “not normal” then maybe flash the lights as i leave the house or set the led’s in the kicthen to raise an alert?

otherwise what does waze do? googling…[/quote]

Waze will tell you to the minute what time you arrive at your destination.
where the cops are, traffic jams, best route to take, accidents… etc etc.
best travel app there is.
you can automate if you’d like, but no need to re-invent the wheel in my opinion.
waze does a great job in helping you travel. no need to do anything but install the app and run it.[/quote]

I believe he is looking for an alert BEFORE he leaves the house so he can leave early and give himself extra time. At least, that’s what I’d use it for!