A module for the MagicMirror that displays driving times from a location to one or more destinations based on Google Maps Traffic information. As it uses the times in traffic the values are dynamic as long as there is reasonaby accurate traffic detail available to Google in your area. If the in traffic travel time is longer then a symbol will be showed.
Navigate into your MagicMirror's ~/MagicMirror/modules folder and execute
git clone https://github.com/Jacopo1891/MMM-GoogleTrafficTimes.git
A new folder will be created, please navigate into it. Once in ~/MagicMirror/modules/MMM-GoogleTrafficTimes run:
npm install
to install the module and dependencies.
To use this module, add it to the modules array in the config/config.js file:
var config = {
modules: [
{
module: 'MMM-GoogleTrafficTimes',
position: 'top_left',
config: {
key: 'YOUR_KEY',
origin: 'SW1A 1AA',
destinations: [
{
name: "Work",
address: "SW1A 2PW"
},
{
name: "Gym",
address: "XXX"
}
],
updateInterval: 900000,
avoidHighways: false,
avoidTolls: false,
mode: 'driving',
language: "en-EN",
offsetTime: 25,
lastUpdate: true,
timeLastUpdateWarning: 1,
horizontalLayout: false,
schedules: [],
debug: false
},
}
]
}
key
: Your Google API key as described in the relevant section of this readmeorigin
: This is the location all travel times to the destinations below will be measured from.destinations
: Those are the locations you need travel times to (min 1, max 20).updateInterval
: Time (in milliseconds) before refreshing data. Default: 900000 -> 15 minutes.avoidHighways
: true or false, controls whether Highways are avoided (true) or utilised (false) in routing.avoidTolls
: true or false, controls whether Tolls are avoided (true) or utilised (false) in routing.mode
: The mode of transport to use when calculating directions, driving
(default), cycling
or walking
(requests cycling/walking directions via bicycle paths/pedestrian paths - where available)language
: Set languages, default en-EN
. (fr-FR
, de-DE
, it-IT
)offsetTime
: Percentage to decide if there is traffic and show symbol. See paragraph to undestand logic and edit properly.lastUpdate
: true or false, shows a warning message if data is not updated.timeLastUpdateWarning
: Specifies time (in minutes) that have to elapse since last failed data update to display the warning message. (Default 1 minute.)horizontalLayout
: true or false, Organize results on horizonal line. (Default false.)schedules
: parameter accepts an array of objects, each representing a schedule for content display (Default empty -> the module will be displayed at all times)debug
: true or false, shows logs on console (node_helper -> backend, module -> browser).The Destinations need to be entered in the form
[
{
name: "Work",
address: "SW1A 2PW"
}
]
In the example config for Destination 1 we have a Label of Work with an Address of SW1A 2PW.
The Label name
appears as the title for each result as shown in the Example Screenshot below.
In this release the origin and destination addresses have been tested across a large number of countries but certainly not all.
Whilst the Google API can accept a multitude of formats from addresses to lat&long co-ordinates this script has some matching code to make the results format nicely and this could have issues with an as yet untried address format.
In order to use this module you will need a Google Maps API which is available from the Google GCP console. You will need to enable the following APIs for your key, Maps JavaScript API, Geocoding API, Distance Matrix API.
To determine if the road is busy or not, I decided to add the optimal time (meaning without traffic by Google Matrix) with an offset obtained using this simple formula:
optimalTime + (optimalTime * offset)
If the estimated time from Google Matrix is greater than this value, it means there is traffic, and the symbol is displayed.
By default, the offset is set to 25%, which seems like a good compromise.
The schedules parameter accepts an array of objects, each representing a schedule for module display.
Each object in the list must include the following keys:
days
: An array of numbers representing the days of the week to apply the schedule. Day numbers correspond to the following values: 0 (Sunday) to 6 (Saturday). For example, [0, 1, 2, 3, 4] indicates that the schedule applies from Sunday to Thursday.
startHH
: The starting hour of the schedule (in 24-hour format).
startMM
: The starting minute of the schedule.
endHH
: The ending hour of the schedule (in 24-hour format).
endMM
: The ending minute of the schedule.
If the days array is empty, the content will be displayed at all times.
Here's an example of how to configure the schedules parameter:
schedules: [
{
days: [0, 1, 2, 3, 4], // From Sunday to Thursday
startHH: "08",
startMM: "00",
endHH: "17",
endMM: "30"
},
{
days: [5], // Friday
startHH: "08",
startMM: "30",
},
{
days: [], // Display at all times
startHH: null,
startMM: null,
endHH: null,
endMM: null
}
]
This example sets up three schedules:
From Sunday to Thursday, display content from 08:00 to 17:30.
On Friday, display content from 08:30.
Display content at all times when the days array is empty.
debug: true
on config.js as described in installation section.npm start dev
or
npm start dev | grep MMM-GoogleTrafficTimes
to see only MMM-GoogleTrafficTimes's logs.
Please feel free to raise an issue on GitHub for any features you would like to see or usage issues you experience and I will endeavour to address them.
Find it useful? Please consider buying me or other contributors a coffee.