Skip to content

This a module for the MagicMirror. It shows your commute time using Google's Traffic API

Notifications You must be signed in to change notification settings

Sp4M/MMM-MyCommute

 
 

Repository files navigation

MMM-MyCommute

This a module for the MagicMirror.

It shows your commute time using Google's Traffic API (requires an API Key from Google).

It is a fork of mrx-work-traffic by Dominic Marx. https://github.com/domsen123/mrx-work-traffic

Screen Shot

Installation

  1. Navigate into your MagicMirror modules folder and execute
    git clone https://github.com/jclarke0000/MMM-MyCommute.git.
  2. Enter the MMM-MyCommute directory and execute npm install.
  3. Go to https://developers.google.com/maps/documentation/javascript/get-api-key and get an API key.

NOTE To those updating from previous verions

You now configure the header in the standard way instead using the headerText and showHeader parameters. So if your config looked like this before:

    {
      module: 'MMM-MyCommute',
      position: 'top_left',
      classes: 'default everyone', 
      config: {
        showHeader: true,
        headerText: 'Traffic',
        ...
      }
    }

change it to this:

   {
      module: 'MMM-MyCommute',
      position: 'top_left',
      header: 'Traffic',
      classes: 'default everyone', 
      config: {
        ...
      }
    }

If you don’t want a header, then just omit it.

Config

Option Descriptio
apikey REQUIRED API Key from Google

Type: string
origin REQUIRED The starting point for your commute. Usually this is your home address.

Type: string
This is as you would see it Google Maps. Example: 65 Front St W, Toronto, ON M5J 1E6
startTime The start time of the window during which this module wil be visible.

Type: string
Must be in 24-hour time format. Defaults to 00:00 (i.e.: midnight)
endTime The end time of the window during which this module wil be visible.

Type: string
Must be in 24-hour time format. Defaults to 23:59 (i.e.: one minute before midnight).
hideDays A list of numbers representing days of the week to hide the module.

Type: array
Valid numbers are 0 through 6, 0 = Sunday, 6 = Saturday.
e.g.: [0,6] hides the module on weekends.
showSummary Whether to show a brief summary of the route

Type: boolean
Defaults to true
colorCodeTravelTime Whether to colour-code the travel time red, yellow, or green based on traffic.

Type: boolean
Defaults to true
travelTimeFormat How the module should format your total travel time.

Type: string
Defaults to m [min] (e.g. 86 min). Some other examples are h[h] m[m] (e.g.: 1h 26min), h:mm (e.g. 1:26). This uses the moment-duration-format plugin's templating feature. https://github.com/jsmreese/moment-duration-format#template
moderateTimeThreshold The amount of variance between time in traffic vs absolute fastest time after which the time is coloured yellow

Type: float
Defaults to 1.1 (i.e.: 10% longer than fastest time)
poorTimeThreshold The amount of variance between time in traffic vs absolute fastest time after which the time is coloured red

Type: float
Defaults to 1.3 (i.e.: 30% longer than fastest time)
nextTransitVehicleDepartureFormat For any transit destinations where showNextVehicleDeparture is true, this dictates how to format the next arrival time.

Type: string
Defaults to [next at] h:mm a.
destinations An array of destinations to which you would like to see commute times.

Type: array of objects.
See below for destination options.

Each object in the destinations array can have the following parameters:

Option Description
destination REQUIRED The address of the destination

Type: string
label REQUIRED How you would like this displayed on your MagicMirror.

Type: string
mode Transportation mode, one of the following: driving, walking, bicycling, transit.

Type: string
Defaults to driving.
transitMode If mode = transit you can additionally specify one or more of the following: bus, subway, train, tram, or rail.

Type: string.
Separate multiple entries with the | character (e.g.: "transitMode" : "bus|subway|tram"). Specifying railindicates that the calculated route should prefer travel by train, tram, light rail, and subway. Equivalenet to train|tram|subway
showNextVehicleDeparture If mode = transit the time of the next departure of the first vehicle on your route will be displayed in the route summary. Only visible when showSummary = true.

Type: boolean.
waypoints If specified, it instructs Google to find the route that passes through the waypoints you specify.

Type: string.
Separate multiple entries with the | character. See https://developers.google.com/maps/documentation/directions/intro#Waypoints for details on how waypoints can be specified.
NOTE: your waypoints will automatically be prefixed with via: so that they are not treated as stopovers. This can cause Google to plan an erratic route. if you find your time predictions are wildly overestimated, then try adjusting your waypoints. Intersections where you would normally make a turn on this roite usually work well (e.g.: Main St & Southwood Drive Toronto ON).
avoid If specified, will instruct the Google API to find a route that avoids one or more of the following: tolls,highways,ferries,indoor.

Type: string.
Separate multiple entries with the | character (e.g.: "avoid" : "highways|tolls").
alternatives If specified, will instruct the Google API to provide times for alternate routes. Must be used with showSummary: true

Type: boolean
color If specified, the colour for the icon in hexadecimal format (e.g.: "#82BAE5")

Type: string
Defaults to white.
startTime The start time of the window during which this destination wil be visible.

Type: string
Must be in 24-hour time format. Defaults to 00:00 (i.e.: midnight)
endTime The end time of the window during which this destination wil be visible.

Type: string
Must be in 24-hour time format. Defaults to 23:59 (i.e.: one minute before midnight).
hideDays A list of numbers representing days of the week to hide the destination.

Type: array
Valid numbers are 0 through 6, 0 = Sunday, 6 = Saturday.
e.g.: [0,6] hides the destination on weekends.

Here is an example of an entry in config.js

{
  module: 'MMM-MyCommute',
  position: 'top_left',
  config: {
    apikey: 'API_KEY_FROM_GOOGLE',
    origin: '65 Front St W, Toronto, ON M5J 1E6',
    startTime: '00:00',
    endTime: '23:59',
    hideDays: [0,6],
    destinations: [
      {
        destination: '14 Duncan St Toronto, ON M5H 3G8',
        label: 'Air Canada Centre',
        mode: 'walking',
        color: '#82E5AA'
      },
      {
        destination: '317 Dundas St W, Toronto, ON M5T 1G4',
        label: 'Art Gallery of Ontario',
        mode: 'transit'
      },
      {
        destination: '55 Mill St, Toronto, ON M5A 3C4',
        label: 'Distillery District',
        mode: 'bicycling'
      },
      {
        destination: '6301 Silver Dart Dr, Mississauga, ON L5P 1B2',
        label: 'Pearson Airport',
        avoid: 'tolls'
      }
    ]
  }
}

Dependencies

Installed during installation

Special Thanks

  • Michael Teeuw for creating the awesome MagicMirror2 project that made this module possible.
  • Dominic Marx for creating the original mrx-work-traffic that this module heavily borrows upon.

About

This a module for the MagicMirror. It shows your commute time using Google's Traffic API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 89.1%
  • CSS 10.9%