[RELEASE] DriveTime - Powered by Google Traffic

DriveTime is a lightweight device driver that, upon the press of a momentary button, provides the travel time and the best route from an origin address to a destination address, taking into account current traffic conditions. Traffic information is provided by Google Traffic.

Example: when pushed, the device updates its attributes indicating how long your commute to work is and the best route to take, e.g., for dashboard display or for Rule Machine rules.

  • The duration attribute indicates how long the trip will take given current traffic conditions.
  • The route attribute indicates the best route to take, given current traffic conditions.
  • The trafficDelay attribute indicates the delay attributable to current traffic conditions, above and beyond how long the trip would take without taking traffic conditions into account.

Installation:

  1. Install the device driver
  2. Add a new virtual device of the type DriveTime
  3. Get a Google Directions API key here. . Enable the Google Directions API.
  4. Enter the Google Directions API key into the preferences of the device
  5. Add the origin address and the destination address into the preferences of the device
  6. Any "push" of the device will update the device's attributes. The device uses the Momentary capability for the button push, not the Pushable button capability.

Note: this device will remain lightweight. If you desire additional features, such as recurring trips, biasing of preferred routes, heads up on when to leave, push notification to specified devices upon arrival, advanced notice that will be late, scheduled checks of traffic, and more, check out the full-feature Multi-Place app.

14 Likes

This looks promising. I have looked at Multi-place but I don't use Withings or have vehicle sensors so it seemed like overkill.

It took me about 20 minutes of blindly fumbling around on the Google API console but I managed to get my key and the DriveTime driver setup.

I showed it to my bride and explained that I could write some rules and monitor her morning drive and let her know if traffic was going to be an issue. This increased the WAF for our automated house. Not something easily accomplished.

Thanks for posting this @JustinL .

2 Likes

Was looking for something like this. Thanks for posting!

I have the device up and running. It provides the directional info as advertised. One issue, however, when using it with webcore - webcore requires a button number value to be sent with the push action for the drivetime device.

I've tried 0, 1, 2, etc. Nothing triggers the push{} event on the device. This is what the event log shows:

Any thoughts?

Also - I think it would be helpful to have a state listing the time the data was retrieved from Google Maps.

This driver uses the Momentary capability, rather than the Pushable Button capability which takes a button number, since there’s no need (conceptually) for different button numbers. Does WebCoRE not support the Momentary capability?

As far as state, that’s easy to do. Will add when I get a chance.

Also - I think

 attribute "trafficDelayStr", "number" // hh:mm

should be

 attribute "trafficDelayStr", "string" // hh:mm
1 Like

I modified the pref:

definition(name: "DriveTime", namespace: "lnjustin", author: "Justin Leonard", importUrl: "")
    {
        capability "Actuator"
        capability "Momentary"
        capability "PushableButton"
        
        attribute "duration", "number" // second
        attribute "durationStr", "string" // hh:mm
        attribute "route", "string"
        attribute "trafficDelay", "number" // seconds
        attribute "trafficDelayStr", "string" // hh:mm
        attribute "distance", "number"
        attribute "updatedLast", "number"
        attribute "updatedLastStr", "string"
        
        command 'push'
        command 'pushWebCore'
    }

Then added a new function bc I couldn't get push to work in webcore (even with the pushablebutton capability):

def pushWebCore() {
    logDebug("DriveTime Pushed from WebCore")
    checkDrive()
}

It now works from webcore using the pushWebCore function. :ghost:

I tried using the Momentary capability with Rule Machine even and it didn't work either. I don't know what the point of Momentary is now, but it doesn't seem functional in practice.

Latest version uses the familiar PushableButton, and allows the user to define multiple pairs of origin/destination, with the button number triggering directions for the correspondingly numbered origin/destination pair.

It was possible to update using RM with the previous version. I used actuator in RM to "push" for an update and created multiple devices for multiple locations.

Your update simplifies the multiple locations for me. Thanks

1 Like

Is there a way I can pull the trafficDelayStr attribute into a local variable in RM?

I'm only seeing the duration and route available.

1 Like

Just updated. Should be fixed now with the latest version.

2 Likes

Thank you, sir!